#include <bits/stdc++.h>
#define va first
#define vb second
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
const int MN = 1e6+35;
const int MOD = 1e9+7;
const int INF = 1e9;
ll A[MN],B[MN],C[MN],F[MN],k[30];
void impos()
{
cout << "No";
exit(0);
}
int main()
{
#ifdef L0TUS
freopen("C:\\Users\\SKYPC364\\Documents\\Coding\\BOJ\\input.txt", "r", stdin);
freopen("C:\\Users\\SKYPC364\\Documents\\Coding\\BOJ\\output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0),cin.tie(0);
int N;
cin >> N;
for(int i=0; i<N; i++) cin >> A[i] >> B[i];
k[0] = 1;
for(int i=1; i<30; i++){
k[i] = k[i-1]*2;
}
for(int i=N-1; i>=0; i--){
for(int j=0; j<30; j++){
if((A[i]-B[i])&k[j]) F[i+j+1]++;
}
}
for(int i=N+29; i>=N; i--){
F[i-N] += F[i];
C[N-1] += F[i]*k[i-N];
F[i] = 0;
}
for(int t=0; t<30; t++){
for(int i=0; i<N; i++){
F[i+1] += F[i]/2;
F[i]%=2;
}
F[0] += F[N];
C[N-1] += F[N];
F[N] = 0;
}
for(int i=0; i<N; i++){
if(F[i]) impos();
}
if(C[N-1]<0||C[N-1]%2) impos();
for(int i=0; i<N-1; i++){
C[i] = A[i]-B[i]+C[(i+N-1)%N]/2;
if(C[i]<0||C[i]%2) impos();
}
for(int t=0; t<3; t++){
for(int i=0; i<N; i++){
ll x = min(C[i]/2,A[i]/2)*2;
A[i] -= x;
A[(i+1)%N] += x/2;
C[i] -= x;
}
}
for(int i=0; i<N; i++) if(A[i]!=B[i]) impos();
cout << "Yes";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |