# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200631 | 2020-02-07T18:02:31 Z | tincamatei | Remittance (JOI19_remittance) | C++14 | 387 ms | 43640 KB |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1000000; const int INF = 1000000000; const long long INFLL = (long long)MAX_N * INF; long long A[MAX_N], B[MAX_N]; bool viz[MAX_N]; long long finalSent[MAX_N]; bool solveRequests(int i, int reqAmount, int N, bool addSent = false) { if(viz[i]) return false; viz[i] = true; if(reqAmount > INF) return false; if(addSent) finalSent[i] += reqAmount / 2; if(A[i] < reqAmount) { reqAmount -= A[i]; A[i] = 0; if(!solveRequests((i - 1 + N) % N, reqAmount * 2, N, true)) return false; } else { A[i] -= reqAmount; } viz[i] = false; return true; } void answerIsNo() { printf("No"); exit(0); } // A[i] - 2 * sent[i] + sent[i - 1] == 0 // A[i] == 2 * sent[i] - sent[i - 1] long long sent[MAX_N]; long long Ac[MAX_N]; int check(long long val, int N, long long overflow) { sent[0] = val; if(overflow - val < 0) return +1; overflow -= val; for(int i = 1; i < N; ++i) { // A[i] = 2 * sent[i] - sent[i - 1] // sent[i] = (A[i] + sent[i - 1]) / 2 sent[i] = (A[i] + sent[i - 1]) / 2; overflow -= sent[i]; if(overflow < 0) return +1; } if(overflow < 0) return +1; else if(overflow > 0) return -1; return 0; } bool launderMoney(int N) { long long st = -1, dr = INFLL + 1; long long overflow = 0LL; for(int i = 0; i < N; ++i) overflow += A[i]; while(dr - st > 1) { int mid = (st + dr) / 2; int rez = check(mid, N, overflow); if(rez == -1) // Too small st = mid; else if(rez == 1) // Too big dr = mid; else { // perfect for(int i = 0; i < N; ++i) { if(A[i] != 2 * sent[i] - sent[(i - 1 + N) % N]) return false; finalSent[i] += sent[i]; } return true; } } return false; } bool checkSent(int N) { for(int _i = 0; _i < 3 * N; ++_i) { int i = _i % N; long long send = min(finalSent[i], Ac[i] / 2); Ac[i] -= 2 * send; Ac[(i + 1) % N] += send; finalSent[i] -= send; } for(int i = 0; i < N; ++i) if(finalSent[i] != 0 || Ac[i] != B[i]) return false; return true; } int main() { int N; scanf("%d", &N); for(int i = 0; i < N; ++i) { scanf("%lld%lld", &A[i], &B[i]); Ac[i] = A[i]; } for(int i = 0; i < N; ++i) { if(!solveRequests(i, B[i], N)) answerIsNo(); } if(!launderMoney(N)) answerIsNo(); if(!checkSent(N)) answerIsNo(); printf("Yes"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 380 KB | Output is correct |
6 | Correct | 5 ms | 380 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 5 ms | 376 KB | Output is correct |
12 | Correct | 5 ms | 380 KB | Output is correct |
13 | Correct | 5 ms | 376 KB | Output is correct |
14 | Correct | 5 ms | 376 KB | Output is correct |
15 | Correct | 5 ms | 376 KB | Output is correct |
16 | Correct | 5 ms | 376 KB | Output is correct |
17 | Correct | 5 ms | 380 KB | Output is correct |
18 | Correct | 5 ms | 376 KB | Output is correct |
19 | Correct | 5 ms | 376 KB | Output is correct |
20 | Correct | 5 ms | 376 KB | Output is correct |
21 | Correct | 5 ms | 376 KB | Output is correct |
22 | Correct | 5 ms | 376 KB | Output is correct |
23 | Correct | 5 ms | 376 KB | Output is correct |
24 | Correct | 5 ms | 376 KB | Output is correct |
25 | Correct | 5 ms | 376 KB | Output is correct |
26 | Correct | 5 ms | 376 KB | Output is correct |
27 | Correct | 5 ms | 376 KB | Output is correct |
28 | Correct | 5 ms | 376 KB | Output is correct |
29 | Correct | 5 ms | 376 KB | Output is correct |
30 | Correct | 5 ms | 376 KB | Output is correct |
31 | Correct | 5 ms | 376 KB | Output is correct |
32 | Correct | 5 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 380 KB | Output is correct |
6 | Correct | 5 ms | 380 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 5 ms | 376 KB | Output is correct |
12 | Correct | 5 ms | 380 KB | Output is correct |
13 | Correct | 5 ms | 376 KB | Output is correct |
14 | Correct | 5 ms | 376 KB | Output is correct |
15 | Correct | 5 ms | 376 KB | Output is correct |
16 | Correct | 5 ms | 376 KB | Output is correct |
17 | Correct | 5 ms | 380 KB | Output is correct |
18 | Correct | 5 ms | 376 KB | Output is correct |
19 | Correct | 5 ms | 376 KB | Output is correct |
20 | Correct | 5 ms | 376 KB | Output is correct |
21 | Correct | 5 ms | 376 KB | Output is correct |
22 | Correct | 5 ms | 376 KB | Output is correct |
23 | Correct | 5 ms | 376 KB | Output is correct |
24 | Correct | 5 ms | 376 KB | Output is correct |
25 | Correct | 5 ms | 376 KB | Output is correct |
26 | Correct | 5 ms | 376 KB | Output is correct |
27 | Correct | 5 ms | 376 KB | Output is correct |
28 | Correct | 5 ms | 376 KB | Output is correct |
29 | Correct | 5 ms | 376 KB | Output is correct |
30 | Correct | 5 ms | 376 KB | Output is correct |
31 | Correct | 5 ms | 376 KB | Output is correct |
32 | Correct | 5 ms | 376 KB | Output is correct |
33 | Correct | 6 ms | 376 KB | Output is correct |
34 | Correct | 5 ms | 376 KB | Output is correct |
35 | Correct | 5 ms | 376 KB | Output is correct |
36 | Correct | 5 ms | 380 KB | Output is correct |
37 | Correct | 5 ms | 376 KB | Output is correct |
38 | Correct | 5 ms | 376 KB | Output is correct |
39 | Correct | 5 ms | 376 KB | Output is correct |
40 | Correct | 5 ms | 376 KB | Output is correct |
41 | Correct | 5 ms | 376 KB | Output is correct |
42 | Correct | 5 ms | 376 KB | Output is correct |
43 | Correct | 5 ms | 380 KB | Output is correct |
44 | Correct | 5 ms | 376 KB | Output is correct |
45 | Correct | 5 ms | 380 KB | Output is correct |
46 | Correct | 5 ms | 376 KB | Output is correct |
47 | Correct | 6 ms | 376 KB | Output is correct |
48 | Correct | 5 ms | 376 KB | Output is correct |
49 | Correct | 5 ms | 376 KB | Output is correct |
50 | Correct | 5 ms | 376 KB | Output is correct |
51 | Correct | 5 ms | 376 KB | Output is correct |
52 | Correct | 5 ms | 376 KB | Output is correct |
53 | Correct | 5 ms | 376 KB | Output is correct |
54 | Correct | 5 ms | 376 KB | Output is correct |
55 | Correct | 5 ms | 376 KB | Output is correct |
56 | Correct | 5 ms | 376 KB | Output is correct |
57 | Correct | 5 ms | 376 KB | Output is correct |
58 | Correct | 5 ms | 376 KB | Output is correct |
59 | Correct | 5 ms | 376 KB | Output is correct |
60 | Correct | 5 ms | 376 KB | Output is correct |
61 | Correct | 5 ms | 376 KB | Output is correct |
62 | Correct | 5 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 380 KB | Output is correct |
6 | Correct | 5 ms | 380 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 5 ms | 376 KB | Output is correct |
12 | Correct | 5 ms | 380 KB | Output is correct |
13 | Correct | 5 ms | 376 KB | Output is correct |
14 | Correct | 5 ms | 376 KB | Output is correct |
15 | Correct | 5 ms | 376 KB | Output is correct |
16 | Correct | 5 ms | 376 KB | Output is correct |
17 | Correct | 5 ms | 380 KB | Output is correct |
18 | Correct | 5 ms | 376 KB | Output is correct |
19 | Correct | 5 ms | 376 KB | Output is correct |
20 | Correct | 5 ms | 376 KB | Output is correct |
21 | Correct | 5 ms | 376 KB | Output is correct |
22 | Correct | 5 ms | 376 KB | Output is correct |
23 | Correct | 5 ms | 376 KB | Output is correct |
24 | Correct | 5 ms | 376 KB | Output is correct |
25 | Correct | 5 ms | 376 KB | Output is correct |
26 | Correct | 5 ms | 376 KB | Output is correct |
27 | Correct | 5 ms | 376 KB | Output is correct |
28 | Correct | 5 ms | 376 KB | Output is correct |
29 | Correct | 5 ms | 376 KB | Output is correct |
30 | Correct | 5 ms | 376 KB | Output is correct |
31 | Correct | 5 ms | 376 KB | Output is correct |
32 | Correct | 5 ms | 376 KB | Output is correct |
33 | Correct | 6 ms | 376 KB | Output is correct |
34 | Correct | 5 ms | 376 KB | Output is correct |
35 | Correct | 5 ms | 376 KB | Output is correct |
36 | Correct | 5 ms | 380 KB | Output is correct |
37 | Correct | 5 ms | 376 KB | Output is correct |
38 | Correct | 5 ms | 376 KB | Output is correct |
39 | Correct | 5 ms | 376 KB | Output is correct |
40 | Correct | 5 ms | 376 KB | Output is correct |
41 | Correct | 5 ms | 376 KB | Output is correct |
42 | Correct | 5 ms | 376 KB | Output is correct |
43 | Correct | 5 ms | 380 KB | Output is correct |
44 | Correct | 5 ms | 376 KB | Output is correct |
45 | Correct | 5 ms | 380 KB | Output is correct |
46 | Correct | 5 ms | 376 KB | Output is correct |
47 | Correct | 6 ms | 376 KB | Output is correct |
48 | Correct | 5 ms | 376 KB | Output is correct |
49 | Correct | 5 ms | 376 KB | Output is correct |
50 | Correct | 5 ms | 376 KB | Output is correct |
51 | Correct | 5 ms | 376 KB | Output is correct |
52 | Correct | 5 ms | 376 KB | Output is correct |
53 | Correct | 5 ms | 376 KB | Output is correct |
54 | Correct | 5 ms | 376 KB | Output is correct |
55 | Correct | 5 ms | 376 KB | Output is correct |
56 | Correct | 5 ms | 376 KB | Output is correct |
57 | Correct | 5 ms | 376 KB | Output is correct |
58 | Correct | 5 ms | 376 KB | Output is correct |
59 | Correct | 5 ms | 376 KB | Output is correct |
60 | Correct | 5 ms | 376 KB | Output is correct |
61 | Correct | 5 ms | 376 KB | Output is correct |
62 | Correct | 5 ms | 376 KB | Output is correct |
63 | Correct | 387 ms | 23912 KB | Output is correct |
64 | Correct | 269 ms | 43640 KB | Output is correct |
65 | Incorrect | 386 ms | 23928 KB | Output isn't correct |
66 | Halted | 0 ms | 0 KB | - |