이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
//#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int A[1000006],B[1000006],bal[1000006],n,r;
bool solve(int idx,int m){
if(idx==r){
if(!m)return 1;
return 0;
}
if(((bal[idx]+m) < 0) || ((m+bal[idx])&1))
return 0;
return solve((idx+1)%n,(m+bal[idx])>>1);
}
int32_t main(){
boost;
//freopen(".in","r",stdin);
cin>>n;
for (int i = 0; i < n; ++i){
cin>>A[i]>>B[i];
bal[i]=A[i]-B[i];
}
for (int i = 0; i < n; ++i)
if((bal[i]>=0) && !(bal[i]&1)){
r=i;
if(solve((i+1)%n,bal[i]/2)){
cout<<"Yes\n";
return 0;
}
}
cout<<"No\n";
return 0;
}
//do smth instead of nothing and stay organized
//long long
//array bounds
//special cases
//binary search
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |