이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2")
#pragma GCC optimize("unroll-loops,O3")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 1e6+20,mod = 1e9+7,inf = 1e9+10;
inline int mkay(int a,int b){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int a,int k){
if (k < 0) return 0;
int z = 1;
while (k){
if (k&1) z = 1ll*z*a%mod;
a = 1ll*a*a%mod;
k /= 2;
}
return z;
}
int a[N],b[N],n,x[N],j;
int nxt(int i){
return ((i == n-1) ? 0 : i+1);
}
bool check(int val){
x[j] = val;
int cur = j;
do{
int k = nxt(cur);
if (k == j) break;
if ((a[cur]-b[cur]+x[cur])%2 || a[cur]-b[cur] < -x[cur]){
return 0;
}
x[k] = (a[cur]-b[cur]-x[cur])/2;
cur = k;
}while (1);
return 1;
}
int main(){
ios_base :: sync_with_stdio(0); cin.tie(0);
cin >> n;
ll s = 0;
int mx = -1;
rep(i,0,n){
cin >> a[i] >> b[i];
s += a[i]-b[i];
if (a[i]-b[i] > mx){
j = i;
mx = a[i]-b[i];
}
}
if (s < 0){
cout << "No";
return 0;
}
rep(i,0,6) if (check(i)){
cout << "Yes";
return 0;
}
cout << "No";
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... |