이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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
//
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |