solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
long long r;
while (b) {
r = a % b;
a = b... | 15 |
/*
ββ β»ββββββ β»β
βγγγγγγβ
βγγγβγγγ β
βγβ³βγ ββ³γ β
βγγγγγγ β
βγγγβ»γγγ β
βγγγγγγ β
βββγγγβββββ
βγγγβ η₯ε
½δΏδ½
βγγγβ
βγγγβββββββββββ
βγγγγγγγ β£β
βγγγγ ββ
βββ β βββββ³ β βββ
β β« β« β β« β«
βββ»ββ βββ»ββ
*/
/... | 11 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> pega[200005];
int peg[200005], id[200005], rev[200005];
int main() {
ios::sync_with_stdio(false);
int n, q, p;
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> pega[i].first;
pega[i].second = i;
}
sort(pega + 1, pega + n + 1);
for (i... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MM = 1200000;
long long int m, n, k, p1, p2, p3, p, f, a[MM];
string s, s1, s2;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
m = sqrt(n);
for (long long int i = 1; i <= m; i++) {
if ((i + n) % 3 == 0) {
if ((i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-11;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<int> h[N];
long long w[N], down[N], up[N], sum_down[N], sum_up[N];
void dfs_down(int u, int fa) {
down[u] = sum_down[u] = w[u];
for (int i = 0; i < h[u].size(); i++) {
int j = h[u][i];
if (j == fa) continue;
dfs_down(j, u);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int const MAXN = 100;
int n, temp;
int arr[MAXN + 1]{};
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
arr[temp]++;
}
int ans = 0;
for (int i = 0; i <= 100; i++) {
ans += arr[i] / 2;
}
cout << ans / 2 << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int mod = (int)1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;
int head;
int p[maxn], pm[maxn], ks, rz[maxn];
vector<int> beg;
void dfs(int u) {
if (!pm[u]) {
pm[u] = ks;
rz[head]++;
dfs(p[u]);
return;
}
}
i... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
int q, n;
cin >> q;
for (int i = 0; i < q; i++) {
cin >> n;
if (n == 2)
cout << 2 << "\n";
else {
if (n % 2 != 0)
cout << 1 << "\n";
else
cout << 0 << "\n";
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
map<long long, bool> tz;
int gcd(int a, int b) {
if (a == 0)
return b;
else
return gcd(b, b % a);
}
int cnk(long long n, long long k, long long mod) {
long long result = 1;
int lal = 0;
for (int lol = n; lal < k; lal++, lol--) {
result *= lol;
resu... | 4 |
#include <bits/stdc++.h>
using namespace std;
namespace Solve1 {
const int maxn = 100005;
const int spc = 4000005;
struct SegmentTree {
int sumv[spc], lc[spc], rc[spc], rt[spc], np;
void Initial() {
np = 0;
memset(rt, 0, sizeof(rt));
memset(lc, 0, sizeof(lc));
memset(rc, 0, sizeof(rc));
memset(s... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
char ch[N];
int flag[N];
int main() {
int n, i, f;
scanf("%s", ch + 1);
n = strlen(ch + 1);
if (n == 1)
puts("0");
else {
f = 0;
for (i = 1; i <= n; i++)
if (ch[i] == '0') {
f = 1;
flag[i] = 1;
bre... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> E[301000];
int IT[524288 + 524288 + 2], n, Q, C[301000], Num[301000], cnt, Ed[301000],
ReNum[301000];
void DFS(int a) {
Num[a] = ++cnt;
ReNum[cnt] = a;
C[a] = 1;
for (int i = 0; i < E[a].size(); i++) {
DFS(E[a][i]);
C[a] += C[E[a][i]];
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const int MAXN = 200010;
pair<int, int> v[MAXN];
pair<int, int> va[MAXN];
int n, m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[500], b, tcase = 1, t, n, i, j, mx = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
mx += a[i];
}
int f = 1;
i = 1;
j = 0;
while (mx > 0) {
int fl = 1;
int x = a[i];
if (x) {
printf("P");
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
long long dp[5001][5001];
long long aa[5001], n, k;
long long dfs(long long x, long long l) {
if (x >= n) return 0;
if (l <= 0) return 0;
if (dp[x][l] != -1) return dp[x][l];
return dp[x][l] = ma... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 500 * 1000;
int ans[max_n * 2];
int main() {
int n;
cin >> n;
memset(ans, -1, sizeof ans);
int a = 0, b = n - 1, c = n, d = 2 * n - 2;
for (int i = (1); i < (n); i++)
if (i & 1) {
ans[a] = ans[b] = i;
a++, b--;
} else {
... | 11 |
#include <bits/stdc++.h>
int main() {
char arr1[103];
char arr2[103];
int s1, s2, i, k, j, flag = 1;
gets(arr1);
gets(arr2);
s1 = strlen(arr1);
s2 = strlen(arr2);
if (s1 != s2) {
printf("NO");
return 0;
}
i = 0;
j = strlen(arr1) - 1;
for (k = 0; k < s1; k++) {
if (arr1[i] != arr2[j])... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 999999;
const long long INF = 1e16;
vector<long long> split(long long k) {
long long cur = 1;
vector<long long> ans;
while (k > 0) {
long long nxt = min(cur, k);
ans.push_back(nxt);
k -= nxt;
cur *= 2;
}
return ans;
}
signed ... | 22 |
#include <bits/stdc++.h>
using namespace std;
int p10[1000100], n, d[256];
string s, digits = "1689";
int main() {
ios::sync_with_stdio(0);
p10[0] = 1;
for (int i = 1; i <= 1000000; i++) p10[i] = p10[i - 1] * 10 % 7;
d['1'] = d['6'] = d['8'] = d['9'] = 1;
cin >> s;
n = s.size();
for (int i = 0; i < 4; i++... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200010;
const long long MOD = (int)1e9 + 7;
const int INF = 1e9;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-8;
long long tab[101][101][101];
string s;
vector<int> val;
long long dp(int l, int r, int qt) {
if (l > r) return 0;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
cin >> n >> k >> s;
int a[26] = {0};
for (int i = 0; i < n; i++) {
a[s[i] - 'a']++;
}
int flag = 0;
for (int i = 0; i < 26; i++) {
if (a[i] > k) {
flag = 1;
break;
}
}
if (flag == 1)
cout << "N... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-18;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
return a = min(a, b);... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long lca(unordered_map<long long, long long> &weights, long long v,
long long u, long long w) {
long long result = 0;
while (v != u) {
if (v > u) {
result += weights[v];
weights[v] += w;
v /= 2;
} else {
result += weigh... | 7 |
#include <bits/stdc++.h>
using namespace std;
signed func(long long int a, long long int b, long long int x,
long long int y) {
if (x - y - b <= 0 && x - y + b >= 0 && x + y - 2 * a + b <= 0 &&
x + y - b >= 0)
return 1;
return 0;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> tree[200005];
vector<long long> v;
int dp[200005], a[200005];
int h[200005];
int c = 1;
void dfs(int node, int p) {
h[c++] = node;
for (auto i : tree[node]) {
if (i.first != p) {
v.push_back(v.back() + i.second);
long long x = v.ba... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
const int MAX_N = 100010;
int n;
int par[MAX_N];
vector<int> ch[MAX_N];
int maxdepth[MAX_N];
vector<int> res... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int k = 0; k < t; k++) {
int n;
cin >> n;
if (n % 2 == 0) {
for (int i = 0; i < n / 2; i++) cout << 1;
cout << endl;
} else {
cout << 7;
for (int i = 0; i < n / 2 - 1; i++) cout << 1;
cou... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long modInverse(long long a, long long m);
long long gcd(long long a, long long b);
long long power(long long x, unsigned long long y, unsigned long long m);
void pairsort(int a[], int b[], int n);
long long logint(long long x, long long y);
long long gcd(long long a, ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long ar[3000];
int main() {
long long x, n, i, j, k, s = 0, v = 0;
cin >> x;
for (i = 0; i < x; i++) {
cin >> k;
s += k;
}
cin >> n;
for (i = 0; i < 2 * n; i++) cin >> ar[i];
if (ar[2 * n - 1] < s || n == 0) {
cout << "-1" << endl;
} else {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
void build_z_function(string& s, vector<int>& z) {
int n = s.size();
z = vector<int>(n);
z[0] = n;
int L = 0, R = 0;
for (int i = 1; i < n; i++) {
if (i > R) {
L = R = i;
while (R < n && s[R - L] == s[R]) {
R++;
}
z[i] = R - L;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
bool sol(int i, int s, int n) {
if (i == n) {
if (s % 360 == 0)
return 1;
else
return 0;
}
return sol(i + 1, s + v[i], n) || sol(i + 1, s - v[i], n);
}
int main() {
int n, k;
char c = 'a', f = 'c';
cin >> n >> k;
string s;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, maxLength = 0, counter = 0;
cin >> n;
int freq[1001] = {};
for (int i = 0; i < n; i++) {
int number;
cin >> number;
freq[number]++;
}
for (int i = 0; i < 1001; i++) {
if (freq[i]) counter++;
if (freq[i] > maxLength) maxLen... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using llu = unsigned long long;
vector<ll> v[200005];
ll vis[200005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t, n, m, i, j, k;
cin >> n;
ll a[n + 1];
for (i = 1; i <= n; i++) cin >> a[i];
ll ans... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int pos[100500];
int d[100500];
int res[100500];
int main() {
int n, cur;
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%d", &cur);
pos[cur] = i;
}
vector<int> por(n);
set<pair<int, int> > decrease;
set<pair<int, int> > inc... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void cmin(T &a, T b) {
((a > b) && (a = b));
}
template <class T>
inline void cmax(T &a, T b) {
((a < b) && (a = b));
}
char IO;
template <class T = int>
T rd() {
T s = 0;
int f = 0;
while (!isdigit(IO = getchar())) f |= IO == '-';
do s... | 27 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, k, c[N], f[N], h[N];
int dp[505][5505];
int main() {
cin >> n >> k;
int num;
for (int i = 1; i <= n * k; ++i) {
cin >> num;
++c[num];
}
for (int i = 1; i <= n; ++i) {
cin >> num;
++f[num];
}
for (int i = 1; i <= k; ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
int a[n][6];
map<int, int> m1, m2, m3;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 6; ++j) {
cin >> a[i][j];
if (i == 0) ++m1[a[i][j]];
if (i == 2) ++m3[a[i][j]];
if (i == 1) ++m2[a[i][j]];
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007ll;
void ad(long long &a, long long b) { a = (a + b) % mod; }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int n;
scanf("%d", &n);
vector<long long> a(n);
for (int i = 0; i < n; i++) {
... | 19 |
#include <bits/stdc++.h>
using namespace std;
bool st[2000], ed[2000];
char a[2001], b[2001], c[2001];
int md = 1e9 + 13;
double ch = 27.321;
set<double> s[2000];
double dd(double x) { return x - floor(x / md) * md; }
void nxt(double &x) {
double z = dd(x * ch);
z = floor(z * 1000) / 1000;
x = z;
}
int main() {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
if (n <= 2) {
cout << "1\n";
continue;
}
n -= 2;
int ans = 1;
ans += (n + x - 1) / x;
cout << ans << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int ans, n, cur, d[100100], a[100100];
int main() {
cin >> n;
if (n == 1) {
cout << 1;
return 0;
}
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
cur = 0;
for (int j = 2; j * j <= a[i]; j++)
if (a[i] % j == 0) {
... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long int const mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t, a, b, x, d, d1, d2;
cin >> t;
while (t--) {
cin >> a >> b;
d = abs(a - b);
d1 = max(a, b);
d2 = min(a, b... | 5 |
#include <bits/stdc++.h>
using namespace std;
string B = "BRG";
string R = "RGB";
string G = "GBR";
string s;
int l, r, k, n, res, t;
int inB, inR, inG;
void solve() {
res = 1000000;
cin >> n >> k;
cin >> s;
l = r = inB = inR = inG = 0;
while (r < n) {
if (r - l == k) {
res = min(res, min(inB, min(i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int arr[100001], N, ans;
void DFS(int a, int b, int x, int y, int r) {
if (a <= x && b <= y) {
ans = (ans < N - r ? ans : N - r);
return;
}
if (r == 0 || ans == N - r) return;
if (arr[r] == 2) {
while (a > x) {
x *= 2;
r--;
}
while (b... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a;
long long max_last = -1, sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
sum += a;
max_last = max(a, max_last);
}
long long ans = sum / (n - 1);
if (sum % (n - 1) != 0) ans++;
if (max_last > ans) ans += (ma... | 8 |
#include <bits/stdc++.h>
const int sz = 10000;
using namespace std;
int clue();
int result();
void show();
bool check();
int main() {
int n, m;
cin >> n >> m;
vector<pair<string, string> > v;
vector<pair<string, string> >::iterator it;
while (m--) {
string a, b;
cin >> a >> b;
if (a.size() <= b.si... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, x[100005], y[100005];
long long ccw(int o, int a, int b) {
return 1LL * (x[a] - x[o]) * (y[b] - y[o]) -
1LL * (x[b] - x[o]) * (y[a] - y[o]);
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d %d", &x[i], &y[i]);
long long area = 0;... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<int> z_function(string s) {
int n = (int)s.size();
vector<int> z(n);
for (int i = 1, l = 0, r = 0; i < n; ++i) {
if (i <= r) z[i] = min(r - i + 1, z[i - l]);
while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
if (i + z[i] - 1 > r) l = i, r = i +... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y);
long long mpower(long long x, long long y, long long p);
long long modInv(long long a, long long m);
long long gcdExtended(long long a, long long b, long long *x, long long *y);
bool isPrime(long long n);
int main() {
ios_base::s... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
string s;
cin >> s;
if (s[0] != 'W' && s[0] != 'B' && s[0] != 'G') {
cout << "#Color" << endl;
return 0;
}
}
}
cout <<... | 0 |
#include <bits/stdc++.h>
using namespace std;
int total[2000005], mid[2000005];
int main() {
int n, m, maxi, x, y, ok, mid, c, d;
scanf("%d", &n);
maxi = ok = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &m);
total[m]++;
maxi = max(maxi, m);
}
if (total[0] == 1) {
if (maxi == 0) {
ok =... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T abs(T x) {
return x < 0 ? -x : x... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string bin;
cin >> bin;
int ans = 0;
for (int i = bin.size() - 1; i >= 0; i--) {
if (bin[i] == '0')
ans++;
else if (bin[i] == '1') {
if (i == 0) break;
ans += 2;
bin[i - 1]++;
} else {
ans++;
if (i != 0) b... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4005;
const int inf = 0x7f7f7f7f;
int n, m;
int u[maxn], v[maxn];
int cnt[maxn];
bool adj[maxn][maxn];
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> u[i] >> v[i];
cnt[u[i]]++;
cnt[v[i]]++;
adj[u[i]][v[i]] = 1;
adj[... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
map<string, int> q;
int n, m, cnt = 0;
cin >> n >> m;
int ans1 = n, ans2 = m;
while (n--) {
cin >> s;
q[s]++;
}
while (m--) {
cin >> s;
q[s]++;
if (q[s] > 1) cnt++;
}
if (cnt % 2 == 1) ans2 -= 1;
if (ans1 <= a... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double Pi = acos(-1.0);
int A[2 * 1000002];
template <class type>
class BIT {
type *tree;
int maxVal;
public:
BIT(type *T, int n) {
tree = T;
maxVal = n;
memset(tree, 0, sizeof(type) * maxVal);
}
void update(int id, type val) {
while (id < ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int A[150010], B[150010], Da[150010], Db[150010], N, i;
int main() {
cin >> N;
for (i = 1; i <= N; ++i) scanf("%d", &A[i]);
for (i = 1; i <= N; ++i) scanf("%d", &B[i]);
if (A[1] != B[1] || A[N] != B[N]) return puts("No"), 0;
for (i = 2; i <= N; ++i) Da[i] = A[i] -... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1050;
int n, cnt;
int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + (ch & 15);
ch = getchar();
}
return x * f;
}
str... | 24 |
#include <bits/stdc++.h>
template <typename T, typename U>
inline void swap(T &a, U &b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
inline void swap(int &a, int &b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
inline void swap(long long &a, long long &b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
template <typename T, typ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
string str;
cin >> str;
if (n == 1) {
cout << "Yes";
return 0;
}
int cnt[26];
memset(cnt, 0, sizeof cnt);
for (int i = 0; i < str.length(); i++) {
int p = str[i] - 'a';
cnt[p]++;
}
for (int i = 0; i ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int z[10000001];
int kp[10000001];
char s[10000001];
void z_func() {
int L = 0, R = 0;
for (int i = 1; i < n; ++i) {
if (i > R) {
L = R = i;
while (R < n && s[R - L] == s[R]) R++;
z[i] = R - L;
R--;
} else {
int k = i - L;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int main() {
int n, t;
int i, j, k, now, flag;
while (cin >> n >> t) {
now = 1;
for (i = 1; i <= n - 1; i++) cin >> a[i];
flag = 0;
while (now <= t) {
now = now + a[now];
if (now == t) {
flag = 1;
break;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, k, len;
long long arr[N];
long long solve() {
multiset<long long> in, out;
long long mx = -1e16, sum = 0, fadl = k;
for (int i = 1; i <= n; i++) {
sum += arr[i];
if (i - len > 0) {
if (arr[i - len] >= 0)
sum -= arr[i ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 50 + 10, M = 2e4 + 10;
int a[N][M], tree[4 * M], lazy[4 * M], dp[N][M];
void update(int i, int l, int r, int ql, int qr, int x);
void propagate(int i, int lc, int rc);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, k;
cin >> n ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int v[N];
int main() {
int n, k;
int a, b, c, d;
scanf("%d%d", &n, &k);
scanf("%d%d%d%d", &a, &b, &c, &d);
if (k < n + 1) return 0 * puts("-1");
v[1] = a;
v[2] = c;
v[n - 1] = d;
v[n] = b;
int t = 2;
for (int i = (1); i < (n + 1); +... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int main() {
int a, b, r;
scanf("%d %d %d", &a, &b, &r);
if (2 * r <= min(a, b))
puts("First");
else
puts("Second");
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char s1[505][505];
long long dp[2][505][505];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%s", s1[i] + 1);
if (s1[1][1] != s1[n][m]) {
puts("0");
return 0;
}
long long ans = 0;
int cur = 0;
dp[0][1][n] = 1;
for (... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long w, h;
while (cin >> w >> h) {
long long res = 0;
for (long long i = 2; i <= w; i += 2) {
for (long long j = 2; j <= h; j += 2) {
res += (w - i + 1) * (h - j + 1);
}
}
cout << res << endl;
}
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, t1, t2, t3, c1 = 0, ans, par[100001], g;
vector<pair<int, int>> e[100001];
priority_queue<pair<pair<int, int>, pair<int, int>>,
vector<pair<pair<int, int>, pair<int, int>>>,
greater<pair<pair<int, int>, pair<int, int>>>>
bfs;
pair... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000, M = 6;
long long F[N + 1], G[N + 1], C[M];
struct st {
int i;
long long v;
} Q[N + 1];
int main() {
int k;
scanf("%d", &k);
for (int i = 0; i < M; i++) scanf("%lld", &C[i]);
memset(F + 1, 0xc0, sizeof(long long[N]));
for (int b = 0, t = ... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long a[5205][5205];
bool check(long long i, long long j, long long k) {
k--;
long long act =
a[i + k][j + k] - a[i - 1][j + k] - a[i + k][j - 1] + a[i - 1][j - 1];
k++;
if (act == k * k || act == 0) return 1;
return 0;
}
bool verif(long long n, long lon... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 200005;
inline void read(int &x) {
int f = 1;
x = 0;
char s = getchar();
while (s < '0' || s > '9') {
if (s == '-') f = -1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = x * 10 + s - '0';
s = get... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y, di, cnt;
node(int _x = 0, int _y = 0, int _di = 0, int _cnt = 0) {
x = _x;
y = _y;
di = _di;
cnt = _cnt;
}
};
int n, m;
int cx[5] = {0, 0, 1, -1};
int cy[5] = {1, -1, 0, 0};
char s[1005][1005];
bool mem[1005][1005][5][5];
queue<... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string a, b;
cin >> a >> b;
int x = 0, y = 0;
for (int i = 0; i < a.length(); i++) x += a[i] - '0';
for (int i = 0; i < b.length(); i++) y += b[i] - '0';
if (x & 1) x++;
if (x >= y)
puts("YES");
else
... | 9 |
#include <bits/stdc++.h>
using namespace std;
string a, b = "AHIMOTUVWXY";
map<char, long long> mp;
long long i, j;
int main() {
cin >> a;
for (j = 0; j < b.size(); j++) {
mp[b[j]]++;
}
for (i = 0; i < a.size(); i++) {
if (mp[a[i]] == 0) {
cout << "NO";
return 0;
}
}
for (i = 0; i < ... | 2 |
#include <bits/stdc++.h>
int main() {
int i, min, a[5], b[5] = {1, 1, 2, 7, 4};
for (i = 0; i < 5; i++) scanf("%d", &a[i]);
min = a[0] / b[0];
for (i = 1; i < 5; i++)
if (min > a[i] / b[i]) min = a[i] / b[i];
printf("%d\n", min);
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int row, column, r_row, r_column, f_row, f_column;
int dr = 1, dc = 1;
cin >> row >> column >> r_row >> r_column >> f_row >> f_column;
int count;
count = 0;
while (f_row != r_row && f_column != r_colu... | 0 |
#include <bits/stdc++.h>
int main() {
int n;
std::cin >> n;
if (n > 11) {
std::cout << 0;
return 0;
}
int a[15][10];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 5; ++j) {
std::cin >> a[i][j];
}
}
std::vector<int> vec;
for (int i = 0; i < n; ++i) {
bool flag = true;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6000 * 2 + 5;
bool isPrime(int val) {
if (val == 1) return false;
int sq = sqrt((double)val);
for (int i = 2; i <= sq; i++)
if (val % i == 0) return false;
return true;
}
int main() {
int n;
cin >> n;
int maxSum = 0;
for (int i = 1; i <=... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double p = 1.000000011;
double fexp(double base, int power) {
double res = 1;
while (power) {
if (power & 1) res *= base;
base *= base;
power >>= 1;
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, t;
cin >> n >... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200001;
const int maxk = 51;
double DP[maxn][maxk];
double val[maxn], B[maxn], sum[maxn], recip[maxn];
int N, K;
double costo(int i, int j) {
return B[j] - B[i - 1] - sum[i - 1] * (recip[j] - recip[i - 1]);
}
void doDP(int ini, int fin, int iniq, int finq... | 16 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int a[10] = {0};
int main() {
bool ok = false;
int v, dig, cur, p, len, ost, mn = 1000000000;
scanf("%d", &v);
for (int(i) = (1); (i) <= (9); ++(i)) {
scanf("%d", &a[i]);
if (a[i] <= mn) {
dig = i;
mn = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i;
cin >> n;
if (n == 2 || n == 3) {
cout << "1" << endl;
cout << n;
} else {
if (n % 2 == 0) {
cout << n / 2 << endl;
for (i = 0; i < n / 2; i++) cout << "2 ";
} else {
n = n - 3;
cout << n / 2 + 1 << e... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 77;
int k, n, m, a[N], type[N];
pair<int, int> t[N];
vector<pair<int, int> > sum[N], mul[N];
vector<pair<long long, pair<long long, int> > > V;
vector<int> A;
bool CMP(pair<long long, pair<long long, int> > A,
pair<long long, pair<long long, ... | 20 |
#include <bits/stdc++.h>
using namespace std;
struct student {
int id;
int p;
int s;
} st[105], bs[105];
inline student best(const student& a, const student& b) {
return a.p > b.p ? a : b;
}
int n, m, k;
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++) cin >> st[i].p;
for (int i = 0; i < n; i+... | 3 |
#include <bits/stdc++.h>
using namespace std;
int ini() {
int t;
scanf("%d", &t);
return t;
}
vector<vector<pair<long long, long long> > > asd;
int pr[100000 + 5];
vector<int> p;
void path(int u) {
if (u == 0) return;
path(pr[u]);
p.push_back(u);
}
int main() {
int v = ini(), e = ini();
asd.assign(v + 1... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if (n & 1)
cout << (n - 1) / 2;
else
cout << n / 2;
cout << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, p;
int x;
long long row[1003], col[1003];
long long ansr[1000006], ansc[1000006];
priority_queue<long long> a;
priority_queue<long long> b;
long long tmp;
long long ans = -201303169;
int max(int c, int d) {
if (c > d)
return c;
else
return d;
}
int ... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;
constexpr int INF = 2000000000;
constexpr ll LLINF = 9000000000000000000;
struct ... | 17 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
using namespace std;
const long long nmax = 1005;
long long n, k, m, ans[2 * nmax], x;
vector<long long> indx;
pair<pair<long long, long long>, pair<long long, long long>> arr[nmax];
string s;
char result;
struct ecuation_system {
vecto... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int llINF = 0x3f3f3f3f3f3f3f;
const int MAXN = 100100;
const long long int mod = 1e9 + 7;
const int LMAXN = 20;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, sum, gr[512];
bool um[512];
memset(um, ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int mo = 1e9 + 7;
const int N = 1e4 + 10;
int n, pos, posx, dp[N][27][2];
char s[3][N];
bool emp[N];
void upd(int &x, const int &y) { (x += y) >= mo ? x -= mo : 0; }
int bit(int S, int x) {
if (x == 0) return S % 3;
if (x == 1) return S / 3 % 3;
return S / 9;
}
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
vector<long long> v;
long long a_2, a_5, b_0, b_5, c_7, c_5, d_0, d_01, i, k, len;
cin >> s;
reverse(s.begin(), s.end());
len = s.length();
long long maxx = 1e7;
long long min_25 = maxx, min_50 = maxx, min_75 = maxx, min_00 = maxx;
a... | 13 |
#include <bits/stdc++.h>
using namespace std;
int a[1005][1005];
int main() {
int m;
cin >> m;
int tmp = 0;
int i = 100;
while (i * (i - 1) * (i - 2) / 6 > m) i--;
m -= i * (i - 1) * (i - 2) / 6;
for (int j = 0; j < i; j++)
for (int k = 0; k < i; k++)
if (j != k) a[j][k] = 1;
tmp += i;
while... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[1000000 + 10];
int x, y;
int main() {
scanf("%d %d %d", &n, &x, &y);
for (int i = 1; i <= n; i++) scanf("%d", arr + i);
for (int i = 1; i <= n; i++) {
bool isok = true;
for (int j = 1; j <= x; j++) {
if (i - j < 1 || arr[i - j] > arr[i])
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
long long int cost[310][310], pd[310][310];
int main(void) {
int i, j, l, r;
long long int c;
while (scanf("%d %d %d", &n, &m, &k) != EOF) {
for (i = 0; i < 310; i++)
for (j = 0; j < 310; j++) cost[i][j] = pd[i][j] = 99999999999999LL;
for (i... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
int a[MAXN];
char s[MAXN];
int n, k;
int main() {
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
scanf("%s", s);
int lst = 0;
for ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int mod = 1e9 + 7;
int T, n, ans;
int pre[maxn][maxn * 2], suf[maxn][maxn * 2];
char s[maxn], t[maxn];
void add(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d %s %s", &n, s + ... | 20 |
#include <bits/stdc++.h>
using namespace std;
int d[27];
string mas;
string New[10000];
int Num(char d) { return ((int)d - (int)'a' + 1); }
int main() {
int j, l, i, n;
string s;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> mas;
for (j = 1; j <= 26; j++) d[j] = 0;
l = mas.size();
for (j = 0; j < ... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.