# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
223584 | 2020-04-15T14:05:31 Z | spacewalker | 송금 (JOI19_remittance) | C++14 | 544 ms | 114908 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; // if X, the next number will be // 2X - peak vector<ll> canonBinary(vector<ll> &arr) { vector<ll> ans = arr; for (int i = 0; i < 40; ++i) ans.push_back(0); for (int i = 0; i + 1 < ans.size(); ++i) { ans[i + 1] += ans[i] / 2; ans[i] %= 2; } return ans; } void answer(bool yn) { if (yn) printf("Yes\n"); else printf("No\n"); exit(0); } ll tryDivide(vector<ll> digs, ll n) { // Attempts to return digs / (2 ^ n - 1), returns -1 if that is not an integer // NUMBERS HERE ARE MOST SIGNIFICANT FIRST vector<ll> curRem; int curRemDigitSum = 0; vector<ll> ans; for (int d : digs) { if (curRem.empty() && d == 0) { ans.push_back(0); continue; } curRem.push_back(d); curRemDigitSum += d; if (curRem.size() < n || (curRem.size() == n && curRemDigitSum < n)) { // printf("zero added\n"); ans.push_back(0); } else { ans.push_back(1); // update curRem to be curRem - (2 ^ n - 1) // printf("DIVIDE INITIATED:\n"); // for (int x : curRem) printf("%d", x); // printf("\n"); fflush(stdout); if (curRem.size() == n) { curRem.clear(); curRemDigitSum = 0; } else { for (int i = 1; i <= n; ++i) curRem[i] -= 1; int recentOne = -1; for (int i = 0; i <= n; ++i) { if (curRem[i] == 1) recentOne = i; else if (curRem[i] == -1) { curRem[recentOne] = 0; for (int j = recentOne + 1; j <= i; ++j) { curRem[j] = 1; } recentOne = i; } } int fone = -1; for (int i = 0; i <= n; ++i) { if (curRem[i] == 1) { fone = i; break; } } curRemDigitSum = 0; if (fone == -1) { curRem.clear(); } else { curRem = vector<ll>(begin(curRem) + fone, end(curRem)); for (int x : curRem) curRemDigitSum += x; } } } } if (curRemDigitSum == 0) { ll numerical = 0; for (int x : ans) numerical = 2 * numerical + x; return numerical; } else return -1; } int main() { int n; scanf("%d", &n); vector<ll> before(n), after(n); for (int i = 0; i < n; ++i) scanf("%lld %lld", &before[i], &after[i]); ll sanity = 0; for (int i = 0; i < n; ++i) if (before[i] != after[i]) ++sanity; if (sanity == 0) answer(true); sanity = 0; for (int x : after) sanity += x; if (sanity == 0) answer(false); vector<ll> beforeConv = canonBinary(before), afterConv = canonBinary(after); vector<ll> difference(beforeConv.size(), 0); int diffLen = difference.size(); // for (int i = diffLen - 1; i >= 0; --i) printf("%lld", beforeConv[i]); // printf("\n"); // for (int i = diffLen - 1; i >= 0; --i) printf("%lld", afterConv[i]); // printf("\n"); for (int i = 0; i < diffLen; ++i) difference[i] = beforeConv[i] - afterConv[i]; // for (int i = diffLen - 1; i >= 0; --i) printf("%lld", difference[i]); // printf("\n"); bool earlyNegativeBreak = false; int recentOne = -1; for (int i = diffLen - 1; i >= 0; --i) { if (difference[i] == 1) recentOne = i; else if (difference[i] == -1) { if (recentOne == -1) { earlyNegativeBreak = true; break; } else { for (int j = i; j < recentOne; ++j) difference[j] = 1; difference[recentOne] = 0; recentOne = i; } } } if (earlyNegativeBreak) { answer(false); } // for (int i = diffLen - 1; i >= 0; --i) printf("%lld", difference[i]); // printf("\n"); // fflush(stdout); reverse(begin(difference), end(difference)); // cast from little endian to big endian vector<ll> flows(n); flows[n-1] = tryDivide(difference, n); // flows[n-1] = (A + 2B + 4C + 8D + 16E) / 31 // flows[n-2] = (E + 2A + 4B + 8C + 16D) / 31 // 2a - b = A etc etc for (int i = n - 2; i >= 0; --i) flows[i] = 2*flows[i+1] - (before[i + 1] - after[i + 1]); // for (int i = 0; i < n; ++i) printf("%d flow %lld\n", i, flows[i]); for (int i = 0; i < n; ++i) if (flows[i] < 0) answer(false); answer(true); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 256 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 256 KB | Output is correct |
11 | Correct | 5 ms | 256 KB | Output is correct |
12 | Correct | 5 ms | 256 KB | Output is correct |
13 | Correct | 4 ms | 256 KB | Output is correct |
14 | Correct | 5 ms | 256 KB | Output is correct |
15 | Correct | 4 ms | 256 KB | Output is correct |
16 | Correct | 5 ms | 256 KB | Output is correct |
17 | Correct | 4 ms | 256 KB | Output is correct |
18 | Correct | 5 ms | 256 KB | Output is correct |
19 | Correct | 4 ms | 256 KB | Output is correct |
20 | Correct | 4 ms | 256 KB | Output is correct |
21 | Correct | 5 ms | 256 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 5 ms | 256 KB | Output is correct |
24 | Correct | 5 ms | 256 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 4 ms | 384 KB | Output is correct |
27 | Correct | 5 ms | 256 KB | Output is correct |
28 | Correct | 5 ms | 384 KB | Output is correct |
29 | Correct | 5 ms | 256 KB | Output is correct |
30 | Correct | 5 ms | 384 KB | Output is correct |
31 | Correct | 5 ms | 384 KB | Output is correct |
32 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 256 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 256 KB | Output is correct |
11 | Correct | 5 ms | 256 KB | Output is correct |
12 | Correct | 5 ms | 256 KB | Output is correct |
13 | Correct | 4 ms | 256 KB | Output is correct |
14 | Correct | 5 ms | 256 KB | Output is correct |
15 | Correct | 4 ms | 256 KB | Output is correct |
16 | Correct | 5 ms | 256 KB | Output is correct |
17 | Correct | 4 ms | 256 KB | Output is correct |
18 | Correct | 5 ms | 256 KB | Output is correct |
19 | Correct | 4 ms | 256 KB | Output is correct |
20 | Correct | 4 ms | 256 KB | Output is correct |
21 | Correct | 5 ms | 256 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 5 ms | 256 KB | Output is correct |
24 | Correct | 5 ms | 256 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 4 ms | 384 KB | Output is correct |
27 | Correct | 5 ms | 256 KB | Output is correct |
28 | Correct | 5 ms | 384 KB | Output is correct |
29 | Correct | 5 ms | 256 KB | Output is correct |
30 | Correct | 5 ms | 384 KB | Output is correct |
31 | Correct | 5 ms | 384 KB | Output is correct |
32 | Correct | 5 ms | 384 KB | Output is correct |
33 | Correct | 5 ms | 384 KB | Output is correct |
34 | Correct | 5 ms | 384 KB | Output is correct |
35 | Correct | 5 ms | 384 KB | Output is correct |
36 | Correct | 5 ms | 256 KB | Output is correct |
37 | Correct | 5 ms | 256 KB | Output is correct |
38 | Correct | 5 ms | 256 KB | Output is correct |
39 | Correct | 5 ms | 256 KB | Output is correct |
40 | Correct | 5 ms | 256 KB | Output is correct |
41 | Correct | 4 ms | 256 KB | Output is correct |
42 | Correct | 5 ms | 384 KB | Output is correct |
43 | Correct | 4 ms | 384 KB | Output is correct |
44 | Correct | 5 ms | 384 KB | Output is correct |
45 | Correct | 5 ms | 384 KB | Output is correct |
46 | Correct | 5 ms | 256 KB | Output is correct |
47 | Correct | 5 ms | 384 KB | Output is correct |
48 | Correct | 5 ms | 256 KB | Output is correct |
49 | Correct | 4 ms | 256 KB | Output is correct |
50 | Correct | 5 ms | 256 KB | Output is correct |
51 | Correct | 5 ms | 384 KB | Output is correct |
52 | Correct | 4 ms | 256 KB | Output is correct |
53 | Correct | 5 ms | 384 KB | Output is correct |
54 | Correct | 5 ms | 256 KB | Output is correct |
55 | Correct | 5 ms | 384 KB | Output is correct |
56 | Correct | 5 ms | 256 KB | Output is correct |
57 | Correct | 5 ms | 384 KB | Output is correct |
58 | Correct | 4 ms | 256 KB | Output is correct |
59 | Correct | 4 ms | 256 KB | Output is correct |
60 | Correct | 5 ms | 288 KB | Output is correct |
61 | Correct | 5 ms | 256 KB | Output is correct |
62 | Correct | 5 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 256 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 256 KB | Output is correct |
11 | Correct | 5 ms | 256 KB | Output is correct |
12 | Correct | 5 ms | 256 KB | Output is correct |
13 | Correct | 4 ms | 256 KB | Output is correct |
14 | Correct | 5 ms | 256 KB | Output is correct |
15 | Correct | 4 ms | 256 KB | Output is correct |
16 | Correct | 5 ms | 256 KB | Output is correct |
17 | Correct | 4 ms | 256 KB | Output is correct |
18 | Correct | 5 ms | 256 KB | Output is correct |
19 | Correct | 4 ms | 256 KB | Output is correct |
20 | Correct | 4 ms | 256 KB | Output is correct |
21 | Correct | 5 ms | 256 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 5 ms | 256 KB | Output is correct |
24 | Correct | 5 ms | 256 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 4 ms | 384 KB | Output is correct |
27 | Correct | 5 ms | 256 KB | Output is correct |
28 | Correct | 5 ms | 384 KB | Output is correct |
29 | Correct | 5 ms | 256 KB | Output is correct |
30 | Correct | 5 ms | 384 KB | Output is correct |
31 | Correct | 5 ms | 384 KB | Output is correct |
32 | Correct | 5 ms | 384 KB | Output is correct |
33 | Correct | 5 ms | 384 KB | Output is correct |
34 | Correct | 5 ms | 384 KB | Output is correct |
35 | Correct | 5 ms | 384 KB | Output is correct |
36 | Correct | 5 ms | 256 KB | Output is correct |
37 | Correct | 5 ms | 256 KB | Output is correct |
38 | Correct | 5 ms | 256 KB | Output is correct |
39 | Correct | 5 ms | 256 KB | Output is correct |
40 | Correct | 5 ms | 256 KB | Output is correct |
41 | Correct | 4 ms | 256 KB | Output is correct |
42 | Correct | 5 ms | 384 KB | Output is correct |
43 | Correct | 4 ms | 384 KB | Output is correct |
44 | Correct | 5 ms | 384 KB | Output is correct |
45 | Correct | 5 ms | 384 KB | Output is correct |
46 | Correct | 5 ms | 256 KB | Output is correct |
47 | Correct | 5 ms | 384 KB | Output is correct |
48 | Correct | 5 ms | 256 KB | Output is correct |
49 | Correct | 4 ms | 256 KB | Output is correct |
50 | Correct | 5 ms | 256 KB | Output is correct |
51 | Correct | 5 ms | 384 KB | Output is correct |
52 | Correct | 4 ms | 256 KB | Output is correct |
53 | Correct | 5 ms | 384 KB | Output is correct |
54 | Correct | 5 ms | 256 KB | Output is correct |
55 | Correct | 5 ms | 384 KB | Output is correct |
56 | Correct | 5 ms | 256 KB | Output is correct |
57 | Correct | 5 ms | 384 KB | Output is correct |
58 | Correct | 4 ms | 256 KB | Output is correct |
59 | Correct | 4 ms | 256 KB | Output is correct |
60 | Correct | 5 ms | 288 KB | Output is correct |
61 | Correct | 5 ms | 256 KB | Output is correct |
62 | Correct | 5 ms | 256 KB | Output is correct |
63 | Correct | 392 ms | 39792 KB | Output is correct |
64 | Correct | 247 ms | 80612 KB | Output is correct |
65 | Correct | 544 ms | 113476 KB | Output is correct |
66 | Correct | 249 ms | 75112 KB | Output is correct |
67 | Correct | 279 ms | 92264 KB | Output is correct |
68 | Correct | 317 ms | 89444 KB | Output is correct |
69 | Correct | 527 ms | 101220 KB | Output is correct |
70 | Correct | 242 ms | 80612 KB | Output is correct |
71 | Correct | 264 ms | 81892 KB | Output is correct |
72 | Correct | 319 ms | 94296 KB | Output is correct |
73 | Correct | 516 ms | 113776 KB | Output is correct |
74 | Correct | 246 ms | 80544 KB | Output is correct |
75 | Correct | 261 ms | 81892 KB | Output is correct |
76 | Correct | 327 ms | 94692 KB | Output is correct |
77 | Correct | 503 ms | 113720 KB | Output is correct |
78 | Correct | 261 ms | 27640 KB | Output is correct |
79 | Correct | 268 ms | 27644 KB | Output is correct |
80 | Correct | 394 ms | 105908 KB | Output is correct |
81 | Correct | 448 ms | 105904 KB | Output is correct |
82 | Correct | 165 ms | 19960 KB | Output is correct |
83 | Correct | 199 ms | 43520 KB | Output is correct |
84 | Correct | 183 ms | 19960 KB | Output is correct |
85 | Correct | 509 ms | 114908 KB | Output is correct |
86 | Correct | 479 ms | 114716 KB | Output is correct |
87 | Correct | 215 ms | 28920 KB | Output is correct |
88 | Correct | 381 ms | 94440 KB | Output is correct |