# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
441108 | 2021-07-04T07:44:06 Z | mosesmayer | Remittance (JOI19_remittance) | C++17 | 463 ms | 44216 KB |
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define int LL using namespace std; typedef long long LL; typedef pair<int,int> pii; typedef vector<int> vi; const LL LINF = 1e18; const int mxsz = 1e6 + 5; int n; int a[mxsz], b[mxsz]; int d[mxsz]; int32_t main(){ scanf("%lld", &n); for (int i = 0; i < n; i++) scanf("%lld %lld", a+i, b+i); LL dbt = 0, zeroed = 0, topup = 0, neg = 0; LL totalTopup = 0; for (int i = 0; i < n; i++){ d[i] = a[i] - b[i]; if (d[i] > 0) topup++, totalTopup += d[i]; else if (d[i] < 0) neg++; } #ifdef DEBUG for (int i = 0; i < n; i++){ cout << i << ": " << d[i] << '\n'; } #endif bool can = 1; for (int i = 0; neg > 0 || dbt < 0; (i += n-1) %= n){ dbt <<= 1; #ifdef DEBUG cout << i << ' ' << dbt << ' ' << topup << ' ' << neg << '\n'; #endif if (topup == 0){can = 0; break;} if (d[i] < 0){ dbt += d[i]; neg--; d[i] = 0; } else if (d[i] > 0){ if (dbt < 0){ LL x = min(llabs(dbt), 1LL * d[i]); dbt += x; d[i] -= x; if (d[i] == 0) topup--; } } if (dbt < (-LINF)){can = 0; break;} } if (can && topup > 0){ #ifdef DEBUG cout << "topup available\n"; for (int i = 0; i < n; i++){ cout << i << ": " << d[i] << '\n'; } #endif int cur = 0; int extra = 0; for (int i = 0; i < n; i++) extra += d[i]; for (int i = 0; cur++ < n + 10 && extra > 0; (i += 1)%=n){ if (d[i] > 1){ int x = d[i]; d[i] -= x; extra -= x; extra += __builtin_popcount(x); cur = 0; for (int b = 0; (1<<b) <= x; b++){ if (x & (1<<b)) d[(i + b) % n]++; } } } bool sabi = 1, pinjem = 0; for (int i = 0; i < n; i++){ sabi &= d[i] == 1; pinjem |= b[i] > 0; } if (extra > 0 && !(sabi && pinjem)) can = 0; } puts(can ? "Yes" : "No"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 300 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 1 ms | 204 KB | Output is correct |
17 | Correct | 1 ms | 204 KB | Output is correct |
18 | Correct | 1 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 312 KB | Output is correct |
20 | Correct | 1 ms | 204 KB | Output is correct |
21 | Correct | 1 ms | 256 KB | Output is correct |
22 | Correct | 1 ms | 204 KB | Output is correct |
23 | Correct | 1 ms | 204 KB | Output is correct |
24 | Correct | 1 ms | 204 KB | Output is correct |
25 | Correct | 0 ms | 204 KB | Output is correct |
26 | Correct | 1 ms | 204 KB | Output is correct |
27 | Correct | 0 ms | 204 KB | Output is correct |
28 | Correct | 0 ms | 204 KB | Output is correct |
29 | Correct | 1 ms | 332 KB | Output is correct |
30 | Correct | 1 ms | 304 KB | Output is correct |
31 | Correct | 0 ms | 204 KB | Output is correct |
32 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 300 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 1 ms | 204 KB | Output is correct |
17 | Correct | 1 ms | 204 KB | Output is correct |
18 | Correct | 1 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 312 KB | Output is correct |
20 | Correct | 1 ms | 204 KB | Output is correct |
21 | Correct | 1 ms | 256 KB | Output is correct |
22 | Correct | 1 ms | 204 KB | Output is correct |
23 | Correct | 1 ms | 204 KB | Output is correct |
24 | Correct | 1 ms | 204 KB | Output is correct |
25 | Correct | 0 ms | 204 KB | Output is correct |
26 | Correct | 1 ms | 204 KB | Output is correct |
27 | Correct | 0 ms | 204 KB | Output is correct |
28 | Correct | 0 ms | 204 KB | Output is correct |
29 | Correct | 1 ms | 332 KB | Output is correct |
30 | Correct | 1 ms | 304 KB | Output is correct |
31 | Correct | 0 ms | 204 KB | Output is correct |
32 | Correct | 0 ms | 204 KB | Output is correct |
33 | Correct | 1 ms | 204 KB | Output is correct |
34 | Correct | 1 ms | 204 KB | Output is correct |
35 | Correct | 0 ms | 204 KB | Output is correct |
36 | Correct | 1 ms | 204 KB | Output is correct |
37 | Correct | 0 ms | 204 KB | Output is correct |
38 | Correct | 1 ms | 204 KB | Output is correct |
39 | Correct | 1 ms | 204 KB | Output is correct |
40 | Correct | 0 ms | 204 KB | Output is correct |
41 | Correct | 0 ms | 204 KB | Output is correct |
42 | Correct | 1 ms | 204 KB | Output is correct |
43 | Correct | 1 ms | 204 KB | Output is correct |
44 | Correct | 1 ms | 204 KB | Output is correct |
45 | Correct | 1 ms | 204 KB | Output is correct |
46 | Correct | 1 ms | 204 KB | Output is correct |
47 | Correct | 0 ms | 204 KB | Output is correct |
48 | Correct | 0 ms | 204 KB | Output is correct |
49 | Correct | 1 ms | 204 KB | Output is correct |
50 | Correct | 1 ms | 204 KB | Output is correct |
51 | Correct | 0 ms | 204 KB | Output is correct |
52 | Correct | 1 ms | 204 KB | Output is correct |
53 | Correct | 1 ms | 204 KB | Output is correct |
54 | Correct | 1 ms | 204 KB | Output is correct |
55 | Correct | 1 ms | 204 KB | Output is correct |
56 | Correct | 1 ms | 204 KB | Output is correct |
57 | Correct | 1 ms | 204 KB | Output is correct |
58 | Correct | 1 ms | 204 KB | Output is correct |
59 | Correct | 1 ms | 204 KB | Output is correct |
60 | Correct | 1 ms | 204 KB | Output is correct |
61 | Correct | 1 ms | 204 KB | Output is correct |
62 | Correct | 1 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 300 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 1 ms | 204 KB | Output is correct |
17 | Correct | 1 ms | 204 KB | Output is correct |
18 | Correct | 1 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 312 KB | Output is correct |
20 | Correct | 1 ms | 204 KB | Output is correct |
21 | Correct | 1 ms | 256 KB | Output is correct |
22 | Correct | 1 ms | 204 KB | Output is correct |
23 | Correct | 1 ms | 204 KB | Output is correct |
24 | Correct | 1 ms | 204 KB | Output is correct |
25 | Correct | 0 ms | 204 KB | Output is correct |
26 | Correct | 1 ms | 204 KB | Output is correct |
27 | Correct | 0 ms | 204 KB | Output is correct |
28 | Correct | 0 ms | 204 KB | Output is correct |
29 | Correct | 1 ms | 332 KB | Output is correct |
30 | Correct | 1 ms | 304 KB | Output is correct |
31 | Correct | 0 ms | 204 KB | Output is correct |
32 | Correct | 0 ms | 204 KB | Output is correct |
33 | Correct | 1 ms | 204 KB | Output is correct |
34 | Correct | 1 ms | 204 KB | Output is correct |
35 | Correct | 0 ms | 204 KB | Output is correct |
36 | Correct | 1 ms | 204 KB | Output is correct |
37 | Correct | 0 ms | 204 KB | Output is correct |
38 | Correct | 1 ms | 204 KB | Output is correct |
39 | Correct | 1 ms | 204 KB | Output is correct |
40 | Correct | 0 ms | 204 KB | Output is correct |
41 | Correct | 0 ms | 204 KB | Output is correct |
42 | Correct | 1 ms | 204 KB | Output is correct |
43 | Correct | 1 ms | 204 KB | Output is correct |
44 | Correct | 1 ms | 204 KB | Output is correct |
45 | Correct | 1 ms | 204 KB | Output is correct |
46 | Correct | 1 ms | 204 KB | Output is correct |
47 | Correct | 0 ms | 204 KB | Output is correct |
48 | Correct | 0 ms | 204 KB | Output is correct |
49 | Correct | 1 ms | 204 KB | Output is correct |
50 | Correct | 1 ms | 204 KB | Output is correct |
51 | Correct | 0 ms | 204 KB | Output is correct |
52 | Correct | 1 ms | 204 KB | Output is correct |
53 | Correct | 1 ms | 204 KB | Output is correct |
54 | Correct | 1 ms | 204 KB | Output is correct |
55 | Correct | 1 ms | 204 KB | Output is correct |
56 | Correct | 1 ms | 204 KB | Output is correct |
57 | Correct | 1 ms | 204 KB | Output is correct |
58 | Correct | 1 ms | 204 KB | Output is correct |
59 | Correct | 1 ms | 204 KB | Output is correct |
60 | Correct | 1 ms | 204 KB | Output is correct |
61 | Correct | 1 ms | 204 KB | Output is correct |
62 | Correct | 1 ms | 204 KB | Output is correct |
63 | Correct | 281 ms | 43020 KB | Output is correct |
64 | Correct | 208 ms | 27568 KB | Output is correct |
65 | Correct | 437 ms | 42900 KB | Output is correct |
66 | Correct | 207 ms | 27592 KB | Output is correct |
67 | Correct | 199 ms | 29044 KB | Output is correct |
68 | Correct | 207 ms | 31312 KB | Output is correct |
69 | Correct | 400 ms | 43072 KB | Output is correct |
70 | Correct | 212 ms | 27716 KB | Output is correct |
71 | Correct | 209 ms | 29020 KB | Output is correct |
72 | Correct | 198 ms | 31428 KB | Output is correct |
73 | Correct | 403 ms | 43160 KB | Output is correct |
74 | Correct | 206 ms | 27588 KB | Output is correct |
75 | Correct | 202 ms | 29016 KB | Output is correct |
76 | Correct | 205 ms | 31428 KB | Output is correct |
77 | Correct | 286 ms | 43140 KB | Output is correct |
78 | Correct | 406 ms | 35396 KB | Output is correct |
79 | Correct | 404 ms | 35392 KB | Output is correct |
80 | Correct | 380 ms | 35280 KB | Output is correct |
81 | Correct | 405 ms | 35440 KB | Output is correct |
82 | Correct | 180 ms | 27580 KB | Output is correct |
83 | Correct | 173 ms | 27732 KB | Output is correct |
84 | Correct | 199 ms | 27588 KB | Output is correct |
85 | Correct | 446 ms | 44208 KB | Output is correct |
86 | Correct | 463 ms | 44216 KB | Output is correct |
87 | Correct | 344 ms | 36568 KB | Output is correct |
88 | Correct | 337 ms | 36444 KB | Output is correct |