Submission #489476

# Submission time Handle Problem Language Result Execution time Memory
489476 2021-11-23T03:20:11 Z 8e7 Remittance (JOI19_remittance) C++17
100 / 100
234 ms 52100 KB
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
void debug(){cout << endl;}
template<class T, class ...U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary (T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#define ll long long
#define maxn 1000005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
ll a[maxn], b[maxn], c[maxn], ans[maxn];
bool check(int n, ll num) {
	ans[n-1] = num;
	for (int i = 0;i < n - 1;i++) {
		if ((ans[(i+n-1)%n] - c[i]) % 2) return 0;
		ans[i] = (ans[(i+n-1)%n] - c[i]) / 2;
		//debug(i, ans[i]);
	}
	return (ans[n-2] - 2 * ans[n-1] == c[n-1]);
}
int main() {
	io
	int n;
	cin >> n;
	
	for (int i = 0;i < n;i++) {
		cin >> a[i] >> b[i];	
		c[i] = b[i] - a[i];
	}
	ll sum = 0, cnt = 0;
	ll cur = 1;
	for (int i = max(0, n - 30);i < n;i++) {
		sum += cur * c[i];
		cur *= 2;
	}
	ll val = (-sum) / (cur - 1);
	if (!check(n, val)) {
		if (!check(n, val - 1)) {
			check(n, val + 1);
		}
	}
	
	for (int i = 0;i < n;i++) {
		cnt += ans[i];
		if (ans[i] < 0) {
			cout << "No\n";
			return 0;
		}
	}
	cur = 0;
	ll prv = n-1;
	while (cnt > 0) {
		int dif = min(ans[cur], a[cur]/2);	
		ans[cur] -= dif, a[cur] -= dif*2;
		a[(cur+1)%n] += dif;	
		cnt -= dif;
		if (dif > 0) {
			prv = cur;
		} else if (cur == prv) {
			cout << "No\n";
			return 0;
		}
		cur = (cur + 1) % n;
	}
	for (int i = 0;i < n;i++) {
		if (a[i] != b[i]) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;

}
/*
5
0 0
1 0
2 3
3 3
4 0
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 0 ms 332 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 0 ms 332 KB Output is correct
41 Correct 0 ms 332 KB Output is correct
42 Correct 0 ms 332 KB Output is correct
43 Correct 0 ms 332 KB Output is correct
44 Correct 0 ms 332 KB Output is correct
45 Correct 0 ms 332 KB Output is correct
46 Correct 0 ms 332 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 0 ms 332 KB Output is correct
50 Correct 0 ms 332 KB Output is correct
51 Correct 0 ms 332 KB Output is correct
52 Correct 0 ms 332 KB Output is correct
53 Correct 0 ms 332 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 0 ms 332 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 0 ms 332 KB Output is correct
59 Correct 0 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 0 ms 332 KB Output is correct
62 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 0 ms 332 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 0 ms 332 KB Output is correct
41 Correct 0 ms 332 KB Output is correct
42 Correct 0 ms 332 KB Output is correct
43 Correct 0 ms 332 KB Output is correct
44 Correct 0 ms 332 KB Output is correct
45 Correct 0 ms 332 KB Output is correct
46 Correct 0 ms 332 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 0 ms 332 KB Output is correct
50 Correct 0 ms 332 KB Output is correct
51 Correct 0 ms 332 KB Output is correct
52 Correct 0 ms 332 KB Output is correct
53 Correct 0 ms 332 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 0 ms 332 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 0 ms 332 KB Output is correct
59 Correct 0 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 0 ms 332 KB Output is correct
62 Correct 0 ms 332 KB Output is correct
63 Correct 182 ms 25544 KB Output is correct
64 Correct 116 ms 35448 KB Output is correct
65 Correct 205 ms 50628 KB Output is correct
66 Correct 115 ms 35472 KB Output is correct
67 Correct 126 ms 36812 KB Output is correct
68 Correct 131 ms 39272 KB Output is correct
69 Correct 207 ms 50932 KB Output is correct
70 Correct 119 ms 35412 KB Output is correct
71 Correct 115 ms 36864 KB Output is correct
72 Correct 129 ms 39196 KB Output is correct
73 Correct 222 ms 50916 KB Output is correct
74 Correct 108 ms 35400 KB Output is correct
75 Correct 117 ms 36868 KB Output is correct
76 Correct 130 ms 39256 KB Output is correct
77 Correct 207 ms 51048 KB Output is correct
78 Correct 171 ms 43188 KB Output is correct
79 Correct 170 ms 43244 KB Output is correct
80 Correct 178 ms 43248 KB Output is correct
81 Correct 160 ms 43160 KB Output is correct
82 Correct 103 ms 35536 KB Output is correct
83 Correct 105 ms 35404 KB Output is correct
84 Correct 101 ms 35468 KB Output is correct
85 Correct 234 ms 52100 KB Output is correct
86 Correct 228 ms 52036 KB Output is correct
87 Correct 191 ms 44276 KB Output is correct
88 Correct 187 ms 44284 KB Output is correct