#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
#define vt vector
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
#define debug(x) do{auto _x = x; cerr << #x << " = " << _x << endl;} while(0)
const ll INF = 1e18;
struct SegTree {
int n;
vt<int> seg;
void init(int _n) {
for (n = 1; n < _n; n *= 2);
seg.resize(2 * n);
}
void upd(int i, int v) {
i += n;
seg[i] = v;
while (i > 1) {
i /= 2;
seg[i] = seg[2 * i] + seg[2 * i + 1];
}
}
int query(int l, int r) {
int res = 0;
for (l += n, r += n + 1; l < r; l /= 2, r /= 2) {
if (l & 1) res += seg[l++];
if (r & 1) res += seg[--r];
}
return res;
}
};
/*
centroid decomposition on the tree
count the # of paths that go through some root such that there is a 0 and 1 in one subtree
and a 2 in another
consider the total # of tours that go through some root node
consider tuples of ordered values in a tour of {subtree 1, root, subtree 2}
cases are:
1. {{0, 1}, {}, {2}}
2. {{0}, {}, {1, 2}}
3. {{0}, {1}, {2}}
4. {{0, 1}, {2}, {}}
5. {{}, {0}, {1, 2}}
when performing an update, we need to be able to subtract off the old paths that contained
the existing restaurant and add the new paths that use it
we need to be able to:
1. query # of 1's between two vertices
we need to remap node labels for each centroid decomp
*/
using pi = pair<int, int>;
struct Centroid {
int root;
vt<int> tout; // dfs time out
SegTree tree0, tree2; // euler tour for counting # of 0's and 2's in a node's subtree
vt<ll> cnt10, cnt12; // # of pairs of 10 and 12 in each subtree
vt<int> cnt0, cnt2;
ll tot10, tot12, tot0, tot2;
vt<int> subtree;
vt<pi> subtree_times;
ll ans;
};
int n, q;
vt<vt<int>> adj;
vt<Centroid> centroids;
vt<vt<pi>> parents; // centroid root, time
vt<int> colour;
ll gans;
vt<int> sz;
vt<bool> done;
int dfs_sz(int u, int par = -1) {
sz[u] = 1;
for (int v : adj[u]) {
if (v == par || done[v]) continue;
sz[u] += dfs_sz(v, u);
}
return sz[u];
}
int find_centroid(int u, int tsz, int par = -1) {
for (int v : adj[u]) {
if (v == par || done[v]) continue;
if (sz[v] * 2 > tsz) return find_centroid(v, tsz, u);
}
return u;
}
void dfs_time(int u, int& t, Centroid& obj, ll ones, int par = -1, int subtree = -1) {
int tin = ++t;
parents[u].pb({obj.root, t});
obj.subtree[tin] = subtree;
if (colour[u] == 0) obj.tree0.upd(tin, 1);
if (colour[u] == 2) obj.tree2.upd(tin, 1);
if (subtree != -1) {
// update 10's and 12's
if (colour[u] == 0) {
obj.cnt0[subtree]++;
obj.cnt10[subtree] += ones;
} else if (colour[u] == 1) {
ones++;
} else {
obj.cnt2[subtree]++;
obj.cnt12[subtree] += ones;
}
}
F0R (i, adj[u].size()) {
int v = adj[u][i];
if (v == par || done[v]) continue;
if (subtree == -1) {
obj.subtree_times[i].f = t;
}
dfs_time(v, t, obj, ones, u, subtree == -1 ? i : subtree);
if (subtree == -1) {
obj.subtree_times[i].f = t;
}
}
obj.tout[tin] = t;
}
void decomp(int u = 0) {
int tsz = dfs_sz(u);
int r = find_centroid(u, tsz);
Centroid& obj = centroids[r];
obj.root = r;
obj.tout = obj.subtree = vt<int>(tsz);
obj.cnt0 = obj.cnt2 = vt<int>(adj[r].size());
obj.cnt10 = obj.cnt12 = vt<ll>(adj[r].size());
obj.subtree_times.resize(adj[r].size());
obj.tree0.init(tsz);
obj.tree2.init(tsz);
int t = -1;
dfs_time(r, t, obj, 0);
obj.tot0 = accumulate(all(obj.cnt0), 0ll);
obj.tot2 = accumulate(all(obj.cnt2), 0ll);
obj.tot10 = accumulate(all(obj.cnt10), 0ll);
obj.tot12 = accumulate(all(obj.cnt12), 0ll);
// calculate answer
F0R (i, adj[r].size()) {
int v = adj[r][i];
if (done[v]) continue;
obj.ans += 1ll * obj.cnt10[i] * (obj.tot2 - obj.cnt2[i]);
obj.ans += 1ll * obj.cnt0[i] * (obj.tot12 - obj.cnt12[i]);
if (colour[r] == 1) obj.ans += 1ll * obj.cnt0[i] * (obj.tot2 - obj.cnt2[i]);
}
if (colour[r] == 0) obj.ans += obj.tot12;
if (colour[r] == 2) obj.ans += obj.tot10;
gans += obj.ans;
done[r] = true;
for (int v : adj[r]) {
if (!done[v]) decomp(v);
}
}
struct HLD {
int t;
vt<int> sz, pos, par, root, depth;
vt<vt<int>> adj;
SegTree seg;
void init(vt<vt<int>>& _adj) {
t = 0;
sz = pos = par = root = depth = vt<int>(n);
adj = _adj;
seg.init(n);
}
int dfs_sz(int u) {
sz[u] = 1;
for (int& v : adj[u]) {
par[v] = u;
depth[v] = depth[u] + 1;
adj[v].erase(find(all(adj[v]), u));
sz[u] += dfs_sz(v);
if (sz[v] > sz[adj[u][0]]) swap(v, adj[u][0]);
}
return sz[u];
}
void dfs_hld(int u) {
pos[u] = t++;
for (int& v : adj[u]) {
root[v] = (v == adj[u][0] ? root[u] : v);
dfs_hld(v);
}
}
void gen() {
dfs_sz(0);
dfs_hld(0);
}
int query(int u, int v) {
int res = 0;
while (root[u] != root[v]) {
if (depth[root[u]] > depth[root[v]]) swap(u, v);
res += seg.query(pos[root[v]], pos[v]);
v = par[root[v]];
}
if (depth[u] > depth[v]) swap(u, v);
return res + seg.query(pos[u], pos[v]);
}
void upd(int u, int v) {
seg.upd(pos[u], v);
}
};
HLD hld;
void upd(Centroid& obj, int u, int tin, int prev_c, int new_c) {
int i = obj.subtree[tin];
int tout = obj.tout[tin];
ll prev_ans = obj.ans;
// handle removal
// not root
if (u != obj.root) {
int subroot = adj[obj.root][i];
// subtract answer
if (prev_c == 0) {
ll par1s = hld.query(u, subroot) - (colour[u] == 1);
obj.ans -= par1s * (obj.tot2 - obj.cnt2[i]);
obj.ans -= obj.tot12 - obj.cnt12[i];
if (colour[obj.root] == 1) obj.ans -= obj.tot2 - obj.cnt2[i];
if (colour[obj.root] == 2) obj.ans -= par1s;
// update counts
obj.cnt0[i]--;
obj.tot0--;
obj.tree0.upd(tin, 0);
obj.tot10 -= par1s;
obj.cnt10[i] -= par1s;
} else if (prev_c == 1) {
int t0 = obj.tree0.query(tin, tout);
int t2 = obj.tree2.query(tin, tout);
obj.ans -= t0 * (obj.tot2 - obj.cnt2[i]);
obj.ans -= t2 * (obj.tot0 - obj.cnt0[i]);
if (colour[obj.root] == 2) obj.ans -= t0;
if (colour[obj.root] == 0) obj.ans -= t2;
// upd
obj.cnt10[i] -= t0;
obj.tot10 -= t0;
obj.cnt12[i] -= t2;
obj.tot12 -= t2;
} else {
ll par1s = hld.query(u, subroot) - (colour[u] == 1);
obj.ans -= par1s * (obj.tot0 - obj.cnt0[i]);
obj.ans -= obj.tot10 - obj.cnt10[i];
if (colour[obj.root] == 1) obj.ans -= obj.tot0 - obj.cnt0[i];
if (colour[obj.root] == 0) obj.ans -= par1s;
// upd
obj.cnt2[i]--;
obj.tot2--;
obj.tree2.upd(tin, 0);
obj.tot12 -= par1s;
obj.cnt12[i] -= par1s;
}
} else {
if (prev_c == 0) {
obj.ans -= obj.tot12;
} else if (prev_c == 1) {
ll sub = 0;
F0R (j, adj[obj.root].size()) {
sub += obj.cnt0[j] * (obj.tot2 - obj.cnt2[j]);
}
obj.ans -= 1ll * sub;
} else {
obj.ans -= obj.tot10;
}
}
// now handle addition
if (u != obj.root) {
int subroot = adj[obj.root][i];
// add answer
if (new_c == 0) {
ll par1s = hld.query(u, subroot) - (colour[u] == 1);
obj.ans += par1s * (obj.tot2 - obj.cnt2[i]);
obj.ans += obj.tot12 - obj.cnt12[i];
if (colour[obj.root] == 1) obj.ans += obj.tot2 - obj.cnt2[i];
if (colour[obj.root] == 2) obj.ans += par1s;
// update counts
obj.cnt0[i]++;
obj.tot0++;
obj.tree0.upd(tin, 1);
obj.tot10 += par1s;
obj.cnt10[i] += par1s;
} else if (new_c == 1) {
int t0 = obj.tree0.query(tin, tout);
int t2 = obj.tree2.query(tin, tout);
obj.ans += t0 * (obj.tot2 - obj.cnt2[i]);
obj.ans += t2 * (obj.tot0 - obj.cnt0[i]);
if (colour[obj.root] == 2) obj.ans += t0;
if (colour[obj.root] == 0) obj.ans += t2;
// upd
obj.cnt10[i] += t0;
obj.tot10 += t0;
obj.cnt12[i] += t2;
obj.tot12 += t2;
} else {
ll par1s = hld.query(u, subroot) - (colour[u] == 1);
obj.ans += par1s * (obj.tot0 - obj.cnt0[i]);
obj.ans += obj.tot10 - obj.cnt10[i];
if (colour[obj.root] == 1) obj.ans += obj.tot0 - obj.cnt0[i];
if (colour[obj.root] == 0) obj.ans += par1s;
// upd
obj.cnt2[i]++;
obj.tot2++;
obj.tree2.upd(tin, 1);
obj.tot12 += par1s;
obj.cnt12[i] += par1s;
}
} else {
if (new_c == 0) {
obj.ans += obj.tot12;
} else if (new_c == 1) {
ll sub = 0;
F0R (j, adj[obj.root].size()) {
sub += obj.cnt0[j] * (obj.tot2 - obj.cnt2[j]);
}
obj.ans += 1ll * sub;
} else {
obj.ans += obj.tot10;
}
}
gans -= prev_ans;
gans += obj.ans;
}
void change(int u, int c) {
if (c == colour[u]) return;
for (auto [cent, tin] : parents[u]) {
upd(centroids[cent], u, tin, colour[u], c);
}
if (colour[u] == 1) hld.upd(u, 0);
colour[u] = c;
if (c == 1) hld.upd(u, 1);
}
void init(int N, vt<int> F, vt<int> U, vt<int> V, int Q) {
n = N;
q = Q;
colour = F;
parents.resize(n);
centroids.resize(n);
adj.resize(n);
F0R (i, n - 1) {
adj[U[i]].pb(V[i]);
adj[V[i]].pb(U[i]);
}
hld.init(adj);
hld.gen();
F0R (i, n) {
if (colour[i] == 1) hld.upd(i, 1);
}
sz.resize(n);
done.resize(n);
gans = 0;
decomp();
}
ll num_tours() {
return gans;
}
Compilation message
joitour.cpp: In function 'void dfs_time(int, int&, Centroid&, ll, int, int)':
joitour.cpp:15:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | #define FOR(i, a, b) for (int i = (a); i < (b); i++)
| ^
joitour.cpp:17:19: note: in expansion of macro 'FOR'
17 | #define F0R(i, b) FOR (i, 0, b)
| ^~~
joitour.cpp:135:5: note: in expansion of macro 'F0R'
135 | F0R (i, adj[u].size()) {
| ^~~
joitour.cpp: In function 'void decomp(int)':
joitour.cpp:15:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | #define FOR(i, a, b) for (int i = (a); i < (b); i++)
| ^
joitour.cpp:17:19: note: in expansion of macro 'FOR'
17 | #define F0R(i, b) FOR (i, 0, b)
| ^~~
joitour.cpp:174:5: note: in expansion of macro 'F0R'
174 | F0R (i, adj[r].size()) {
| ^~~
joitour.cpp: In function 'void upd(Centroid&, int, int, int, int)':
joitour.cpp:15:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | #define FOR(i, a, b) for (int i = (a); i < (b); i++)
| ^
joitour.cpp:17:19: note: in expansion of macro 'FOR'
17 | #define F0R(i, b) FOR (i, 0, b)
| ^~~
joitour.cpp:309:13: note: in expansion of macro 'F0R'
309 | F0R (j, adj[obj.root].size()) {
| ^~~
joitour.cpp:15:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | #define FOR(i, a, b) for (int i = (a); i < (b); i++)
| ^
joitour.cpp:17:19: note: in expansion of macro 'FOR'
17 | #define F0R(i, b) FOR (i, 0, b)
| ^~~
joitour.cpp:374:13: note: in expansion of macro 'F0R'
374 | F0R (j, adj[obj.root].size()) {
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
600 KB |
Output is correct |
25 |
Correct |
17 ms |
5208 KB |
Output is correct |
26 |
Correct |
14 ms |
4696 KB |
Output is correct |
27 |
Correct |
10 ms |
3672 KB |
Output is correct |
28 |
Correct |
17 ms |
5208 KB |
Output is correct |
29 |
Correct |
14 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
987 ms |
301820 KB |
Output is correct |
3 |
Correct |
991 ms |
301396 KB |
Output is correct |
4 |
Correct |
930 ms |
299900 KB |
Output is correct |
5 |
Correct |
948 ms |
302416 KB |
Output is correct |
6 |
Correct |
434 ms |
265296 KB |
Output is correct |
7 |
Correct |
411 ms |
265376 KB |
Output is correct |
8 |
Correct |
755 ms |
273616 KB |
Output is correct |
9 |
Correct |
751 ms |
265424 KB |
Output is correct |
10 |
Correct |
708 ms |
256976 KB |
Output is correct |
11 |
Correct |
712 ms |
253400 KB |
Output is correct |
12 |
Correct |
851 ms |
276816 KB |
Output is correct |
13 |
Correct |
873 ms |
276700 KB |
Output is correct |
14 |
Correct |
854 ms |
276560 KB |
Output is correct |
15 |
Correct |
836 ms |
275792 KB |
Output is correct |
16 |
Correct |
896 ms |
293948 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
731 ms |
244632 KB |
Output is correct |
22 |
Correct |
689 ms |
245220 KB |
Output is correct |
23 |
Correct |
722 ms |
244688 KB |
Output is correct |
24 |
Correct |
740 ms |
246568 KB |
Output is correct |
25 |
Correct |
314 ms |
170164 KB |
Output is correct |
26 |
Correct |
323 ms |
170180 KB |
Output is correct |
27 |
Correct |
325 ms |
170056 KB |
Output is correct |
28 |
Correct |
312 ms |
170180 KB |
Output is correct |
29 |
Correct |
465 ms |
297296 KB |
Output is correct |
30 |
Correct |
475 ms |
297584 KB |
Output is correct |
31 |
Correct |
474 ms |
297296 KB |
Output is correct |
32 |
Correct |
474 ms |
297436 KB |
Output is correct |
33 |
Correct |
412 ms |
260024 KB |
Output is correct |
34 |
Correct |
384 ms |
260260 KB |
Output is correct |
35 |
Correct |
408 ms |
260264 KB |
Output is correct |
36 |
Correct |
395 ms |
260212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
856 KB |
Output is correct |
8 |
Correct |
14 ms |
5008 KB |
Output is correct |
9 |
Correct |
460 ms |
297632 KB |
Output is correct |
10 |
Correct |
449 ms |
297364 KB |
Output is correct |
11 |
Correct |
471 ms |
297424 KB |
Output is correct |
12 |
Correct |
443 ms |
297552 KB |
Output is correct |
13 |
Correct |
443 ms |
141984 KB |
Output is correct |
14 |
Correct |
419 ms |
141996 KB |
Output is correct |
15 |
Correct |
580 ms |
142156 KB |
Output is correct |
16 |
Correct |
566 ms |
142152 KB |
Output is correct |
17 |
Correct |
578 ms |
142160 KB |
Output is correct |
18 |
Correct |
570 ms |
142160 KB |
Output is correct |
19 |
Correct |
892 ms |
297428 KB |
Output is correct |
20 |
Correct |
869 ms |
297500 KB |
Output is correct |
21 |
Correct |
1233 ms |
297428 KB |
Output is correct |
22 |
Correct |
1214 ms |
297296 KB |
Output is correct |
23 |
Correct |
1259 ms |
297380 KB |
Output is correct |
24 |
Correct |
1208 ms |
297296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
13 ms |
4692 KB |
Output is correct |
8 |
Correct |
400 ms |
260176 KB |
Output is correct |
9 |
Correct |
372 ms |
260176 KB |
Output is correct |
10 |
Correct |
417 ms |
260180 KB |
Output is correct |
11 |
Correct |
393 ms |
260176 KB |
Output is correct |
12 |
Correct |
381 ms |
122436 KB |
Output is correct |
13 |
Correct |
494 ms |
122440 KB |
Output is correct |
14 |
Correct |
485 ms |
122448 KB |
Output is correct |
15 |
Correct |
485 ms |
122260 KB |
Output is correct |
16 |
Correct |
507 ms |
122448 KB |
Output is correct |
17 |
Correct |
473 ms |
122380 KB |
Output is correct |
18 |
Correct |
797 ms |
260264 KB |
Output is correct |
19 |
Correct |
1123 ms |
260252 KB |
Output is correct |
20 |
Correct |
1089 ms |
260260 KB |
Output is correct |
21 |
Correct |
1014 ms |
260056 KB |
Output is correct |
22 |
Correct |
1106 ms |
260072 KB |
Output is correct |
23 |
Correct |
1051 ms |
260248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
600 KB |
Output is correct |
25 |
Correct |
17 ms |
5208 KB |
Output is correct |
26 |
Correct |
14 ms |
4696 KB |
Output is correct |
27 |
Correct |
10 ms |
3672 KB |
Output is correct |
28 |
Correct |
17 ms |
5208 KB |
Output is correct |
29 |
Correct |
14 ms |
4696 KB |
Output is correct |
30 |
Correct |
587 ms |
139600 KB |
Output is correct |
31 |
Correct |
535 ms |
139856 KB |
Output is correct |
32 |
Correct |
681 ms |
140112 KB |
Output is correct |
33 |
Correct |
694 ms |
140688 KB |
Output is correct |
34 |
Correct |
724 ms |
140948 KB |
Output is correct |
35 |
Correct |
674 ms |
139600 KB |
Output is correct |
36 |
Correct |
476 ms |
126812 KB |
Output is correct |
37 |
Correct |
494 ms |
126840 KB |
Output is correct |
38 |
Correct |
636 ms |
128740 KB |
Output is correct |
39 |
Correct |
634 ms |
126800 KB |
Output is correct |
40 |
Correct |
608 ms |
125604 KB |
Output is correct |
41 |
Correct |
593 ms |
123728 KB |
Output is correct |
42 |
Correct |
550 ms |
131344 KB |
Output is correct |
43 |
Correct |
653 ms |
130876 KB |
Output is correct |
44 |
Correct |
647 ms |
130896 KB |
Output is correct |
45 |
Correct |
657 ms |
131180 KB |
Output is correct |
46 |
Correct |
693 ms |
130896 KB |
Output is correct |
47 |
Correct |
678 ms |
131528 KB |
Output is correct |
48 |
Correct |
637 ms |
139604 KB |
Output is correct |
49 |
Correct |
557 ms |
140368 KB |
Output is correct |
50 |
Correct |
727 ms |
139632 KB |
Output is correct |
51 |
Correct |
499 ms |
120896 KB |
Output is correct |
52 |
Correct |
587 ms |
122188 KB |
Output is correct |
53 |
Correct |
577 ms |
121168 KB |
Output is correct |
54 |
Correct |
618 ms |
121120 KB |
Output is correct |
55 |
Correct |
602 ms |
121532 KB |
Output is correct |
56 |
Correct |
582 ms |
121424 KB |
Output is correct |
57 |
Correct |
994 ms |
85188 KB |
Output is correct |
58 |
Correct |
319 ms |
85192 KB |
Output is correct |
59 |
Correct |
297 ms |
85324 KB |
Output is correct |
60 |
Correct |
319 ms |
85140 KB |
Output is correct |
61 |
Correct |
289 ms |
85192 KB |
Output is correct |
62 |
Correct |
413 ms |
142160 KB |
Output is correct |
63 |
Correct |
444 ms |
141960 KB |
Output is correct |
64 |
Correct |
584 ms |
142048 KB |
Output is correct |
65 |
Correct |
565 ms |
142184 KB |
Output is correct |
66 |
Correct |
574 ms |
142096 KB |
Output is correct |
67 |
Correct |
550 ms |
142160 KB |
Output is correct |
68 |
Correct |
392 ms |
122452 KB |
Output is correct |
69 |
Correct |
488 ms |
122344 KB |
Output is correct |
70 |
Correct |
473 ms |
122448 KB |
Output is correct |
71 |
Correct |
477 ms |
122432 KB |
Output is correct |
72 |
Correct |
497 ms |
122448 KB |
Output is correct |
73 |
Correct |
453 ms |
122448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
600 KB |
Output is correct |
25 |
Correct |
17 ms |
5208 KB |
Output is correct |
26 |
Correct |
14 ms |
4696 KB |
Output is correct |
27 |
Correct |
10 ms |
3672 KB |
Output is correct |
28 |
Correct |
17 ms |
5208 KB |
Output is correct |
29 |
Correct |
14 ms |
4696 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
987 ms |
301820 KB |
Output is correct |
32 |
Correct |
991 ms |
301396 KB |
Output is correct |
33 |
Correct |
930 ms |
299900 KB |
Output is correct |
34 |
Correct |
948 ms |
302416 KB |
Output is correct |
35 |
Correct |
434 ms |
265296 KB |
Output is correct |
36 |
Correct |
411 ms |
265376 KB |
Output is correct |
37 |
Correct |
755 ms |
273616 KB |
Output is correct |
38 |
Correct |
751 ms |
265424 KB |
Output is correct |
39 |
Correct |
708 ms |
256976 KB |
Output is correct |
40 |
Correct |
712 ms |
253400 KB |
Output is correct |
41 |
Correct |
851 ms |
276816 KB |
Output is correct |
42 |
Correct |
873 ms |
276700 KB |
Output is correct |
43 |
Correct |
854 ms |
276560 KB |
Output is correct |
44 |
Correct |
836 ms |
275792 KB |
Output is correct |
45 |
Correct |
896 ms |
293948 KB |
Output is correct |
46 |
Correct |
0 ms |
344 KB |
Output is correct |
47 |
Correct |
1 ms |
344 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Correct |
731 ms |
244632 KB |
Output is correct |
51 |
Correct |
689 ms |
245220 KB |
Output is correct |
52 |
Correct |
722 ms |
244688 KB |
Output is correct |
53 |
Correct |
740 ms |
246568 KB |
Output is correct |
54 |
Correct |
314 ms |
170164 KB |
Output is correct |
55 |
Correct |
323 ms |
170180 KB |
Output is correct |
56 |
Correct |
325 ms |
170056 KB |
Output is correct |
57 |
Correct |
312 ms |
170180 KB |
Output is correct |
58 |
Correct |
465 ms |
297296 KB |
Output is correct |
59 |
Correct |
475 ms |
297584 KB |
Output is correct |
60 |
Correct |
474 ms |
297296 KB |
Output is correct |
61 |
Correct |
474 ms |
297436 KB |
Output is correct |
62 |
Correct |
412 ms |
260024 KB |
Output is correct |
63 |
Correct |
384 ms |
260260 KB |
Output is correct |
64 |
Correct |
408 ms |
260264 KB |
Output is correct |
65 |
Correct |
395 ms |
260212 KB |
Output is correct |
66 |
Correct |
0 ms |
344 KB |
Output is correct |
67 |
Correct |
0 ms |
344 KB |
Output is correct |
68 |
Correct |
1 ms |
344 KB |
Output is correct |
69 |
Correct |
1 ms |
344 KB |
Output is correct |
70 |
Correct |
1 ms |
344 KB |
Output is correct |
71 |
Correct |
1 ms |
344 KB |
Output is correct |
72 |
Correct |
2 ms |
856 KB |
Output is correct |
73 |
Correct |
14 ms |
5008 KB |
Output is correct |
74 |
Correct |
460 ms |
297632 KB |
Output is correct |
75 |
Correct |
449 ms |
297364 KB |
Output is correct |
76 |
Correct |
471 ms |
297424 KB |
Output is correct |
77 |
Correct |
443 ms |
297552 KB |
Output is correct |
78 |
Correct |
443 ms |
141984 KB |
Output is correct |
79 |
Correct |
419 ms |
141996 KB |
Output is correct |
80 |
Correct |
580 ms |
142156 KB |
Output is correct |
81 |
Correct |
566 ms |
142152 KB |
Output is correct |
82 |
Correct |
578 ms |
142160 KB |
Output is correct |
83 |
Correct |
570 ms |
142160 KB |
Output is correct |
84 |
Correct |
892 ms |
297428 KB |
Output is correct |
85 |
Correct |
869 ms |
297500 KB |
Output is correct |
86 |
Correct |
1233 ms |
297428 KB |
Output is correct |
87 |
Correct |
1214 ms |
297296 KB |
Output is correct |
88 |
Correct |
1259 ms |
297380 KB |
Output is correct |
89 |
Correct |
1208 ms |
297296 KB |
Output is correct |
90 |
Correct |
0 ms |
340 KB |
Output is correct |
91 |
Correct |
1 ms |
344 KB |
Output is correct |
92 |
Correct |
1 ms |
344 KB |
Output is correct |
93 |
Correct |
1 ms |
344 KB |
Output is correct |
94 |
Correct |
1 ms |
344 KB |
Output is correct |
95 |
Correct |
1 ms |
600 KB |
Output is correct |
96 |
Correct |
13 ms |
4692 KB |
Output is correct |
97 |
Correct |
400 ms |
260176 KB |
Output is correct |
98 |
Correct |
372 ms |
260176 KB |
Output is correct |
99 |
Correct |
417 ms |
260180 KB |
Output is correct |
100 |
Correct |
393 ms |
260176 KB |
Output is correct |
101 |
Correct |
381 ms |
122436 KB |
Output is correct |
102 |
Correct |
494 ms |
122440 KB |
Output is correct |
103 |
Correct |
485 ms |
122448 KB |
Output is correct |
104 |
Correct |
485 ms |
122260 KB |
Output is correct |
105 |
Correct |
507 ms |
122448 KB |
Output is correct |
106 |
Correct |
473 ms |
122380 KB |
Output is correct |
107 |
Correct |
797 ms |
260264 KB |
Output is correct |
108 |
Correct |
1123 ms |
260252 KB |
Output is correct |
109 |
Correct |
1089 ms |
260260 KB |
Output is correct |
110 |
Correct |
1014 ms |
260056 KB |
Output is correct |
111 |
Correct |
1106 ms |
260072 KB |
Output is correct |
112 |
Correct |
1051 ms |
260248 KB |
Output is correct |
113 |
Correct |
587 ms |
139600 KB |
Output is correct |
114 |
Correct |
535 ms |
139856 KB |
Output is correct |
115 |
Correct |
681 ms |
140112 KB |
Output is correct |
116 |
Correct |
694 ms |
140688 KB |
Output is correct |
117 |
Correct |
724 ms |
140948 KB |
Output is correct |
118 |
Correct |
674 ms |
139600 KB |
Output is correct |
119 |
Correct |
476 ms |
126812 KB |
Output is correct |
120 |
Correct |
494 ms |
126840 KB |
Output is correct |
121 |
Correct |
636 ms |
128740 KB |
Output is correct |
122 |
Correct |
634 ms |
126800 KB |
Output is correct |
123 |
Correct |
608 ms |
125604 KB |
Output is correct |
124 |
Correct |
593 ms |
123728 KB |
Output is correct |
125 |
Correct |
550 ms |
131344 KB |
Output is correct |
126 |
Correct |
653 ms |
130876 KB |
Output is correct |
127 |
Correct |
647 ms |
130896 KB |
Output is correct |
128 |
Correct |
657 ms |
131180 KB |
Output is correct |
129 |
Correct |
693 ms |
130896 KB |
Output is correct |
130 |
Correct |
678 ms |
131528 KB |
Output is correct |
131 |
Correct |
637 ms |
139604 KB |
Output is correct |
132 |
Correct |
557 ms |
140368 KB |
Output is correct |
133 |
Correct |
727 ms |
139632 KB |
Output is correct |
134 |
Correct |
499 ms |
120896 KB |
Output is correct |
135 |
Correct |
587 ms |
122188 KB |
Output is correct |
136 |
Correct |
577 ms |
121168 KB |
Output is correct |
137 |
Correct |
618 ms |
121120 KB |
Output is correct |
138 |
Correct |
602 ms |
121532 KB |
Output is correct |
139 |
Correct |
582 ms |
121424 KB |
Output is correct |
140 |
Correct |
994 ms |
85188 KB |
Output is correct |
141 |
Correct |
319 ms |
85192 KB |
Output is correct |
142 |
Correct |
297 ms |
85324 KB |
Output is correct |
143 |
Correct |
319 ms |
85140 KB |
Output is correct |
144 |
Correct |
289 ms |
85192 KB |
Output is correct |
145 |
Correct |
413 ms |
142160 KB |
Output is correct |
146 |
Correct |
444 ms |
141960 KB |
Output is correct |
147 |
Correct |
584 ms |
142048 KB |
Output is correct |
148 |
Correct |
565 ms |
142184 KB |
Output is correct |
149 |
Correct |
574 ms |
142096 KB |
Output is correct |
150 |
Correct |
550 ms |
142160 KB |
Output is correct |
151 |
Correct |
392 ms |
122452 KB |
Output is correct |
152 |
Correct |
488 ms |
122344 KB |
Output is correct |
153 |
Correct |
473 ms |
122448 KB |
Output is correct |
154 |
Correct |
477 ms |
122432 KB |
Output is correct |
155 |
Correct |
497 ms |
122448 KB |
Output is correct |
156 |
Correct |
453 ms |
122448 KB |
Output is correct |
157 |
Correct |
1399 ms |
300820 KB |
Output is correct |
158 |
Correct |
1349 ms |
301484 KB |
Output is correct |
159 |
Correct |
1685 ms |
300112 KB |
Output is correct |
160 |
Correct |
1766 ms |
300116 KB |
Output is correct |
161 |
Correct |
1710 ms |
302488 KB |
Output is correct |
162 |
Correct |
1666 ms |
302040 KB |
Output is correct |
163 |
Correct |
1077 ms |
265296 KB |
Output is correct |
164 |
Correct |
1118 ms |
265552 KB |
Output is correct |
165 |
Correct |
1547 ms |
273624 KB |
Output is correct |
166 |
Correct |
1554 ms |
265376 KB |
Output is correct |
167 |
Correct |
1441 ms |
256976 KB |
Output is correct |
168 |
Correct |
1398 ms |
253392 KB |
Output is correct |
169 |
Correct |
1253 ms |
276432 KB |
Output is correct |
170 |
Correct |
1534 ms |
275828 KB |
Output is correct |
171 |
Correct |
1508 ms |
275856 KB |
Output is correct |
172 |
Correct |
1528 ms |
275792 KB |
Output is correct |
173 |
Correct |
1573 ms |
276048 KB |
Output is correct |
174 |
Correct |
1591 ms |
276844 KB |
Output is correct |
175 |
Correct |
1405 ms |
292828 KB |
Output is correct |
176 |
Correct |
1371 ms |
293200 KB |
Output is correct |
177 |
Correct |
1797 ms |
296932 KB |
Output is correct |
178 |
Correct |
1191 ms |
247180 KB |
Output is correct |
179 |
Correct |
1428 ms |
245072 KB |
Output is correct |
180 |
Correct |
1344 ms |
249308 KB |
Output is correct |
181 |
Correct |
1320 ms |
244048 KB |
Output is correct |
182 |
Correct |
1295 ms |
245584 KB |
Output is correct |
183 |
Correct |
1292 ms |
244560 KB |
Output is correct |
184 |
Execution timed out |
3089 ms |
170436 KB |
Time limit exceeded |
185 |
Halted |
0 ms |
0 KB |
- |