이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
using namespace std;
#pragma GCC optimize ("Ofast")
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
typedef long long LL;
typedef pair<int,int> pii;
#define iter(x) x.begin(),x.end()
#define pb push_back
#define mkp make_pair
#define F first
#define S second
#define REP(n) for (int __=n;__--;)
#define REP0(i,n) for (int i=0;i<n;++i)
#define REP1(i,n) for (int i=1;i<=n;++i)
const int maxn = 1e6+10,mod = 0;
const LL inf = 0;
int a[maxn],n;
bool done(){
REP1(i,n) if (a[i]) return false;
return true;
}
bool pos(){
REP1(i,n) if (a[i] > 0) return true;
return false;
}
void solve(){
cin >> n;
REP1(i,n){
int k;
cin >> a[i] >> k;
a[i] -= k;
}
while (!done()){
//REP1(i,n) cerr << a[i] <<' '; cerr << '\n';
if (!pos()){
cout << "No\n";
return;
}
for (int i=1;i<n;++i){
if (a[i] > 0){
a[i+1] += (a[i] + 1) >> 1;
a[i] -= ((a[i] + 1) >> 1) << 1;
}
}
if (a[n] > 0){
a[1] += (a[n] + 1) >> 1;
a[n] -= ((a[n] + 1) >> 1) << 1;
}
//REP1(i,n) cerr << a[i] <<' '; cerr << '\n';
}
cout << "Yes\n";
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
solve();
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... |