#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e6 + 9;
int n, nxt[N];
ll a[N], b[N];
bool check() {
ll ma = *max_element(a + 1, a + n + 1);
ll mi = *min_element(a + 1, a + n + 1);
if (ma != mi) return false;
if (ma == 0) return true;
if (ma == 1) return *max_element(b + 1, b + n + 1) > 0;
return false;
}
int main() {
cin.tie(NULL)->sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i] >> b[i], a[i] -= b[i], nxt[i] = i % n + 1;
for (int times = 0; times * n < 1e8; ++times)
for (int i = 1; i <= n; ++i)
if (a[i] > 0) {
ll tmp = a[i] >> 1;
a[i] -= tmp << 1;
a[nxt[i]] += tmp;
}
cout << (check() ? "Yes\n" : "No\n");
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
340 KB |
Output is correct |
2 |
Correct |
124 ms |
328 KB |
Output is correct |
3 |
Correct |
119 ms |
332 KB |
Output is correct |
4 |
Correct |
103 ms |
316 KB |
Output is correct |
5 |
Correct |
86 ms |
212 KB |
Output is correct |
6 |
Correct |
101 ms |
316 KB |
Output is correct |
7 |
Correct |
91 ms |
212 KB |
Output is correct |
8 |
Correct |
328 ms |
316 KB |
Output is correct |
9 |
Correct |
100 ms |
316 KB |
Output is correct |
10 |
Correct |
92 ms |
212 KB |
Output is correct |
11 |
Correct |
86 ms |
320 KB |
Output is correct |
12 |
Correct |
151 ms |
328 KB |
Output is correct |
13 |
Correct |
89 ms |
340 KB |
Output is correct |
14 |
Correct |
92 ms |
320 KB |
Output is correct |
15 |
Correct |
121 ms |
212 KB |
Output is correct |
16 |
Correct |
178 ms |
320 KB |
Output is correct |
17 |
Correct |
89 ms |
332 KB |
Output is correct |
18 |
Correct |
80 ms |
340 KB |
Output is correct |
19 |
Correct |
79 ms |
320 KB |
Output is correct |
20 |
Correct |
339 ms |
316 KB |
Output is correct |
21 |
Correct |
304 ms |
320 KB |
Output is correct |
22 |
Correct |
88 ms |
320 KB |
Output is correct |
23 |
Correct |
282 ms |
320 KB |
Output is correct |
24 |
Correct |
329 ms |
340 KB |
Output is correct |
25 |
Correct |
106 ms |
340 KB |
Output is correct |
26 |
Correct |
325 ms |
320 KB |
Output is correct |
27 |
Correct |
100 ms |
320 KB |
Output is correct |
28 |
Correct |
93 ms |
340 KB |
Output is correct |
29 |
Correct |
331 ms |
340 KB |
Output is correct |
30 |
Correct |
106 ms |
340 KB |
Output is correct |
31 |
Correct |
323 ms |
324 KB |
Output is correct |
32 |
Correct |
336 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
340 KB |
Output is correct |
2 |
Correct |
124 ms |
328 KB |
Output is correct |
3 |
Correct |
119 ms |
332 KB |
Output is correct |
4 |
Correct |
103 ms |
316 KB |
Output is correct |
5 |
Correct |
86 ms |
212 KB |
Output is correct |
6 |
Correct |
101 ms |
316 KB |
Output is correct |
7 |
Correct |
91 ms |
212 KB |
Output is correct |
8 |
Correct |
328 ms |
316 KB |
Output is correct |
9 |
Correct |
100 ms |
316 KB |
Output is correct |
10 |
Correct |
92 ms |
212 KB |
Output is correct |
11 |
Correct |
86 ms |
320 KB |
Output is correct |
12 |
Correct |
151 ms |
328 KB |
Output is correct |
13 |
Correct |
89 ms |
340 KB |
Output is correct |
14 |
Correct |
92 ms |
320 KB |
Output is correct |
15 |
Correct |
121 ms |
212 KB |
Output is correct |
16 |
Correct |
178 ms |
320 KB |
Output is correct |
17 |
Correct |
89 ms |
332 KB |
Output is correct |
18 |
Correct |
80 ms |
340 KB |
Output is correct |
19 |
Correct |
79 ms |
320 KB |
Output is correct |
20 |
Correct |
339 ms |
316 KB |
Output is correct |
21 |
Correct |
304 ms |
320 KB |
Output is correct |
22 |
Correct |
88 ms |
320 KB |
Output is correct |
23 |
Correct |
282 ms |
320 KB |
Output is correct |
24 |
Correct |
329 ms |
340 KB |
Output is correct |
25 |
Correct |
106 ms |
340 KB |
Output is correct |
26 |
Correct |
325 ms |
320 KB |
Output is correct |
27 |
Correct |
100 ms |
320 KB |
Output is correct |
28 |
Correct |
93 ms |
340 KB |
Output is correct |
29 |
Correct |
331 ms |
340 KB |
Output is correct |
30 |
Correct |
106 ms |
340 KB |
Output is correct |
31 |
Correct |
323 ms |
324 KB |
Output is correct |
32 |
Correct |
336 ms |
340 KB |
Output is correct |
33 |
Correct |
119 ms |
340 KB |
Output is correct |
34 |
Correct |
123 ms |
332 KB |
Output is correct |
35 |
Correct |
124 ms |
340 KB |
Output is correct |
36 |
Correct |
327 ms |
340 KB |
Output is correct |
37 |
Correct |
330 ms |
316 KB |
Output is correct |
38 |
Correct |
310 ms |
340 KB |
Output is correct |
39 |
Correct |
333 ms |
320 KB |
Output is correct |
40 |
Correct |
321 ms |
340 KB |
Output is correct |
41 |
Correct |
116 ms |
212 KB |
Output is correct |
42 |
Correct |
166 ms |
332 KB |
Output is correct |
43 |
Correct |
112 ms |
320 KB |
Output is correct |
44 |
Correct |
182 ms |
212 KB |
Output is correct |
45 |
Correct |
186 ms |
340 KB |
Output is correct |
46 |
Correct |
102 ms |
340 KB |
Output is correct |
47 |
Correct |
244 ms |
340 KB |
Output is correct |
48 |
Correct |
145 ms |
340 KB |
Output is correct |
49 |
Correct |
111 ms |
340 KB |
Output is correct |
50 |
Correct |
300 ms |
340 KB |
Output is correct |
51 |
Correct |
309 ms |
340 KB |
Output is correct |
52 |
Correct |
161 ms |
324 KB |
Output is correct |
53 |
Correct |
306 ms |
340 KB |
Output is correct |
54 |
Correct |
323 ms |
340 KB |
Output is correct |
55 |
Correct |
294 ms |
320 KB |
Output is correct |
56 |
Correct |
306 ms |
340 KB |
Output is correct |
57 |
Correct |
120 ms |
340 KB |
Output is correct |
58 |
Correct |
136 ms |
444 KB |
Output is correct |
59 |
Correct |
309 ms |
320 KB |
Output is correct |
60 |
Correct |
317 ms |
340 KB |
Output is correct |
61 |
Correct |
303 ms |
332 KB |
Output is correct |
62 |
Correct |
321 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
340 KB |
Output is correct |
2 |
Correct |
124 ms |
328 KB |
Output is correct |
3 |
Correct |
119 ms |
332 KB |
Output is correct |
4 |
Correct |
103 ms |
316 KB |
Output is correct |
5 |
Correct |
86 ms |
212 KB |
Output is correct |
6 |
Correct |
101 ms |
316 KB |
Output is correct |
7 |
Correct |
91 ms |
212 KB |
Output is correct |
8 |
Correct |
328 ms |
316 KB |
Output is correct |
9 |
Correct |
100 ms |
316 KB |
Output is correct |
10 |
Correct |
92 ms |
212 KB |
Output is correct |
11 |
Correct |
86 ms |
320 KB |
Output is correct |
12 |
Correct |
151 ms |
328 KB |
Output is correct |
13 |
Correct |
89 ms |
340 KB |
Output is correct |
14 |
Correct |
92 ms |
320 KB |
Output is correct |
15 |
Correct |
121 ms |
212 KB |
Output is correct |
16 |
Correct |
178 ms |
320 KB |
Output is correct |
17 |
Correct |
89 ms |
332 KB |
Output is correct |
18 |
Correct |
80 ms |
340 KB |
Output is correct |
19 |
Correct |
79 ms |
320 KB |
Output is correct |
20 |
Correct |
339 ms |
316 KB |
Output is correct |
21 |
Correct |
304 ms |
320 KB |
Output is correct |
22 |
Correct |
88 ms |
320 KB |
Output is correct |
23 |
Correct |
282 ms |
320 KB |
Output is correct |
24 |
Correct |
329 ms |
340 KB |
Output is correct |
25 |
Correct |
106 ms |
340 KB |
Output is correct |
26 |
Correct |
325 ms |
320 KB |
Output is correct |
27 |
Correct |
100 ms |
320 KB |
Output is correct |
28 |
Correct |
93 ms |
340 KB |
Output is correct |
29 |
Correct |
331 ms |
340 KB |
Output is correct |
30 |
Correct |
106 ms |
340 KB |
Output is correct |
31 |
Correct |
323 ms |
324 KB |
Output is correct |
32 |
Correct |
336 ms |
340 KB |
Output is correct |
33 |
Correct |
119 ms |
340 KB |
Output is correct |
34 |
Correct |
123 ms |
332 KB |
Output is correct |
35 |
Correct |
124 ms |
340 KB |
Output is correct |
36 |
Correct |
327 ms |
340 KB |
Output is correct |
37 |
Correct |
330 ms |
316 KB |
Output is correct |
38 |
Correct |
310 ms |
340 KB |
Output is correct |
39 |
Correct |
333 ms |
320 KB |
Output is correct |
40 |
Correct |
321 ms |
340 KB |
Output is correct |
41 |
Correct |
116 ms |
212 KB |
Output is correct |
42 |
Correct |
166 ms |
332 KB |
Output is correct |
43 |
Correct |
112 ms |
320 KB |
Output is correct |
44 |
Correct |
182 ms |
212 KB |
Output is correct |
45 |
Correct |
186 ms |
340 KB |
Output is correct |
46 |
Correct |
102 ms |
340 KB |
Output is correct |
47 |
Correct |
244 ms |
340 KB |
Output is correct |
48 |
Correct |
145 ms |
340 KB |
Output is correct |
49 |
Correct |
111 ms |
340 KB |
Output is correct |
50 |
Correct |
300 ms |
340 KB |
Output is correct |
51 |
Correct |
309 ms |
340 KB |
Output is correct |
52 |
Correct |
161 ms |
324 KB |
Output is correct |
53 |
Correct |
306 ms |
340 KB |
Output is correct |
54 |
Correct |
323 ms |
340 KB |
Output is correct |
55 |
Correct |
294 ms |
320 KB |
Output is correct |
56 |
Correct |
306 ms |
340 KB |
Output is correct |
57 |
Correct |
120 ms |
340 KB |
Output is correct |
58 |
Correct |
136 ms |
444 KB |
Output is correct |
59 |
Correct |
309 ms |
320 KB |
Output is correct |
60 |
Correct |
317 ms |
340 KB |
Output is correct |
61 |
Correct |
303 ms |
332 KB |
Output is correct |
62 |
Correct |
321 ms |
340 KB |
Output is correct |
63 |
Correct |
667 ms |
39172 KB |
Output is correct |
64 |
Correct |
208 ms |
23680 KB |
Output is correct |
65 |
Correct |
545 ms |
38836 KB |
Output is correct |
66 |
Correct |
190 ms |
23784 KB |
Output is correct |
67 |
Correct |
209 ms |
25236 KB |
Output is correct |
68 |
Correct |
215 ms |
27532 KB |
Output is correct |
69 |
Correct |
563 ms |
39300 KB |
Output is correct |
70 |
Correct |
207 ms |
23784 KB |
Output is correct |
71 |
Correct |
215 ms |
25164 KB |
Output is correct |
72 |
Correct |
213 ms |
27528 KB |
Output is correct |
73 |
Correct |
530 ms |
39232 KB |
Output is correct |
74 |
Correct |
202 ms |
23772 KB |
Output is correct |
75 |
Correct |
229 ms |
25160 KB |
Output is correct |
76 |
Correct |
206 ms |
27488 KB |
Output is correct |
77 |
Correct |
328 ms |
39268 KB |
Output is correct |
78 |
Correct |
462 ms |
31568 KB |
Output is correct |
79 |
Correct |
508 ms |
31476 KB |
Output is correct |
80 |
Correct |
517 ms |
31404 KB |
Output is correct |
81 |
Correct |
226 ms |
31436 KB |
Output is correct |
82 |
Correct |
443 ms |
23716 KB |
Output is correct |
83 |
Correct |
168 ms |
23732 KB |
Output is correct |
84 |
Correct |
173 ms |
23784 KB |
Output is correct |
85 |
Correct |
596 ms |
40372 KB |
Output is correct |
86 |
Correct |
563 ms |
40276 KB |
Output is correct |
87 |
Correct |
545 ms |
32644 KB |
Output is correct |
88 |
Correct |
547 ms |
32564 KB |
Output is correct |