#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define MAX_N 1000005
#define f first
#define s second
using namespace std;
typedef pair<int, int> ii;
long long A[MAX_N], B[MAX_N];
long long N;
void fastscan(int &number)
{
//variable to indicate sign of input number
bool negative = false;
register int c;
number = 0;
// extract current character from buffer
c = getchar();
if (c=='-')
{
// number is negative
negative = true;
// extract the next character from the buffer
c = getchar();
}
// Keep on extracting characters if they are integers
// i.e ASCII Value lies from '0'(48) to '9' (57)
for (; (c>47 && c<58); c=getchar())
number = number *10 + c - 48;
// if scanned input has a negative sign, negate the
// value of the input number
if (negative)
number *= -1;
}
void solve() {
cin >> N;
int a, b;
for (int i = 0; i < N; i ++) {
fastscan(a);
fastscan(b);
A[i] = a;
B[i] = b;
}
long long carry;
for (int ii = 0; ii < 10; ii ++) {
for (int i = 0; i < N; i ++) {
if (A[i] > B[i]) {
carry = ((A[i] - B[i]) / 2);
A[i] -= ((A[i] - B[i]) / 2) * 2;
A[(i + 1) % N] += carry;
}
}
}
bool flag = true;
for (int i = 0; i < N; i ++) {
flag = (flag && (A[i] == B[i]));
}
if (flag)
cout << ("Yes") << endl;
else {
bool flag2 = true;
for (int i = 0; i < N; i ++)
flag2 = (flag2 && (A[i] - 1 == B[i]));
for (int i = 0; i < N; i ++) {
if (A[i] > 1)
break;
if (i == N - 1)
flag2 = false;
}
cout << (flag2 ? "Yes" : "No") << endl;
}
return;
}
int main() {
int T;
T = 1;
for (int i = 0; i < T; i ++) {
solve();
}
return (0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |