Submission #502936

# Submission time Handle Problem Language Result Execution time Memory
502936 2022-01-06T18:56:40 Z tengiz05 Remittance (JOI19_remittance) C++17
55 / 100
1000 ms 11460 KB
#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n;
    std::cin >> n;
    
    std::vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i] >> b[i];
    }
    
    std::function<void()> dfs = [&]() {
        for (int _ = 0; _ < 50 * n; _++) {
            int p = 0;
            for (int i = 0; i < n; i++) {
                int j = (p + 1) % n;
                int d = a[p] - b[p];
                if (d <= 0) {
                    p = j;
                    continue;
                }
                if (d == 1 && a[p] > 1) {
                    d++;
                }
                d /= 2;
                a[p] -= 2 * d;
                a[j] += d;
                p = j;
            }
            if (a == b) {
                std::cout << "Yes\n";
                std::exit(0);
            }
            int good = 0;
            for (int i = 0; i < n; i++) {
                good += a[i] > b[i];
            }
            if (!good) {
                std::cout << "No\n";
                std::exit(0);
            }
        }
        std::cout << "No\n";
        std::exit(0);
    };
    
    dfs();
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 308 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 1 ms 288 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 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 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 312 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 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 308 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 1 ms 288 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 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 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 316 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 0 ms 312 KB Output is correct
41 Correct 0 ms 312 KB Output is correct
42 Correct 1 ms 296 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 316 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 0 ms 308 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 1 ms 312 KB Output is correct
55 Correct 0 ms 204 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 0 ms 312 KB Output is correct
58 Correct 0 ms 308 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 312 KB Output is correct
61 Correct 1 ms 204 KB Output is correct
62 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 308 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 1 ms 288 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 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 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 316 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 0 ms 312 KB Output is correct
41 Correct 0 ms 312 KB Output is correct
42 Correct 1 ms 296 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 316 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 0 ms 308 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 1 ms 312 KB Output is correct
55 Correct 0 ms 204 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 0 ms 312 KB Output is correct
58 Correct 0 ms 308 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 312 KB Output is correct
61 Correct 1 ms 204 KB Output is correct
62 Correct 0 ms 204 KB Output is correct
63 Correct 267 ms 8464 KB Output is correct
64 Correct 105 ms 11388 KB Output is correct
65 Correct 203 ms 8416 KB Output is correct
66 Correct 121 ms 11460 KB Output is correct
67 Correct 124 ms 11408 KB Output is correct
68 Correct 158 ms 11436 KB Output is correct
69 Correct 200 ms 8468 KB Output is correct
70 Execution timed out 1022 ms 11448 KB Time limit exceeded
71 Halted 0 ms 0 KB -