/*
Author: AquaBlaze
Keqing best girl :)
Nephren will always be in my heart
*/
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define ROF(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())
#define pc(x) putchar(x)
#define MP make_pair
#define MT make_tuple
using namespace std;
typedef long long i64;
typedef tuple<int,int,int> iii;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int N = 1000003, lg = 30;
int mod3 = 1000000021;
int mod2 = 1000000009;
int mod = 1000000007;
int n;
i64 rem[N];
i64 x[N];
i64 pw(i64 a, i64 b){
i64 ans = 1, res = a;
for(i64 i = 1; i <= b; i<<=1, res=res*res%mod){
if(i&b) ans = ans*res%mod;
}
return ans;
}
i64 A[N], B[N];
i64 tA[N], tB[N];
bool check(){
memset(x, 0, sizeof x);
i64 p2 = 1;
FOR(i, 0, n-1){
x[0] = (x[0]+rem[i]*p2)%mod;
p2 = p2*2%mod;
}
if(x[0]<0) x[0]+=mod;
p2 = (1-p2)%mod+mod;
p2 %= mod;
p2 = pw(p2, mod-2);
x[0] = x[0]*p2%mod;
//printf("%lld\n",x[0]);
FOR(i, 1, n-1){
x[i] = x[i-1]-rem[i-1];
//printf("%lld\n",x[i]);
if(x[i] < 0 || x[i]%2!=0){
return false;
}
x[i] /= 2;
}
// check correctness
FOR(i, 0, n-1){
if(x[i]-2*x[(i+1)%n] != rem[i]){
return false;
}
}
// ok
FOR(i, 0, n-1){
if(B[i] != 0){
return true;
}
}
return false;
}
void solve(){
cin >> n;
FOR(i, 0, n-1){
i64 a, b;
cin >> a >> b;
tA[i] = A[i] = a;
tB[i] = B[i] = b;
rem[i] = b-a;
}
bool eq = true;
FOR(i, 0, n-1){
if(A[i] != B[i]){
eq = false; break;
}
}
if(eq){
puts("Yes"); return;
}
if(check()){
puts("Yes"); return;
}
FOR(i, 0, n-1) A[i] = tA[i], B[i] = tB[i];
mod = mod2;
if(check()){
puts("Yes"); return;
}
FOR(i, 0, n-1) A[i] = tA[i], B[i] = tB[i];
mod = mod3;
if(check()){
puts("Yes"); return;
}
puts("No");
}
int main(){
solve();
return 0;
}
/*
*
*
*
*
*
*
*
*
*
*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8172 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
5 ms |
8172 KB |
Output is correct |
5 |
Correct |
5 ms |
8172 KB |
Output is correct |
6 |
Correct |
5 ms |
8172 KB |
Output is correct |
7 |
Correct |
5 ms |
8172 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
5 ms |
8172 KB |
Output is correct |
10 |
Correct |
5 ms |
8172 KB |
Output is correct |
11 |
Correct |
5 ms |
8172 KB |
Output is correct |
12 |
Correct |
7 ms |
8172 KB |
Output is correct |
13 |
Correct |
7 ms |
8172 KB |
Output is correct |
14 |
Correct |
7 ms |
8172 KB |
Output is correct |
15 |
Correct |
7 ms |
8192 KB |
Output is correct |
16 |
Correct |
7 ms |
8172 KB |
Output is correct |
17 |
Correct |
7 ms |
8172 KB |
Output is correct |
18 |
Correct |
5 ms |
8172 KB |
Output is correct |
19 |
Correct |
7 ms |
8172 KB |
Output is correct |
20 |
Correct |
7 ms |
8172 KB |
Output is correct |
21 |
Correct |
7 ms |
8172 KB |
Output is correct |
22 |
Correct |
7 ms |
8172 KB |
Output is correct |
23 |
Correct |
7 ms |
8172 KB |
Output is correct |
24 |
Correct |
5 ms |
8172 KB |
Output is correct |
25 |
Correct |
7 ms |
8192 KB |
Output is correct |
26 |
Correct |
7 ms |
8172 KB |
Output is correct |
27 |
Correct |
8 ms |
8172 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
5 ms |
8172 KB |
Output is correct |
30 |
Correct |
7 ms |
8172 KB |
Output is correct |
31 |
Correct |
7 ms |
8172 KB |
Output is correct |
32 |
Correct |
5 ms |
8172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8172 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
5 ms |
8172 KB |
Output is correct |
5 |
Correct |
5 ms |
8172 KB |
Output is correct |
6 |
Correct |
5 ms |
8172 KB |
Output is correct |
7 |
Correct |
5 ms |
8172 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
5 ms |
8172 KB |
Output is correct |
10 |
Correct |
5 ms |
8172 KB |
Output is correct |
11 |
Correct |
5 ms |
8172 KB |
Output is correct |
12 |
Correct |
7 ms |
8172 KB |
Output is correct |
13 |
Correct |
7 ms |
8172 KB |
Output is correct |
14 |
Correct |
7 ms |
8172 KB |
Output is correct |
15 |
Correct |
7 ms |
8192 KB |
Output is correct |
16 |
Correct |
7 ms |
8172 KB |
Output is correct |
17 |
Correct |
7 ms |
8172 KB |
Output is correct |
18 |
Correct |
5 ms |
8172 KB |
Output is correct |
19 |
Correct |
7 ms |
8172 KB |
Output is correct |
20 |
Correct |
7 ms |
8172 KB |
Output is correct |
21 |
Correct |
7 ms |
8172 KB |
Output is correct |
22 |
Correct |
7 ms |
8172 KB |
Output is correct |
23 |
Correct |
7 ms |
8172 KB |
Output is correct |
24 |
Correct |
5 ms |
8172 KB |
Output is correct |
25 |
Correct |
7 ms |
8192 KB |
Output is correct |
26 |
Correct |
7 ms |
8172 KB |
Output is correct |
27 |
Correct |
8 ms |
8172 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
5 ms |
8172 KB |
Output is correct |
30 |
Correct |
7 ms |
8172 KB |
Output is correct |
31 |
Correct |
7 ms |
8172 KB |
Output is correct |
32 |
Correct |
5 ms |
8172 KB |
Output is correct |
33 |
Correct |
7 ms |
8172 KB |
Output is correct |
34 |
Correct |
5 ms |
8192 KB |
Output is correct |
35 |
Correct |
5 ms |
8172 KB |
Output is correct |
36 |
Correct |
5 ms |
8172 KB |
Output is correct |
37 |
Correct |
6 ms |
8172 KB |
Output is correct |
38 |
Correct |
5 ms |
8172 KB |
Output is correct |
39 |
Correct |
5 ms |
8172 KB |
Output is correct |
40 |
Correct |
5 ms |
8188 KB |
Output is correct |
41 |
Correct |
5 ms |
8172 KB |
Output is correct |
42 |
Correct |
7 ms |
8172 KB |
Output is correct |
43 |
Correct |
7 ms |
8172 KB |
Output is correct |
44 |
Correct |
7 ms |
8172 KB |
Output is correct |
45 |
Correct |
7 ms |
8172 KB |
Output is correct |
46 |
Correct |
7 ms |
8172 KB |
Output is correct |
47 |
Correct |
7 ms |
8172 KB |
Output is correct |
48 |
Correct |
7 ms |
8172 KB |
Output is correct |
49 |
Correct |
5 ms |
8172 KB |
Output is correct |
50 |
Correct |
7 ms |
8172 KB |
Output is correct |
51 |
Correct |
7 ms |
8172 KB |
Output is correct |
52 |
Correct |
7 ms |
8188 KB |
Output is correct |
53 |
Correct |
7 ms |
8172 KB |
Output is correct |
54 |
Correct |
5 ms |
8192 KB |
Output is correct |
55 |
Correct |
7 ms |
8172 KB |
Output is correct |
56 |
Correct |
7 ms |
8172 KB |
Output is correct |
57 |
Correct |
7 ms |
8172 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
5 ms |
8172 KB |
Output is correct |
60 |
Correct |
7 ms |
8172 KB |
Output is correct |
61 |
Correct |
7 ms |
8172 KB |
Output is correct |
62 |
Correct |
5 ms |
8172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8172 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
5 ms |
8172 KB |
Output is correct |
5 |
Correct |
5 ms |
8172 KB |
Output is correct |
6 |
Correct |
5 ms |
8172 KB |
Output is correct |
7 |
Correct |
5 ms |
8172 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
5 ms |
8172 KB |
Output is correct |
10 |
Correct |
5 ms |
8172 KB |
Output is correct |
11 |
Correct |
5 ms |
8172 KB |
Output is correct |
12 |
Correct |
7 ms |
8172 KB |
Output is correct |
13 |
Correct |
7 ms |
8172 KB |
Output is correct |
14 |
Correct |
7 ms |
8172 KB |
Output is correct |
15 |
Correct |
7 ms |
8192 KB |
Output is correct |
16 |
Correct |
7 ms |
8172 KB |
Output is correct |
17 |
Correct |
7 ms |
8172 KB |
Output is correct |
18 |
Correct |
5 ms |
8172 KB |
Output is correct |
19 |
Correct |
7 ms |
8172 KB |
Output is correct |
20 |
Correct |
7 ms |
8172 KB |
Output is correct |
21 |
Correct |
7 ms |
8172 KB |
Output is correct |
22 |
Correct |
7 ms |
8172 KB |
Output is correct |
23 |
Correct |
7 ms |
8172 KB |
Output is correct |
24 |
Correct |
5 ms |
8172 KB |
Output is correct |
25 |
Correct |
7 ms |
8192 KB |
Output is correct |
26 |
Correct |
7 ms |
8172 KB |
Output is correct |
27 |
Correct |
8 ms |
8172 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
5 ms |
8172 KB |
Output is correct |
30 |
Correct |
7 ms |
8172 KB |
Output is correct |
31 |
Correct |
7 ms |
8172 KB |
Output is correct |
32 |
Correct |
5 ms |
8172 KB |
Output is correct |
33 |
Correct |
7 ms |
8172 KB |
Output is correct |
34 |
Correct |
5 ms |
8192 KB |
Output is correct |
35 |
Correct |
5 ms |
8172 KB |
Output is correct |
36 |
Correct |
5 ms |
8172 KB |
Output is correct |
37 |
Correct |
6 ms |
8172 KB |
Output is correct |
38 |
Correct |
5 ms |
8172 KB |
Output is correct |
39 |
Correct |
5 ms |
8172 KB |
Output is correct |
40 |
Correct |
5 ms |
8188 KB |
Output is correct |
41 |
Correct |
5 ms |
8172 KB |
Output is correct |
42 |
Correct |
7 ms |
8172 KB |
Output is correct |
43 |
Correct |
7 ms |
8172 KB |
Output is correct |
44 |
Correct |
7 ms |
8172 KB |
Output is correct |
45 |
Correct |
7 ms |
8172 KB |
Output is correct |
46 |
Correct |
7 ms |
8172 KB |
Output is correct |
47 |
Correct |
7 ms |
8172 KB |
Output is correct |
48 |
Correct |
7 ms |
8172 KB |
Output is correct |
49 |
Correct |
5 ms |
8172 KB |
Output is correct |
50 |
Correct |
7 ms |
8172 KB |
Output is correct |
51 |
Correct |
7 ms |
8172 KB |
Output is correct |
52 |
Correct |
7 ms |
8188 KB |
Output is correct |
53 |
Correct |
7 ms |
8172 KB |
Output is correct |
54 |
Correct |
5 ms |
8192 KB |
Output is correct |
55 |
Correct |
7 ms |
8172 KB |
Output is correct |
56 |
Correct |
7 ms |
8172 KB |
Output is correct |
57 |
Correct |
7 ms |
8172 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
5 ms |
8172 KB |
Output is correct |
60 |
Correct |
7 ms |
8172 KB |
Output is correct |
61 |
Correct |
7 ms |
8172 KB |
Output is correct |
62 |
Correct |
5 ms |
8172 KB |
Output is correct |
63 |
Correct |
901 ms |
48772 KB |
Output is correct |
64 |
Correct |
380 ms |
51180 KB |
Output is correct |
65 |
Correct |
845 ms |
48748 KB |
Output is correct |
66 |
Correct |
371 ms |
51180 KB |
Output is correct |
67 |
Correct |
407 ms |
52588 KB |
Output is correct |
68 |
Correct |
500 ms |
54892 KB |
Output is correct |
69 |
Correct |
856 ms |
48700 KB |
Output is correct |
70 |
Correct |
388 ms |
51180 KB |
Output is correct |
71 |
Correct |
426 ms |
52588 KB |
Output is correct |
72 |
Correct |
512 ms |
55056 KB |
Output is correct |
73 |
Correct |
893 ms |
48748 KB |
Output is correct |
74 |
Correct |
389 ms |
51436 KB |
Output is correct |
75 |
Correct |
427 ms |
52640 KB |
Output is correct |
76 |
Correct |
521 ms |
54892 KB |
Output is correct |
77 |
Correct |
886 ms |
48876 KB |
Output is correct |
78 |
Correct |
695 ms |
58944 KB |
Output is correct |
79 |
Correct |
678 ms |
58828 KB |
Output is correct |
80 |
Correct |
621 ms |
58988 KB |
Output is correct |
81 |
Correct |
656 ms |
59068 KB |
Output is correct |
82 |
Correct |
426 ms |
51308 KB |
Output is correct |
83 |
Correct |
402 ms |
51180 KB |
Output is correct |
84 |
Correct |
362 ms |
43500 KB |
Output is correct |
85 |
Correct |
888 ms |
48860 KB |
Output is correct |
86 |
Correct |
935 ms |
48776 KB |
Output is correct |
87 |
Correct |
733 ms |
60176 KB |
Output is correct |
88 |
Correct |
659 ms |
60012 KB |
Output is correct |