solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
constexpr int dx[] = {1, 0, -1, 0};
constexpr int dy[] = {0, 1, 0, -1};
constexpr int inf = 1e9 + 10;
vector<string> g;
vector<vector<int>> d;
int n, m, k;
bool valid(int x, int y) {
return x >= 0 && y >= 0 && x < n && y < m && g[x][y] == '.';
}
int main() {
ios::sync... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long a, b;
scanf("%lld%lld", &a, &b);
long long ans = min(a, b / 2);
a -= ans; b -= ans * 2;
printf("%lld\n", ans + b / 4);
} | 0 |
#include<cstdio>
#include<algorithm>
#include<vector>
#define N_ 201000
using namespace std;
int A[N_], B[N_], DegA[N_], DegB[N_], Q[N_], head, tail, vis[N_], CA, CB;
int n, Num[N_][2];
vector<int>GA[N_], GB[N_];
#define N_ 300100
#define M_ 2001000
struct MaxFlow {
vector<int>G[N_];
struct Edge {
int b, e, f;
}E... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s, t, c;
int main() {
cin >> s >> t;
c = s;
int pos = s.size() - 1;
while (pos >= 0) {
if (s[pos] != 'z') {
c[pos] = s[pos] + 1;
break;
} else
c[pos] = 'a';
pos--;
}
if (c == t)
cout << "No such string";
else
cout <... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = int(5e5) + 10;
const int K = int(2e6) + 10;
const int MOD = int(1e9) + 7;
const int INF = int(1e9) + 5;
const long long INF64 = 1e18;
int t[N], a[N];
int n;
void update(int x, int d = 1) {
for (; x <= n; x += x & (-x)) {
t[x] += d;
}
return;
}
int qu... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool dbg = 0;
clock_t start_time = clock();
void bad(string mes = "Impossible") {
cout << mes;
exit(0);
}
template <typename T>
string bin(T x, int st = 2) {
string ans = "";
while (x > 0) {
ans += char('0' + x % st);
x /= st;
}
reverse(ans.begin(), ans.... | 1 |
#include<bits/stdc++.h>
using namespace std;
int ab[50000],ac[50000],bc[50000];
bool check(char i,char j){
if(i=='?'||j=='?'||i==j) return 1;
return 0;
}
int main(){
string a,b,c;
cin>>a>>b>>c;
int la=a.size(),lb=b.size(),lc=c.size();
for(int i=0;i<la;i++){
for(int j=0;j<lb;j++){
if(!check(a[i],b[j]))a... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool IsFail = false;
vector<int> answer;
vector<int> parent;
vector<int> r;
vector<vector<int>> smej;
vector<bool> usd;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> a(n);
vector<int> b(n);
int max = 0;
int... | 2 |
#include<bits/stdc++.h>
int main() {
int a,b;
scanf("%d%d",&a,&b);
printf("%d",(3*a+b)/2);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5, MAXM = 1e5 + 5;
const int MAXS = 5e2 + 5;
template <typename _T>
void read(_T &x) {
x = 0;
char s = getchar();
int f = 1;
while (s < '0' || '9' < s) {
f = 1;
if (s == '-') f = -1;
s = getchar();
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const short inf = 1 << 14;
const double pi = acos(-1);
const double eps = 1e-9;
const int mod = 1e9 + 7;
const int mf[] = {0, 0, 1, -1}, mc[] = {1, -1, 0, 0};
const int N = 1005;
mt19937 rng(
(unsigned int)chrono::steady_clock::now().time_since_epoch().count());
templat... | 6 |
#include <iostream>
using namespace std;
typedef long long ll;
ll n,m,MOD=1e9+7;
ll f(ll x,ll y){
if(y==1)return x;
if(y%2==0)return f(x,y/2)*f(x,y/2)%MOD;
return x*f(x,y-1)%MOD;
}
int main(void){
cin>>n>>m;
cout<<f(n,m)<<endl;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
int n,k,val[100005],l[100005],r[100005];
vector<int> g[100005];
void die()
{
cout<<"No"<<endl;
exit(0);
}
void solve(int v,int p)
{
l[v]=-1e9-1;
r[v]=1e9+1;
if(val[v]!=-1) l[v]=r[v]=val[v];
for(int i=0;i<g[v].size();i++)
{
int to=g[v][i];
if(to==p)
continue;
... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve();
const int MAX_N = 100001;
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const long long LINF = 1ll * 1000000 * 1000000 * 1000000;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cin >> t;
for (in... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
const int LG = 26;
int _w;
int n, dat[N], discre[N], discre_tot;
namespace BIT {
int tree[N], n;
void init(int _n) {
n = _n;
for (int i = 1; i <= _n + 1; ++i) tree[i] = 0;
}
void add(int i, int v) {
while (i <= n) tree[i] += v, i += (i & (-i));
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
map<long long, long long> m;
string s;
map<string, long long> x;
string h(long long n) {
string t = "";
while (n) {
if ((n % 10) % 2 == 0)
t += "0";
else
t += "1";
n /= 10;
}
while (t.length() < 20) t += "0";
reverse(t.begin(... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
set<int> ans;
vector<char*> vec;
void getDif(int i) {
int pos = 0;
int dif = strcmp(vec[i] + pos, vec[i + 1] + pos);
while (dif > 0) {
while (vec[i][pos] == vec[i + 1][pos]) pos++;
ans.insert(pos);
pos++;
dif = strcmp(vec[i] + pos, vec[i + 1]... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007
#define MAX_N 200005
ll inv[MAX_N], fact[MAX_N], ifact[MAX_N];
int C(int n, int k){
if(n<k) return 0;
return fact[n]*ifact[k]%MOD*ifact[n-k]%MOD;
}
void prepare(){
inv[1]=fact[0]=fact... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int M = 1e2 + 5;
const int inf = 2000000000;
const int md = 1e9 + 7;
const long double eps = 0.000000001;
long long n, m, x, i;
char c;
string s;
multiset<long long> st;
map<long long, int> mp;
long long get(long long x) {
int f = 1;
int ans ... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
ll N, H;
cin >> N >> H;
ll ng = 10000000000, ok = 0;
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (mid * (mid + 1) / 2 <= N) {
ok... | 4 |
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int fa[N];
int num[N];
int getfa(int x)
{
return fa[x]==x?x:(fa[x]=getfa(fa[x]));
}
int main()
{
int n,m,x,y,fx,fy,res=1;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)fa[i]=i,num[i]=1;
for(int i=1;i<=m;i++)
{
scanf("%d%d",&x... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N, K, L;
int x[30], a[110];
int dist[10010];
int graph[30][30];
int dp[(1 << 20)];
queue<int> q;
void add(int pos, int d) {
if (d < dist[pos]) {
dist[pos] = d;
q.push(pos);
}
}
void bfs(int start) {
int i;
for ((i) = 0; (i) < (int)(N + 1); (i)++) dist[i]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e5 + 1;
bool dead[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
int mx = 3 * n;
for (int i = 1; i < mx + 1; i++) dead[i] = 0;
vector<int> ind;
vector<int... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int x1, x2, y1, y2;
long long int k;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2 || y1 == y2)
k = abs(x1 - x2) + abs(y1 - y2);
else
k = 2 + abs(x1 - x2) + abs(y1 - y2);
cout << k <... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int N = 4e2+9;
const ll INF = 1LL<<60;
int n;
ll dp[N][N];
ll a[N];
ll sum[N];
ll rec(int l, int r) {
if(dp[l][r]) return dp[l][r];
if(l == r) return dp[l][r] = 0;
ll res = INF;
for(int i = l; i < r; i++)
res = mi... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a = 0, b;
cin >> b;
b++;
int m;
cin >> m;
for (int i = 0; i < m; i++) {
string s1, s2, s3, s4;
int k;
cin >> s1 >> s2 >> s3 >> s4 >> k;
if (s3[0] == 'l' && k < b) b = k;
if (s3[0] == 'r' && k > a) a = k;
}
if (b - a > 1)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
map<int, long long> s;
vector<int> a(n);
long long counter = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
int to = a[i] ^ x;
if (s.find(to) != s.end()) {
counter += s[to];
}
s[a[i]]++;
}
cout <... | 2 |
#include <bits/stdc++.h>
const int N = 500500;
const int Q = 1 << 21;
const long long mod = 998244353;
using namespace std;
int n;
int m;
int a[N];
int b[N];
vector<int> g[N];
vector<int> v[N];
bool can(int x) {
for (int i = 0; i < N; i++) {
v[i].clear();
}
for (int i = 1; i <= n; i++) {
b[i] = a[i];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
char a[maxn];
int wa[maxn], wb[maxn], wv[maxn], wts[maxn];
int cmp(int *r, int a, int b, int l) {
return r[a] == r[b] && r[a + l] == r[b + l];
}
void init_sa(char *r, int *sa, int n, int m) {
int i, j, *x = wa, *y = wb, *t;
int p;
for (i = 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 2e5 + 17;
char s[Nmax], t[Nmax];
bool v[Nmax] = {0};
int a[256] = {0};
int main(void) {
scanf("%s%s", &s, &t);
for (int i = 0; t[i]; i++) a[t[i]]++;
int x = 0, y = 0;
for (int i = 0; s[i]; i++)
if (a[s[i]]) {
a[s[i]]--;
v[i] = 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef struct {
int speed, ram, hdd, pri, id;
} COM;
COM lap[102], lap2[102];
int dump[102];
bool cmp(COM a, COM b) { return a.pri < b.pri; }
int main(void) {
int n, i, j, cnt, flag, ansc;
while (scanf("%d", &n) == 1) {
for (i = 0; i < n; ++i) {
scanf("%d%d... | 2 |
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
struct data{
int t;
ll p,f;
data(){}
data(int tt,ll pp,ll ff){
t=tt;
p=pp;
f=ff;
}
bool operator<(const data &d)const{
if(f==d.f)return p<d.p;
return f<d.f;
}
};
struct CHTrick{
deque... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e18;
int ptrl = 1;
int ptrr = 0;
long long curval = 0;
int a[100011];
int cnt[100011];
long long dp[2][100011];
void go(int l, int r) {
while (ptrl > l) {
ptrl--;
curval += cnt[a[ptrl]];
cnt[a[ptrl]]++;
}
while (ptrr < r) {
ptrr++;
... | 6 |
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
cout << (n / 10 == 9 || n % 10 == 9 ? "Yes" : "No") << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const double eps = 1e-9;
const int INF = inf;
const double EPS = eps;
struct __timestamper {};
const int PER = 60;
class segm_tree {
struct Data {
int toadd[PER];
Data() { fill(toadd, toadd + PER, 0); }
Data(int x) {
assert(2 <= x &&... | 4 |
#include <bits/stdc++.h>
using namespace std;
constexpr double EPS = 1e-14;
struct vec2 {
double x, y;
vec2 operator+(const vec2 rhs) {
return {x + rhs.x, y + rhs.y};
}
vec2 operator-(const vec2 rhs) {
return {x - rhs.x, y - rhs.y};
}
vec2 operator*(const double k) {
ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, h;
while (cin >> n >> m >> h) {
vector<int> a, b;
vector<vector<int> > d;
a.resize(m);
b.resize(n);
d.resize(n);
for (int i = 0; i < m; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int l, r, k;
cin >> l >> r >> k;
k %= (r - l + 1);
rotate(s.begin() + l - 1, s.begin() + r - k, s.begin() + r);
}
cout << s << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cout.write(nam... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 74;
struct P {
int x, y, z;
} pre[N][N][N], p;
int n, d[N][N][N];
char t[N][N];
vector<int> g[N][144];
int main() {
scanf("%d %d %d %d", &n, &p.x, &p.y, &p.z);
memset(d, -1, sizeof(d));
d[p.x][p.y][p.z] = 0;
queue<P> q;
q.push(p);
for (int i = 1;... | 4 |
#include<stdio.h>
int main(){
int x,y;
scanf("%d%d",&x,&y);
printf("%d",x+y/2);
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<max((a+b),max((a-b),(a*b)));
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long m = 1000000007) {
if (b == 0) return 1;
if (b == 1) return a;
long long res = power(a, b / 2, m);
res = (res * res) % m;
if (b & 1) res = (res * a) % m;
return res;
}
long long modinv(long long a, long long m =... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, current, last = 0, rest = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> current;
if ((current == last) || (current == 0)) {
rest++;
current = 0;
}
if (current == 3) {
if (last == 1) {
last = 2;
} ... | 3 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> A[4], B[4];
long long int Kierunek(const pair<int, int>& a, const pair<int, int>& b,
const pair<int, int>& c) {
pair<int, int> p1 = make_pair(b.first - a.first, b.second - a.second);
pair<int, int> p2 = make_pair(c.first - a.first, ... | 3 |
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
queue<int>q;
map<int,int>::iterator mt;
void init(){
mt=mp.end();
mt--;
}
bool erase(int u,int v){
if(!mp[u])return 0;
q.push(u);
mp[u]--;
if(!mp[v])return 0;
q.push(v);
mp[v]--;
while((*mt).second==0 and mt!=mp.begin()){
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
int fa = s[0] == 'a';
int n = s.size();
cout << "0"
<< " ";
for (int i = 1; i < n; i++) {
if (fa && s[i] == 'b' && i < n - 1 && s[i + 1] == 'a') {
fa =... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
scanf("%lld", &t);
while (t--) {
long long x, y;
scanf("%lld %lld", &x, &y);
if (x == y)
cout << "YES\n";
else if (x % 2 != 0) {
if (x <= 3) {
if (y > x)
cout << "NO\n";
else
cou... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a;
int i = 1;
bool open = 0;
while (i <= 5) {
cin >> b;
if (b[0] == a[0] or b[1] == a[1]) {
open = 1;
break;
}
i++;
}
if (open == 1)
cout << "Yes";
else
cout << "No";
return 0;
}
| 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
template <class T>
inline void scan_d(T &ret) {
char c;
int flag = 0;
ret = 0;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
if (c == '-') {
flag = 1;
c = getchar();
}
while (c >= '0'... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
return x * x;
}
template <class T>
inline T parse(const string &s) {
T x;
stringstream ss(s);
ss >> x;
return x;
}
const double EPS = 1e-12;
const int INF = 1000 * 1000 * 1000;
const long long LINF = INF * 1ll * INF;
const do... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(int argv, char** argc) {
cin.sync_with_stdio(0);
int n;
cin >> n;
int nums[n];
for (typeof(n) i = 0; i < n; i++) {
cin >> nums[i];
}
for (typeof(n) i = 0; i < n; i++) {
int min_dist = INT_MAX;
if (i > 0) min_dist = nums[i] - nums[i - 1];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long powCount(long long a, long long b) {
long long count = 0;
while (a % b == 0) {
a /= b;
count++;
}
return count;
}
long long power(long long a, long long b) {
long long res = 1;
while (b--) {
res *= a;
}
return res;
}
int main() {
long... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10;
const long long mod = 3e18;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n, m, i, j, k;
cin >> n >> m;
set<int> s;
for (i = 0; i < n; i++) {
cin >> k;
s.insert(k);
}
long long cost = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
inline int D() {
int m;
cin >> m;
return m;
}
inline long long lD() {
long long m;
cin >> m;
return m;
}
inline double dD() {
double m;
cin >> m;
return m;
}
int a[100006];
int m... | 1 |
#include <bits/stdc++.h>
using namespace std;
int x, y, a, b;
char A[1005], B[1005];
int main() {
scanf("%s%s", A, B);
a = strlen(A);
b = strlen(B);
for (int i = 0; i < a; ++i)
if (A[i] == '1') ++x;
for (int i = 0; i < b; ++i)
if (B[i] == '1') ++y;
if (x & 1) {
if (y <= x + 1)
puts("YES");... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5005;
const long long mod = 998244353;
long long n, a[maxn], c[maxn];
long long sum[maxn], dp[maxn][maxn];
long long find(long long x) {
long long l = 1, r = x, res = 0;
while (l <= r) {
long long mid = (l + r) >> 1;
if (2 * a[mid] <= a[x]... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int AKA = 1e6 + 6;
int a[AKA];
int SD() {
int x;
scanf("%d", &x);
return x;
}
int main() {
int n = SD(), m = SD(), k = SD(), ans = 0;
for (int i = 1; i <= m; ++i) a[i] = 1e9;
for (int i = 0; i < n; ++i) {
int x = SD(), y = SD();
a[x] = min(a[x], y)... | 1 |
#include <cstdio>
#include <algorithm>
using namespace std;
int v[200010], ap[200010];
int cover[200010];
int main ()
{
// freopen ("file.in", "r", stdin);
int n, m;
scanf ("%d %d", &n, &m);
for (int i = 1; i <= n; ++i)
{
scanf ("%d", &v[i]);
++ap[v[i]];
}
for (int i = 1... | 0 |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int h,n,a[1001],b[1001],dp[10001],ans=1e9;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>h>>n;
for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
for(int i=1;i<=h;i++) dp[i]=1e9;
for(int i=0;i<=h;i++)
for(int j=1;j<=n;j++){
if(i+a[j]>=h){ ans... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long N = 1e5 + 10;
vector<pair<long long, long long> > g[N];
vector<pair<pair<long long, long long>, long long> > edge;
long long dis[N];
void dijkstra(long long src) {
memset(dis, 63, sizeof dis);
set<pair<long long, long long> ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int as[100005], flag = 0, flag2 = 0;
string arr;
cin >> arr;
if (arr[0] == 'a')
as[0] = 1;
else
as[0] = 0;
for (int i = 1; i < arr.size(); i++) {
if (arr[i] == 'a')
as[i] = as[i - 1] + 1;
else
as[i] = as[i - 1];
}
int... | 2 |
#include<bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define Speed_UP ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#warning Remember to change t
inline ... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
using namespace std;
long long poww(long long a, long long b, long long md) {
return (!b ? 1
: (b & 1 ? a * poww(a * a % md, b / 2, md) % md
: poww(a * a % md, b / 2, md) % md));
}
const int maxn = 300 + 5... | 5 |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while (t--) {
ll n;
cin>>n;
ll r[n];
vector<pair<ll, ll>> path(n+1);
path[0] = {1, 1};
for (int i = 0; i < n; i++) {
cin>>r[i];
}
for (int i... | 6 |
#include <bits/stdc++.h>
int main() {
int n, m;
scanf("%d %d", &n, &m);
int a[n][m];
int x[2500], y[2500], x1 = 0, y1 = 0, YES = 0;
for (int i = 0; i < 2500; i++) {
x[i] = 51;
y[i] = 51;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &a[i][j]);
if (a[i][j... | 1 |
#include <bits/stdc++.h>
using namespace std;
int cont;
vector<vector<int> > adj, adj2;
vector<int> vis, dfsnum, dfslow, dualdfsnum, comp;
vector<pair<int, int> > bridgeslist;
queue<pair<int, int> > qu;
set<pair<int, int> > st;
int bridges(int cur, int pater) {
vis[cur] = 1;
dfsnum[cur] = dfslow[cur] = ++cont;
du... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m = 999999999, minimum = 999999999;
int newa, newb;
cin >> n;
long long a = 0, b = 1;
for (a = 1; a <= n; ++a) {
if (n % a == 0) {
if (a <= n / a) {
if (abs(b - a) < m) {
b = n / a;
newa = a;
... | 1 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') w = -1, ch = getchar();... | 0 |
#include <iostream>
using namespace std;
int euler_phi(int n){
int res = n;
for(int i=2;i*i<=n;i++){
if(n % i == 0){
res = res / i * (i - 1);
for(;n%i==0;n/=i);
}
}
if(n != 1) res = res / n * (n - 1);
return res;
}
const int N = 1000000;
long long dat[N+1], t, n;
int main(){
dat[0] = 1;
for(int i=1... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long extgcd(long long a, long long b, long long &x, long long &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
long long g = extgcd(b, a % b, y, x);
y -= (a / b) * x;
return g;
}
long long chinese_remainder(long long cnt, long long a[], long long m[]) {
... | 5 |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#includ... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int i, j, k, m, n, ans = 0, cnt = 0;
cin >> n;
string s;
cin >> s;
long long int sum = 0;
for (int i = 0; i < s.length(); i++) {
sum += (s[i] - '0');
}
long long int dif = n - sum;
bool flag = 1;
for (int i = 0; i < s.length(... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int N = 3e5 + 3;
const int mod = 1e9 + 7;
int n;
ll a[N];
template <class T>
struct FT {
vector<T> tree;
int sz;
FT(int n) { sz = n, tree.resize(n + 1); }
T get(int i) {
if (i <= 0 |... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
char a[N], b[N], ans[N];
int main() {
scanf("%s", a);
scanf("%s", b);
int n = strlen(a);
sort(a, a + n);
sort(b, b + n);
reverse(b, b + n);
int la = 0, lb = (n + 1) >> 1;
int ra = 0, rb = n >> 1;
int l = 0, r = n;
for (int i = 0; i... | 3 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
string s;
string arr[20], mark[20];
void solve() {
int n;
cin >> n;
int ans = 0;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
mp[arr[i]]++;
}
for (int i = 1; i <= n; i++) {
if (mp[arr[i]] != 1) {
ans++;
for (int k = ... | 2 |
#include <bits/stdc++.h>
inline int max(int x, int y) { return x > y ? x : y; }
int V, E, k, l, r, o, u, v, w, x, G[8 + 1][300 + 1][300 + 1],
F[2][300 + 1][300 + 1];
int main() {
scanf("%d %d", &V, &E);
for (k = 0; (1 << k) <= V; ++k)
for (u = 1; u <= V; ++u)
for (v = 1; v <= V; ++v) G[k][u][v] = -0x3... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct Martix {
long long a[100][100];
};
Martix unit;
Martix operator*(Martix a, Martix b) {
Martix ans;
memset(ans.a, 0, sizeof(ans.a));
int i, j;
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
long long r = 0;
for (int k = 0; k < 2; k++) {
... | 2 |
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
CIN_ONLY{
ios::sync_with_stdio(false);cin.tie(0);
}
}}star;
#define DEBUG if(0)
#endif
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(b... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dp[55][55][55];
char dr[55][55];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%s", dr[i] + 1);
memset(dp, 63, sizeof(dp));
for (int i = 1; i <= n; ++i)
for (int j = i; j <= n; ++j) dp[i][j][n + 1] = 0;
for (int i = n; i >= 1; ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
void solve() {
long long a, b;
cin >> a >> b;
map<char, long long> mp;
string s = to_string(a);
string t = to_string(b);
for (long long i = 0; i < s.size(); i++) mp[s[i]]++;
if (t.size() > s.size(... | 3 |
#include<bits/stdc++.h>
#define LL long long
static const LL INF = 1<<50;
using namespace std;
int n,k,ans;
LL s[10001];
string num[11];
int t=0;
void cal(string sum,int depth,int bit){
if(depth==k){
int num;
num=atoi(sum.data());
s[t]=num;
t++;
return;
}
for(int i=... | 0 |
#include <bits/stdc++.h>
using namespace std;
class Graph {
public:
int n;
vector<vector<int> > adj;
vector<int> a;
vector<bool> dp;
Graph(int n) {
this->n = n;
a.resize(n + 1);
adj.resize(n + 1);
dp.resize(n + 1, false);
}
void add_edge(int u, int v) { adj[u].push_back(v); }
void creat... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
printf("%d\n", ((n - 1) * 6 + 5) * k);
for (int i = 0; i < n; i++)
printf("%d %d %d %d\n", (6 * i + 1) * k, (6 * i + 2) * k, (i * 6 + 3) * k,
(i * 6 + 5) * k);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool uax(T &x, T y) {
return (y > x) ? x = y, true : false;
}
template <typename T>
inline bool uin(T &x, T y) {
return (y < x) ? x = y, true : false;
}
void err(istream_iterator<string>) {}
template <typename T1, typename T2>
ostream &opera... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long num[1010], ans;
void ok(long long x, long long y, long long n, long long m) {
for (long long i = 0; i < 10; i++) num[i] = 0;
if (!n) num[0]++;
if (!m) num[0]++;
while (n) {
num[x % 7]++;
x /= 7;
n /= 7;
}
while (m) {
num[y % 7]++;
y... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string S;
getline(cin, S);
long long tam = S.size();
long long e;
sort(S.begin(), S.end());
long long total = 0;
for (long long i = 0; i < tam; i++) {
e = count(S.begin(), S.end(), S[i]);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, q, cnt = 0, pre[100005] = {0}, l[100005], r[100005],
ok[100005] = {0}, sum[100005];
vector<int> v[100005];
void dfs(int now) {
++cnt;
l[now] = cnt;
sum[now] = 1;
for (int i = 0; i < v[now].size(); i++) {
int t = v[now][i];
dfs(t)... | 4 |
#include <bits/stdc++.h>
using namespace std;
int mod;
struct Matrix {
long long a[2][2];
Matrix operator*(const Matrix& t) const {
Matrix c;
memset(c.a, 0, sizeof(c.a));
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
c.a[i][j] += a[i][k... | 4 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
ll n;
c... | 2 |
#include <cstdio>
#include <algorithm>
#define LL long long
#define INF 2000000000
#define maxn 1010
using namespace std;
int n,m;
int k[][2]={{-1,0},{1,0},{0,-1},{0,1}};//L,R,U,D
int border[maxn][maxn][4];//边界
int vis[maxn][maxn],qx[maxn*maxn],qy[maxn*maxn];
LL ans;
struct node{
int a,b,c;
}f[maxn],g[maxn];
int X[max... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s[0] >= 'a' && s[0] <= 'z') s[0] -= 32;
cout << s;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 10;
const long long MOD = 1e9 + 7;
const long double EPS = 1e-9;
const int N = 81;
const int M = 1e3 + 10;
int d[N][N][N][2];
int a[N][N];
int main() {
ios_base::sync_with_stdio(false);
int n, k1;
cin >> n >> k1;
int m;
cin >> m;
for ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 18;
int it[maxn], m;
long long a[maxn];
long long b[maxn];
void read() { cin >> m; }
void update_(int pos, int k) {
while (pos) {
it[pos] += k;
pos -= pos & (-pos);
}
}
void update(int pos, int k) {
while (pos < maxn) {
it[pos] += k;
... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
template <typename T>
inline T abs(T a) {
return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
return a * a;
}
template <class T>
T gcd(T a, T b) {
return a ? gcd(b % a, a) : b;
}
template <class T>
T lcm(T... | 5 |
#include<bits/stdc++.h>
#define Min(a,b,c) min(a,min(b,c))
#define Max(a,b,c) max(a,max(b,c))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const double pi = 3.141592653589793;
const double eps = 1e-8;
ll nxt[20000010];
voi... | 4 |
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
int n;
cin >> n;
ll a[n], sum = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
sum += a[i];
}
ll ans = 1ll<<60, tmp = 0;
for(int i = 0; i+1 < n; i++){
tmp += a[i];
ans = min(ans, abs(sum-t... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool f[5050][5050], fl[5050];
int pre[5050][5050], n, m, a[5050], aim, sum, to, tof, inf = 1e9;
int main() {
cin >> n >> m >> aim;
f[0][0] = 1;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
sum += a[i];
int x = a[i] % m;
for (int j = 0; j < m; ++j) f[i][... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long a[300005];
int main() {
int n;
cin >> n;
for (int i = (1); i <= (n); i++) cin >> a[i];
sort(a + 1, a + n + 1);
long long idx = 1, ans = 0;
for (int i = (1); i <= (n); i++) {
ans += abs(a[i] - idx);
idx++;
}
cout << ... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.