#include <bits/stdc++.h>
#define INF 10000000000000000
#define MOD 1000000017
#define mid(l, u) ((l+u)/2)
#define rchild(i) (i*2 + 2)
#define lchild(i) (i*2 + 1)
#define int long long
using namespace std;
signed main(){
int n;
cin>>n;
int e[n];
for(int i =0 ;i<n;i++){
int a, b;
cin>>a>>b;
e[i] = (a-b);
}
int carry = 0;
int lastchange = 0;
int curriter = 0;
for(int i = 0;true;i++, i%=n){
int b = e[i];
//cout<<i<<" "<<b<<" "<<carry<<endl;
e[i]+=carry;
carry = max((int)0, e[i]);
if(carry%2) carry--;
e[i]-=carry;
carry/=2;
curriter++;
if(e[i]!=b) lastchange = curriter;
if((curriter - lastchange)>n) break;
}
bool diff = false;
for(int i = 0;i<n;i++) if(e[i]!=0) diff = true;
if(diff) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
//l, mid(l, r) || l+1, r
//
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
128 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
128 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
128 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |