Submission #666175

# Submission time Handle Problem Language Result Execution time Memory
666175 2022-11-27T16:50:03 Z ParsaS Remittance (JOI19_remittance) C++17
100 / 100
255 ms 52124 KB
// In the name of God
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
#define int ll
const int N = 1e6 + 5;
const int MOD = 2e9 + 11;
int pw[N], d[N], A[N], B[N], x[N];

int binpow(int a, int b) {
    return b ? 1LL * binpow(1LL * a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1;
}
void solve() {
    pw[0] = 1;
    for (int i = 1; i < N; i++)
        pw[i] = 2LL * pw[i - 1] % MOD;
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        A[i] = a, B[i] = b;
        d[i] = a - b;
    }
    int r = 1LL * pw[n - 1] * (d[0] + MOD) % MOD;
    for (int i = 1; i < n; i++) {
        r = (r + 1LL * pw[i - 1] * (1LL * d[i] + MOD) % MOD) % MOD;
    }
    r = 1LL * r * binpow(pw[n] - 1, MOD - 2) % MOD;
    bool ok = true;
    x[0] = r;
    for (int i = 1; i < n; i++) {
        x[i] = (x[i - 1] + d[i]) / 2;
    }
    for (int i = 0; i < n; i++) {
        int j = (i + n - 1) % n;
        ok &= x[i] >= 0 && A[i] - B[i] == 2 * x[i] - x[j];
    }
    bool f = false;
    for (int k = 0; k < 5 && !f; k++) {
        for (int i = 0; i < n; i++) {
            int c = min(A[i] / 2, x[i]);
            A[i] -= 2 * c, x[i] -= c;
            A[(i + 1) % n] += c;
            if (x[i] == 0) {
                f = true;
                break;
            }
        }
    }
    int st = 0;
    for (st; st < n && x[st] > 0; st++);
    ok &= st < n;
    for (int i = (st + 1) % n; ok && i != st; i = (i + 1) % n) {
        ok &= A[i] / 2 >= x[i];
        A[i] -= x[i] * 2;
        A[(i + 1) % n] += x[i];
    }
    cout << (ok ? "Yes" : "No") << '\n';

}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    solve();

    return 0;
}

Compilation message

remittance.cpp: In function 'void solve()':
remittance.cpp:54:10: warning: statement has no effect [-Wunused-value]
   54 |     for (st; st < n && x[st] > 0; st++);
      |          ^~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8148 KB Output is correct
2 Correct 8 ms 8084 KB Output is correct
3 Correct 8 ms 8148 KB Output is correct
4 Correct 7 ms 8152 KB Output is correct
5 Correct 7 ms 8156 KB Output is correct
6 Correct 7 ms 8164 KB Output is correct
7 Correct 8 ms 8124 KB Output is correct
8 Correct 7 ms 8144 KB Output is correct
9 Correct 7 ms 8148 KB Output is correct
10 Correct 7 ms 8148 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 9 ms 8148 KB Output is correct
13 Correct 8 ms 8152 KB Output is correct
14 Correct 8 ms 8156 KB Output is correct
15 Correct 9 ms 8152 KB Output is correct
16 Correct 9 ms 8276 KB Output is correct
17 Correct 9 ms 8156 KB Output is correct
18 Correct 7 ms 8148 KB Output is correct
19 Correct 7 ms 8140 KB Output is correct
20 Correct 7 ms 8148 KB Output is correct
21 Correct 7 ms 8132 KB Output is correct
22 Correct 7 ms 8148 KB Output is correct
23 Correct 7 ms 8144 KB Output is correct
24 Correct 7 ms 8160 KB Output is correct
25 Correct 7 ms 8148 KB Output is correct
26 Correct 8 ms 8148 KB Output is correct
27 Correct 8 ms 8148 KB Output is correct
28 Correct 7 ms 8144 KB Output is correct
29 Correct 9 ms 8164 KB Output is correct
30 Correct 8 ms 8156 KB Output is correct
31 Correct 7 ms 8148 KB Output is correct
32 Correct 8 ms 8076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8148 KB Output is correct
2 Correct 8 ms 8084 KB Output is correct
3 Correct 8 ms 8148 KB Output is correct
4 Correct 7 ms 8152 KB Output is correct
5 Correct 7 ms 8156 KB Output is correct
6 Correct 7 ms 8164 KB Output is correct
7 Correct 8 ms 8124 KB Output is correct
8 Correct 7 ms 8144 KB Output is correct
9 Correct 7 ms 8148 KB Output is correct
10 Correct 7 ms 8148 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 9 ms 8148 KB Output is correct
13 Correct 8 ms 8152 KB Output is correct
14 Correct 8 ms 8156 KB Output is correct
15 Correct 9 ms 8152 KB Output is correct
16 Correct 9 ms 8276 KB Output is correct
17 Correct 9 ms 8156 KB Output is correct
18 Correct 7 ms 8148 KB Output is correct
19 Correct 7 ms 8140 KB Output is correct
20 Correct 7 ms 8148 KB Output is correct
21 Correct 7 ms 8132 KB Output is correct
22 Correct 7 ms 8148 KB Output is correct
23 Correct 7 ms 8144 KB Output is correct
24 Correct 7 ms 8160 KB Output is correct
25 Correct 7 ms 8148 KB Output is correct
26 Correct 8 ms 8148 KB Output is correct
27 Correct 8 ms 8148 KB Output is correct
28 Correct 7 ms 8144 KB Output is correct
29 Correct 9 ms 8164 KB Output is correct
30 Correct 8 ms 8156 KB Output is correct
31 Correct 7 ms 8148 KB Output is correct
32 Correct 8 ms 8076 KB Output is correct
33 Correct 8 ms 8148 KB Output is correct
34 Correct 7 ms 8120 KB Output is correct
35 Correct 8 ms 8108 KB Output is correct
36 Correct 8 ms 8148 KB Output is correct
37 Correct 8 ms 8148 KB Output is correct
38 Correct 7 ms 8148 KB Output is correct
39 Correct 8 ms 8148 KB Output is correct
40 Correct 7 ms 8148 KB Output is correct
41 Correct 7 ms 8156 KB Output is correct
42 Correct 7 ms 8152 KB Output is correct
43 Correct 8 ms 8116 KB Output is correct
44 Correct 9 ms 8148 KB Output is correct
45 Correct 9 ms 8152 KB Output is correct
46 Correct 8 ms 8148 KB Output is correct
47 Correct 8 ms 8104 KB Output is correct
48 Correct 7 ms 8132 KB Output is correct
49 Correct 8 ms 8148 KB Output is correct
50 Correct 7 ms 8148 KB Output is correct
51 Correct 7 ms 8148 KB Output is correct
52 Correct 8 ms 8148 KB Output is correct
53 Correct 9 ms 8164 KB Output is correct
54 Correct 7 ms 8152 KB Output is correct
55 Correct 7 ms 8068 KB Output is correct
56 Correct 8 ms 8152 KB Output is correct
57 Correct 9 ms 8148 KB Output is correct
58 Correct 8 ms 8124 KB Output is correct
59 Correct 9 ms 8152 KB Output is correct
60 Correct 9 ms 8148 KB Output is correct
61 Correct 8 ms 8148 KB Output is correct
62 Correct 8 ms 8124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8148 KB Output is correct
2 Correct 8 ms 8084 KB Output is correct
3 Correct 8 ms 8148 KB Output is correct
4 Correct 7 ms 8152 KB Output is correct
5 Correct 7 ms 8156 KB Output is correct
6 Correct 7 ms 8164 KB Output is correct
7 Correct 8 ms 8124 KB Output is correct
8 Correct 7 ms 8144 KB Output is correct
9 Correct 7 ms 8148 KB Output is correct
10 Correct 7 ms 8148 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 9 ms 8148 KB Output is correct
13 Correct 8 ms 8152 KB Output is correct
14 Correct 8 ms 8156 KB Output is correct
15 Correct 9 ms 8152 KB Output is correct
16 Correct 9 ms 8276 KB Output is correct
17 Correct 9 ms 8156 KB Output is correct
18 Correct 7 ms 8148 KB Output is correct
19 Correct 7 ms 8140 KB Output is correct
20 Correct 7 ms 8148 KB Output is correct
21 Correct 7 ms 8132 KB Output is correct
22 Correct 7 ms 8148 KB Output is correct
23 Correct 7 ms 8144 KB Output is correct
24 Correct 7 ms 8160 KB Output is correct
25 Correct 7 ms 8148 KB Output is correct
26 Correct 8 ms 8148 KB Output is correct
27 Correct 8 ms 8148 KB Output is correct
28 Correct 7 ms 8144 KB Output is correct
29 Correct 9 ms 8164 KB Output is correct
30 Correct 8 ms 8156 KB Output is correct
31 Correct 7 ms 8148 KB Output is correct
32 Correct 8 ms 8076 KB Output is correct
33 Correct 8 ms 8148 KB Output is correct
34 Correct 7 ms 8120 KB Output is correct
35 Correct 8 ms 8108 KB Output is correct
36 Correct 8 ms 8148 KB Output is correct
37 Correct 8 ms 8148 KB Output is correct
38 Correct 7 ms 8148 KB Output is correct
39 Correct 8 ms 8148 KB Output is correct
40 Correct 7 ms 8148 KB Output is correct
41 Correct 7 ms 8156 KB Output is correct
42 Correct 7 ms 8152 KB Output is correct
43 Correct 8 ms 8116 KB Output is correct
44 Correct 9 ms 8148 KB Output is correct
45 Correct 9 ms 8152 KB Output is correct
46 Correct 8 ms 8148 KB Output is correct
47 Correct 8 ms 8104 KB Output is correct
48 Correct 7 ms 8132 KB Output is correct
49 Correct 8 ms 8148 KB Output is correct
50 Correct 7 ms 8148 KB Output is correct
51 Correct 7 ms 8148 KB Output is correct
52 Correct 8 ms 8148 KB Output is correct
53 Correct 9 ms 8164 KB Output is correct
54 Correct 7 ms 8152 KB Output is correct
55 Correct 7 ms 8068 KB Output is correct
56 Correct 8 ms 8152 KB Output is correct
57 Correct 9 ms 8148 KB Output is correct
58 Correct 8 ms 8124 KB Output is correct
59 Correct 9 ms 8152 KB Output is correct
60 Correct 9 ms 8148 KB Output is correct
61 Correct 8 ms 8148 KB Output is correct
62 Correct 8 ms 8124 KB Output is correct
63 Correct 212 ms 40972 KB Output is correct
64 Correct 150 ms 43352 KB Output is correct
65 Correct 255 ms 41576 KB Output is correct
66 Correct 123 ms 43340 KB Output is correct
67 Correct 150 ms 44736 KB Output is correct
68 Correct 149 ms 47168 KB Output is correct
69 Correct 251 ms 40932 KB Output is correct
70 Correct 116 ms 43304 KB Output is correct
71 Correct 127 ms 44628 KB Output is correct
72 Correct 147 ms 47172 KB Output is correct
73 Correct 219 ms 41028 KB Output is correct
74 Correct 120 ms 43324 KB Output is correct
75 Correct 129 ms 44796 KB Output is correct
76 Correct 143 ms 47052 KB Output is correct
77 Correct 240 ms 41588 KB Output is correct
78 Correct 192 ms 51048 KB Output is correct
79 Correct 165 ms 51068 KB Output is correct
80 Correct 191 ms 50988 KB Output is correct
81 Correct 190 ms 51016 KB Output is correct
82 Correct 134 ms 43336 KB Output is correct
83 Correct 114 ms 43336 KB Output is correct
84 Correct 116 ms 43240 KB Output is correct
85 Correct 252 ms 41616 KB Output is correct
86 Correct 234 ms 41676 KB Output is correct
87 Correct 204 ms 52040 KB Output is correct
88 Correct 223 ms 52124 KB Output is correct