#include <iostream>
using namespace std;
int n, a[1000010], b[1000010], cnt;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
if (a[i] != b[i]) cnt++;
}
for (int i = 1; i <= 50; i++) {
if (cnt == 0) {
cout << "Yes" << endl;
return 0;
}
for (int j = 1; j < n; j++) {
if (a[j] > b[j]+1) {
if (a[j+1] == b[j+1]) cnt++;
a[j+1] += (a[j]-b[j])/2;
if (a[j+1] == b[j+1]) cnt--;
a[j] -= (a[j]-b[j])/2*2;
if (a[j] == b[j]) cnt--;
}
}
if (a[n] > b[n]+1) {
if (a[1] == b[1]) cnt++;
a[1] += (a[n]-b[n])/2;
if (a[1] == b[1]) cnt--;
a[n] -= (a[n]-b[n])/2*2;
if (a[n] == b[n]) cnt--;
}
/*for (int j = 1; j <= n; j++) cout << a[j] << " " << b[j] << endl;
cout << endl;*/
}
if (cnt == 0) cout << "Yes" << endl;
else cout << "No" << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2492 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2492 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2492 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |