solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 600010;
const int INF = 1 << 30;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
int n, m, k;
vector<int> g[maxn], w[maxn];
map<pair<int, int>, int> mapp;
queue<int> que;
int d[maxn];
int r[maxn], c[maxn];
bool inq[maxn];
void link(int u, in... | 4 |
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
int MOD = 1000000007;
int MAXINT = 2147483647;
long long INFLL = 1000000000000000000LL;
long long MAXLL = 9223372036854775807LL;
int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int my[8] = {0, 0, -1, 1, -1, 1, -1, 1};
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long arr[4000][4000];
long long M(long long a) { return (a + 1000000007) % 1000000007; }
long long f(long long a, long long b, long long x, long long y) {
if (arr[a][b] == 0 || arr[x][y] == 0) return 0;
long long tab[n][m];
for (long long i = 0; i... | 4 |
#include <bits/stdc++.h>
void solve(long long n, long long k, long long val) {
if (n - 2 * k + 1 <= val) {
if (val % 2) {
printf(".");
} else {
printf("X");
}
} else {
printf(".");
}
}
int main() {
long long n, k;
int q;
scanf("%I64d%I64d%d", &n, &k, &q);
for (int i = 0; i < q;... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int a[1000000];
int main() {
long long int n, d;
cin >> n >> d;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
}
long long int ans = 0;
for (long long int i = 0, j = 0; i < n; i++) {
while (j < n && a[j] - a[i] <= d) {
ans += ((j - ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 113;
const long long INF = 2e18 + 113;
int c, v, mx, add, l;
int ans = 1;
int main() {
cin >> c >> v >> mx >> add >> l;
c = max(0, c - v);
v = min(mx, v + add);
while (c) {
c += l;
++ans;
c = max(0, c - v);
v = min(mx, v + add);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> lucky;
void gen(long long num) {
if (num > 44444444444) return;
if (num > 0) lucky.push_back(num);
gen(num * 10 + 4);
gen(num * 10 + 7);
}
int main() {
gen(0);
sort(lucky.begin(), lucky.end());
long long l, r;
cin >> l >> r;
long long prv... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int l = s.length();
long long maxx = 1;
for (int i = 0; i < l; i++) {
maxx *= (s[i] - '0');
}
if (l == 1) {
cout << s << endl;
return 0;
}
for (int i = 1; i < l; i++) {
long long ans = 1;
for (int j = 0;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double MAXN = 10000000;
const int MAX2 = 1e8 + 1;
long long absl(long long a, long long b) { return (a < b) ? (b - a) : (a - b); }
long long power(long long a, long long b) {
long long res = 1ll;
a = a;
while (b > 0) {
if (b & ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 105;
int a[maxN][maxN], cot[maxN], dong[maxN], d_dong[maxN], d_cot[maxN];
int n, m;
void update(int i, int j) {
dong[i] += -2 * a[i][j];
cot[j] += -2 * a[i][j];
a[i][j] = -a[i][j];
}
int check_dong() {
for (int i = 1; i <= n; i++)
if (dong[i] < ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
template <class T>
inline T biton(T n, T pos) {
return n | ((T)1 << pos);
}
template <class T>
inline T bitoff(T n, T pos) {
return n & ~((T)1 << pos);
}
template <class T>
inline T ison(T n... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int i, f, g;
node(int k) : i(k) {}
};
vector<node> a[1000 + 10];
int i, j, k, m, n, l;
bool cmp(node a, node b) { return a.i < b.i; }
void getF(int i) {
j = k = 0;
while (j < ((int)(a[i]).size()) && k < ((int)(a[i + 1]).size())) {
if (a[i][j].i < a... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct pnt {
int x, y, idx;
bool operator<(const pnt &p) const {
return pair<long long, long long>(x, y) <
pair<long long, long long>(p.x, p.y);
}
} a[2005];
struct line {
int dx, dy, i1, i2;
};
vector<line> v;
int n, rev[2005... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, L;
int v[N];
char S[N];
char Str[N][N];
char Lower(char ch) {
if (ch >= 'A' && ch <= 'Z') return ch - 'A' + 'a';
return ch;
}
char Uper(char ch) {
if (ch >= 'a' && ch <= 'z') return ch - 'a' + 'A';
return ch;
}
int main() {
scanf("%d", &n... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long k;
cin >> k;
long long len = 1, num = 9;
while (k > len * num) {
k -= len * num;
++len, num *= 10;
}
num /= 9;
long long bel = num + (k - 1) / len;
for (int n = len - 1 - (k - 1) % len; n > 0; n--) bel /= 10;
cout << bel % 10... | 1 |
#include<bits/stdc++.h>
#define N 600005
using namespace std;
int n,m,l,r,c[N];
struct node{int l,r,len;}a[N];
inline bool cmp(node aa,node bb){return aa.len<bb.len;}
inline int lowbit(int x){return x&-x;}
inline void add(int x,int y){for(int i=x;i<=m;i+=lowbit(i))c[i]+=y;}
inline int sum(int x){int ans=0;for(int i=x;i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n; cin >> n;
int p = 0;
while (p * (p+1) / 2 < n) p++;
for (int i = 1; i <= p; i++) {
if (p * (p+1) / 2 == n + i) continue;
cout << i << "\n";
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string remex(string s) {
string t = "";
for (int i = 0; s[i]; i++)
if (s[i] == '*' || s[i] == '?')
continue;
else
t += s[i];
return t;
}
void solve() {
string s;
cin >> s;
int k;
cin >> k;
int cnt1 = 0, cnt2 = 0;
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(NULL);
ios::sync_with_stdio(false);
int n;
cin >> n;
int a;
vector<int> v;
v.push_back(0);
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(a);
}
int f1 = 0, f2 = 0, b1 = 0, b2 = 0;
for (int i = 1; i <= n; i++) {
b2 ... | 2 |
#include <bits/stdc++.h>
const int N = (1 << 22);
using namespace std;
int a[N], dp[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < (n); i++) {
cin >> a[i];
dp[a[i]] = a[i];
}
int yek = (1 << 22) - 1;
for (int i = 0; i < (N); i++)
for (int j = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long add(long long a, long long b, long long c) {
long long res = a + b;
return (res >= c ? res - c : res);
}
long long mod_neg(long long a, long long b, long long c) {
long long res;
if (abs(a - b) < c)
res = a - b;
else
res = (a - b) % c;
return (... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;
map<ll, ll> S;
ll Q;
ll R;
int main() {
cin >> N;
for (ll i = 0; i < N; ++i) {
ll a;
cin >> a;
++S[a];
R += a;
}
cin >> Q;
for (ll q = 0; q < Q; ++q) {
ll b, c;
cin >> b >> c;
R += (c - b) * S[b];
S[c]... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
if (!b) return a;
return gcd(b, a % b);
}
map<string, int> mp;
string minn, maxx;
int temp[6000];
struct num {
int def, ope;
string s, v1, v2, val;
int id1, id2;
} f[5010];
int getbit(int n, int bit, int def) {
int sum = 0;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int n;
vector<int> a[200];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;
cin >> n;
int k = (1 + sqrt(1 + 8 * n)) / 2, x = 1;
cout << k << endl;
for (int i = 1; i <= k; i++) {
for (int j = i + 1; j <= k; j... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using dl = double;
const int N = 2e5 + 10;
ll aarray[200000 + 10];
ll magic[101][101];
vector<ll> primes;
bool fk[1000001];
int main() {
ios_base::sync_with_stdio(false);
string str, ptr, ps[1001], ss[1001], ans;
ll n, m, a, j, k, i, p, four ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 3e2, M = 3e5 + 3e2, inf = 2e9 + 10;
inline int fastmin(int x, int y) { return (((x - y) >> 31) & (x ^ y)) ^ y; }
int ANS[M], NEW[N], A[N], UNQ[N], DF[N], DS[N], n, q, sz, l, r, a;
vector<int> FIXR[N], FIXRID[N];
void addf(int ind, int d) {
for (ind = (... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii>... | 0 |
#include <bits/stdc++.h>
using namespace std;
class A {
public:
void solveOne(istream &in, ostream &out) {
int n, v;
in >> n >> v;
set<int> s;
for (int i = 0; i < n; ++i) {
int x;
in >> x;
for (int j = 0; j < x; ++j) {
int y;
in >> y;
if (v > y) {
s... | 1 |
//yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)
//<ここに一言>
//せんげん!
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <cctype>
#include <utility>
#include <... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>... | 4 |
#include <bits/stdc++.h>
using namespace std;
int t, d, l;
vector<int> x;
int solve();
int main() {
while(1) {
cin >> t >> d >> l;
if(t + d + l == 0) break;
x.assign(t, 0);
for(int i = 0; i < t; ++i) cin >> x[i];
cout << solve() << endl;
}
return 0;
}
int solve() {
int ans = 0, lim = -1... | 0 |
#include <bits/stdc++.h>
using namespace std;
class knight {
public:
long long int pow, ind, coin;
};
bool cmp1(knight k1, knight k2) { return k1.pow < k2.pow; }
bool cmp2(knight k1, knight k2) { return k1.ind < k2.ind; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long dp[1012][1012][2];
int k, t, lmax;
char s[1200], in[1200];
long long dfs(int pos, int last, int st, int state) {
if (pos < 1) {
return st == 1;
}
if (!state && dp[pos][last][st] != -1) return dp[pos][last][st];
int u = state ? s[pos] - '0' : 9;
long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, k;
vector<int> a;
vector<int> group;
vector<int> id;
int main(int argc, char *argv[]) {
cin >> n >> k;
a.resize(n + 1);
group.resize(k + 1);
id.resize(k + 1);
int sum = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
sum += a[... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
const int INF = INT_MAX;
const int mod = 1e9 + 7;
const long long LINF = LLONG_MAX;
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> p(n);
for (int i = 0; i < (n); i++) cin >> p[i];
for (int i = (1); i < (n); i++) {
l... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char mapp[110];
int vis[110];
int sum;
while (scanf("%s", mapp) != EOF) {
memset(vis, 0, sizeof vis);
int len = strlen(mapp);
int sum = 0;
for (int i = 0; i < len - 1; i++) {
if (mapp[i] == 'V' && mapp[i + 1] == 'K') {
vis[... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e10 + 7;
const long double eb = 1e-9;
const long long mod = 1e9 + 7;
template <class T>
T add(T v1, T v2, long long mo = mod) {
return (v1 % mo + v2 % mo) % mo;
}
template <class T>
T subtract(T v1, T v2, long long mo = mod) {
return (v1 % mo - v2... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int a[N], num[N];
int main() {
int n;
cin >> n;
bool flag = false;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] != 0) flag = true;
}
if (flag) {
cout << "YES" << endl;
int sum = 0, cnt = 0;
num[cnt++] = 1;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int arr[262144 << 1];
arr aa, bb;
long long int *f = aa + 1;
long long int *ff = bb + 1;
long long int *g;
struct Node {
Node *le, *ri;
long long int del, sum, base;
Node() : le(0), ri(0), del(0), sum(0), base(0) {}
} * A, *B;
Node *buildtree(int l, ... | 5 |
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265359
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
ll s = a[0] + a[1], x = 0;
for (int i = 2; i < n; i+... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int t;
cin >> t;
while (t--) {
long long l, r, d;
cin >> l >> r >> d;
if (d < l)
cout << d << "\n";
else {
cout << ((r / d) + 1) * d << "\n";
}
}
return 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
int d[70][70][70], ans[70][70][70];
int m, n, r;
const int INF = 1 << 30;
void floyd(int t) {
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
d[t][i][j] = min(d[t][i][j], d[t][i][k] + d[t][k][j]);
}
int main() {
c... | 4 |
#include <bits/stdc++.h>
struct STUD {
int id;
bool notified;
int msg_left;
};
int main() {
int n;
int sum = 0;
scanf("%d", &n);
STUD* stud = new STUD[n];
for (int i = 0; i < n; i++) {
stud[i].id = i + 1;
scanf("%d", &stud[i].msg_left);
sum += stud[i].msg_left;
stud[i].notified = false;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int H, W; string s[509];
int main() {
cin >> H >> W;
for(int i = 0; i < H; i++) {
cin >> s[i];
for(int j = 0; j < W; j++) {
cout << (j != W - 1 && (s[i][j] == '#' || j == 0 || i % 2 == 0) ? '#' : '.');
}
cout << endl;
}
cout << endl;
for(int i = 0; i < H; i+... | 0 |
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#incl... | 0 |
#include <bits/stdc++.h>
using namespace ::std;
int main() {
int t;
cin >> t;
while (t--) {
long long int l, r;
cin >> l >> r;
cout << (r / l + 1) * (r / l + 1) * (r % l) +
(l - r % l) * (r / l) * (r / l)
<< endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, sum, t1, t2;
string s;
cin >> n >> k;
cin >> s;
sum = k / 2;
t1 = sum;
t2 = sum;
for (int i = 0; i < n; i++) {
if ((s[i] == '(') && (t1 > 0)) {
t1--;
cout << '(';
} else if ((s[i] == ')') && (t2 > 0) && (t2 > t1)) {... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(0);cin.tie(0);
int n,t=0;
cin>>n;
long long int a[n+5],ans[2]={0};
for(int i=0 ; i<n ; i++)
cin>>a[i];
sort(a,a+n,greater<int>() );
for(int i=0 ; i<n ; i++)
{
if(a[i]==a[i+1]) ans[t++]=a[i],i++;
if(t==2) break;
}
cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
string s;
int mark[N], dp[N][30], c;
vector<int> adj[N];
void dfs(int v) {
mark[v] = 1;
dp[v][s[v - 1] - 'a'] = 1;
for (int u : adj[v]) {
if (mark[u] == 1) {
c = 1;
continue;
}
if (mark[u] == 0) dfs(u);
for (int j = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, cnt = 0;
string st1, st2;
set<pair<string, string> > v;
cin >> n;
cnt = n;
for (i = 0; i < n; i++) {
cin >> st1 >> st2;
v.insert(make_pair(st1, st2));
}
cout << v.size() << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, m, max = -1, fristRow = -1, FristCoulmn = 0, lastRow = 0,
lastColumn = 0;
cin >> x >> m;
char arr[1000][1000];
for (int i = 0; i < x; i++) {
for (int j = 0; j < m; j++) {
cin >> arr[i][j];
if (arr[i][j] == '*') {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, a[210];
cin >> n >> k;
for (int(i) = 0; (i) < (n); i++) cin >> a[i];
int res = -(1e9);
for (int(R) = 0; (R) < (n); R++)
for (int(L) = 0; (L) < (R + 1); L++) {
vector<int> v;
int sum = 0;
for (int i = L; i <= R; i++) {
... | 1 |
#include<complex>
#include<stdio.h>
#define F(a,b,c) acos((b*b+c*c-a*a)/2/b/c)
int main(){int n;double d,e,f,g,h,i;for(scanf("%d",&n);n--;){scanf("%lf%lf%lf%lf%lf%lf",&d,&g,&e,&h,&f,&i);std::complex<double> a(d,g),b(e,h),c(f,i);float A=abs(b-c),B=abs(c-a),C=abs(a-b),L=F(A,B,C),s=sin(2*L),t=sin(2*F(B,C,A)),u=sin(2*F(C,A... | 0 |
#include <bits/stdc++.h>
const double PI = acos(-1.0);
using namespace std;
int n, k, u[4005][4005], RSQ[4005][4005], COST[4005][4005], DP[805][4005];
char* buffer = new char[10000];
void dp(int k, int l, int r, int opt_l, int opt_r) {
if (l > r) return;
int m = (l + r) / 2, idx = -1, mn = 1000000000;
for (int i ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long x, long long mod) {
if (x == 0) return a == 0 ? 0 : 1 % mod;
if (x % 2) return a * powmod(a, x - 1, mod) % mod;
return powmod(a * a % mod, x / 2, mod);
}
long long invmodp(long long a, long long mod) {
return powmod(a, mod - 2... | 4 |
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, w, v;
int main() {
while (cin >> n >> w, w) {
int m = 0, p = 0, d = 0, c[100] = { 0 };
for (int i = 0; i < n; i++) cin >> v, m = max(m, v / w), c[v / w]++;
for (int i = 0; i <= m; i++) d += (m - i) * c[i], p = max(p, c[i]);
... | 0 |
//#define LOCAL
#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main()
{
#ifdef LOCAL
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
#endif
int n, S;
int r[20010];
while (true) {... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(... | 0 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int a[3];
for (long long int i = 0; i < 3; i++) cin >> a[i];
long long int ans = 0;
sort(a, a + 3);
if (a[0] + a[1] <= a[2])
a... | 1 |
#include <cstdio>
using namespace std;
long long v[2005][2005];
const int mod=1e9+7;
int main() {
long long n,k;
scanf("%lld%lld",&n,&k);
v[0][0]=1;
for(int i=1;i<=n;i++){
v[i][0]=1;
for(int j=1;j<=i;j++)
v[i][j]=(v[i-1][j-1]+v[i-1][j])%mod;
}
for(int i=1;i<=k;i++)
... | 0 |
#include<bits/stdc++.h>
#define ll long long
#define lc (id * 2)
#define rc (id * 2 + 1)
#define mid ((l + r) >> 1)
#define fi first
#define se second
using namespace std;
const int maxN = 2e5 + 5;
int p[maxN];
struct SegmentTree {
int e, st[maxN * 4];
void build(int id, int l, int r) {
if (l == r){
... | 0 |
#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
long long int getint() {
long long int ans = 0;
int f = 1;
char c;
while ((c = getchar()) < '0' || c > '9')
if (c == '-') f = -f;
while (c >= '0' && c <= '9') {
ans = ans * 10 + c - '0';
c = getchar();
}
return ans * f;
}
int lowbit(const in... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, t;
string a;
map<string, int> tb;
map<pair<int, string>, int> dp;
void solve(int ix, string pre) {
if (dp.find(make_pair(ix, pre)) != dp.end()) return;
dp[make_pair(ix, pre)] = 1;
int st;
st = ix - 1;
if (st > 4) {
string temp = a.substr(st, 2);
if ... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool dis(long long int n) {
string s = to_string(n);
for (long long int i = 0; i < s.length() - 1; i++) {
for (long long int j = i + 1; j < s.length(); j++) {
if (s[i] == s[j]) return false;
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(f... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int i, v[n + 1], x, y, ans = 0;
for (i = 1; i <= n; i++) {
cin >> v[i];
}
for (i = 0; i < m; i++) {
cin >> x >> y;
ans += min(v[x], v[y]);
}
cout << ans << "\n";
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c ;
cin>>a>>b>>c;
if(((b*10)+c )%4==0){cout<< "YES" ;}
else {cout<< "NO" ; }
return 0;
}
| 0 |
#include <bits/stdc++.h>
static inline unsigned long long rdtsc() {
unsigned long long d;
__asm__ __volatile__("rdtsc" : "=A"(d));
return d;
}
using namespace std;
const int inf = (int)1.01e9;
const double eps = 1e-9;
const int N = 2;
int mod;
struct matrix {
int a[N][N];
matrix() { memset(a, 0, sizeof a); }
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int povernut(int x) {
int res = 0;
while (x) {
res = res * 10 + x % 10;
x /= 10;
}
return res;
}
int main(int argc, char *argv[]) {
int a, b;
scanf("%d%d", &a, &b);
int res = a + povernut(b);
printf("%d", res);
return 0;
}
| 1 |
#include <iostream>
using namespace std;
string s;
int a[27];
int main() {
cin >> s;
for(int i = 0; i < s.length(); i++)
a[s[i] - 'a']++;
for(int i = 0; i < 27; i++)
if (a[i] % 2) {
cout << "No";
return 0;
}
cout << "Yes";
return 0;
} | 0 |
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
pair<int,char> A[5];
for(int f=0;f!=1;){
for(int i=0,a,b;i<5;++i){
cin>>a>>b;
if(a==0&&b==0){f=1;break;}
A[i].first=a+b;
A[i].second=(char)(i+'A');
if(i==4){
sort(&A[0],&A[5],greater<pair<int,char> >());
... | 0 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
int main() {
int a, b, n;
scanf("%d%d%d", &a, &b, &n);
double min_time;
for (int i = 0; i < n; i++) {
int x, y, v;
double time;
scanf("%d%d%d", &x, &y, &v);
time =
(double)(sqrt(pow((double)(x - a), 2) + pow((double)(y - b), 2)) / ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long r, g, b, res = 0, demores = 0, dr, dg, db;
cin >> r >> g >> b;
int k = 0;
res = r / 3 + g / 3 + b / 3;
for (int i = 0; i < 3; i++) {
if (r > 0 and g > 0 and b > 0) {
demores = (r / 3) + (g / 3) + (b / 3) + k;
res = max(res, d... | 2 |
#include <bits/stdc++.h>
using namespace std;
int dp[100][100];
vector<long long> can;
int test;
int r(long long a, long long b) {
if ((a == 0) || (b == 0)) return 0;
int k = r(b % a, a);
if (k == 0) return 1;
long long v = (b % a);
v += a;
long long c = (b - v) / a;
if (a & 1) {
int res = (c & 1);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
bool is_prime(long long x) {
if (x <= 1) return false;
for (int i = 2; i * i <= x; i++)
if (x % i == 0) return false;
return true;
}
bool is_palindrome(string s1) {
int l = s1.length();
for (int i = 0; i < l / 2;... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize(fast - math)
using namespace std;
long long powmod(long long a, long long b, long long mod) {
if (b == 0 || a == 1) {
if (mod == 1)
return 0;
else
return 1;
}
if (b % 2 == 0) {
long long k = powmod(a, b / 2, mod);
return (k * k) % mod;
} ... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> A;
vector<int> C;
vector<long long> DP(6000, 0);
vector<long long> DP2(6000, 0);
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int u;
cin >> u;
A.push_back(u);
}
C = A;
sort(C.begin(), C.end());
for (int i = 0; i < n; i++)... | 3 |
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
//#define EPS 0.000000001
using namespace std;
#define EPS 0.000000001
#define NUM 105
struct Point{
Point(){
x = y = 0;
}
Point(int arg_x,in... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a, m, t;
long long fai(long long n) {
long long sum = n;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) sum = sum / i * (i - 1);
while (n % i == 0) n /= i;
}
if (n > 1) sum = sum / n * (n - 1);
return sum;
}
long long gcd(long long x, long ... | 4 |
#include <bits/stdc++.h>
long long p, n, h[500000], r[5000000], e[500000];
char s[500000];
inline bool ispalind(long long a, long long b) {
return (h[b] - h[a - 1] * e[b - a + 1]) * e[a - 1] == r[b] - r[a - 1];
}
const long long fac = 129581259982959;
signed main() {
scanf("%lld%s", &p, s + 1);
n = strlen(s + 1);... | 4 |
#include <bits/stdc++.h>
using namespace std;
string manacher(string s) {
long long n = s.size();
vector<long long> d1(n);
for (long long i = 0, l = 0, r = -1; i < n; i++) {
long long k = (i > r) ? 1 : min(d1[l + r - i], r - i + 1);
while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) {
k++;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, int> a[200005];
vector<int> v[200005];
long long hm[200005];
priority_queue<int> pq;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%I64d", &a[i].first);
}
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i].second)... | 4 |
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;
#define ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int K, n[4], t[4];
int main() {
ios::sync_with_stdio(false);
cin >> K;
for (int i = 1; i <= 3; ++i) {
cin >> n[i];
}
for (int i = 1; i <= 3; ++i) {
cin >> t[i];
}
multiset<int> mySet[4];
for (int i = 1; i <= 3; ++i) {
for (int j = 1; j <= n[i]; +... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int extgcd(int a, int b, int &x, int &y) {
int d = a;
x = 1;
y = 0;
if (b) d = extgcd(b, a % b, y, x), y -= a / b * x;
return d;
}
int modinv(int a) {
int x, y;
extgcd(a, MOD, x, y);
return (x + MOD) % MOD;
}
int main() {
int n,... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> graph[500005];
bool visited[500005];
void dfs(long long s) {
visited[s] = true;
for (long long i = 0; i < graph[s].size(); i++) {
long long u = graph[s][i];
if (visited[u] == false) {
dfs(u);
}
}
cout << s << " ";
}
int main() {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, div = 0, d, s;
cin >> n >> m;
div = n / m;
s = div + 1;
if (m % n == 0)
for (int i = 0; i < m; i++) cout << div << " ";
else {
d = n - (m * div);
for (int i = 0; i < m; i++) {
if (i >= d)
cout << div << " ";
... | 1 |
#include<bits/stdc++.h>
using namespace std;
int n;
string s[1005];
int main()
{
scanf("%d%*d",&n);
for(int i=0;i<n;i++)
cin>>s[i];
sort(s,s+n);
for(int i=0;i<n;i++)
{
cout<<s[i];
}
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n; cout<<( (n==0) ? 1: 0);
}
| 0 |
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){ _;
int n,m;
while(cin>>n>>m,(n|m)!=0){
map<int,int> h,w;
vector<int> v;
int tmp;
REP(i,n){
cin>>tmp;
v.push_back(0);
for(int &a... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for (int z = 0; z < t; ++z) {
long long n;
cin >> n;
long long k = 0;
long long cur = 0;
long long m = (n + 2) / 3;
while (cur + (1ll << (2 * k)) < m) {
cur +... | 3 |
#include <bits/stdc++.h>
using namespace std;
const bool testcase = 0;
const long long int mod1 = 1000000007;
const long long int mod2 = 998244353;
inline long long int md(long long int x, long long int M = mod1) {
x %= M;
return ((x < 0) ? (x + M) : x);
}
bool is_prime(long long int n) {
if (n < 2) return false;... | 5 |
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int64_t mod=1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using Graph = vector<vector<int>>;
int main() {
int N,M; cin>>N>>M;
Graph G(N);
rep(i,M){
int a,b;
cin>>a>>b;
a--;
b--;
G[a].push_back(b);
G[b]... | 0 |
#include <iostream>
#include <string>
using namespace std;
int main() {
string cipher;
while (getline(cin, cipher)) {
for (int i = 0; i < 26;i++) {
for (unsigned int n = 0;n < cipher.length();n++) {
if (cipher.at(n) == 'z') {
cipher.at(n) = 'a';
}
else if (cipher.at(n) >= 'a'&&cipher.at(n) <= ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, 1, -1, 0};
long long mo = 1e9;
const long double P = 3.141592653589793238L;
void trust_yourself() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long gcd(long long x, long long y) {
if (x == 0) return y;
return ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long debug_counter = 0;
void logic() {
long long n;
cin >> n;
long long index = 1;
while (n - index > 0) {
n = n - index;
index++;
}
cout << n;
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long t;
{... | 1 |
#include <bits/stdc++.h>
using namespace std;
char d[1000001];
vector<int> seg;
int main() {
scanf(" %s", d);
int n, i;
n = strlen(d);
int p = 0;
char r = d[p];
while (d[(p + n - 1) % n] == r) p = (p + n - 1) % n;
int e = p;
while (d[(p + 1) % n] == r) p = (p + 1) % n;
seg.push_back((p - e + 1 + n) % ... | 5 |
#include <bits/stdc++.h>
using namespace std;
constexpr long double m_pi = 3.1415926535897932L;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 61;
constexpr long double EPS = 1e-10;
template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
using vector3 = vector<vector2<T>>;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int l = 0, r = k - 1, i = l;
long long int sum = 0, newsum = 0;
while (i <= r) {
sum = sum + arr[i];
i++;
}
newsum = sum;
l++;
r++;
while (r != n) {
... | 2 |
#include<map>
#include<cstdio>
int main(){
int n;
scanf("%d", &n);
long long ans = 1;
const long long mod = 1e9 + 7;
std::map<int, long long> factors;
for(int i = 2; i <= n; i++){
for(int j = 2, d = i; d > 1; j++){
while(d % j == 0){
factors[j]++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct Node {
int ty, x, y, v, id;
bool operator<(const Node& q) const {
if (x == q.x) return ty < q.ty;
return x < q.x;
}
};
Node a[N * 10], temp[N * 10];
int C[N], ans[N], p[N], q[N], _hash[N], rec[N];
int n, cnt;
int lowbit(int x) { ... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.