이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int a[1000010];
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(false);
int n,x,y,start;
cin>>n;
for(int i=0;i<n;i++){
cin>>x>>y;
a[i]=x-y;
if(a[i]>0 && !(a[i]&1)){
start=i;
}
}
queue<int> q;
q.push(start);
while(!q.empty()){
int f=q.front();
q.pop();
int temp=a[f];
int now=f;
while(temp!=0){
a[now]-=temp;
temp/=2;
now=(now+1)%n;
a[now]+=temp;
if(a[now]<=0) temp=0;
else if(a[now]&1){
temp=a[now]-1;
}
else{
temp=a[now];
}
if(temp==0){
for(int i=0;i<n;i++){
if(a[i]>0 && a[i]&1){
start=i;
}
q.push(start);
}
}
}
}
for(int i=1;i<=n;i++){
if(a[i]!=0){
cout<<"No";
}
}
cout<<"Yes";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |