#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define sz(v) (int)v.size()
#define all(x) begin(x),end(x)
#define dbgv(v) for(auto x: v) cerr << x << ' '; cerr << endl;
#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)
const int nx[4]={-1,0,1,0},ny[4]={0,1,0,-1};
void IO(){
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
}
//-----------------------------------------------//
void no(){
cout << "No" << endl;
exit(0);
}
int main(){
IO();
int N; cin>>N;
vector<ll> a(N+1),b(N+1),c(N+1),power(N+1,1);
ll sum=0;
FOR(i,1,N+1){
cin>>a[i]>>b[i];
c[i]=b[i]-a[i];
sum+=a[i];
power[i]=power[i-1]*2;
}
ll x=0;
FOR(i,1,N+1) x+=power[i-1]*c[i];
if(x%(1-power[N])!=0) no();
x/=(1-power[N]);
if(x<0) no();
vector<ll> X(N+1); X[N]=x;
ROF(i,1,N){
X[i]=c[i+1]+2*X[i+1];
if(X[i]<0) no();
}
assert(X[N]==c[1]+2*X[1]);
//checking
int rep=5e5;
while(rep--){
FOR(i,1,N+1){
int n=min(X[i],a[i]/2);
a[i]-=2*n; X[i]-=n;
int nxt=i+1;
if(i==N) nxt=1;
a[nxt]+=n;
}
}
FOR(i,1,N+1) if(X[i]) no();
FOR(i,1,N+1) if(a[i]!=b[i]) no();
cout << "Yes" << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
204 KB |
Output is correct |
3 |
Correct |
6 ms |
204 KB |
Output is correct |
4 |
Correct |
9 ms |
288 KB |
Output is correct |
5 |
Correct |
15 ms |
280 KB |
Output is correct |
6 |
Correct |
20 ms |
288 KB |
Output is correct |
7 |
Correct |
21 ms |
288 KB |
Output is correct |
8 |
Correct |
7 ms |
204 KB |
Output is correct |
9 |
Correct |
11 ms |
288 KB |
Output is correct |
10 |
Correct |
17 ms |
292 KB |
Output is correct |
11 |
Correct |
20 ms |
268 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
17 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
20 ms |
284 KB |
Output is correct |
21 |
Correct |
20 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
21 ms |
288 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
20 ms |
284 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
20 ms |
204 KB |
Output is correct |
29 |
Correct |
20 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
20 ms |
204 KB |
Output is correct |
32 |
Correct |
20 ms |
288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
204 KB |
Output is correct |
3 |
Correct |
6 ms |
204 KB |
Output is correct |
4 |
Correct |
9 ms |
288 KB |
Output is correct |
5 |
Correct |
15 ms |
280 KB |
Output is correct |
6 |
Correct |
20 ms |
288 KB |
Output is correct |
7 |
Correct |
21 ms |
288 KB |
Output is correct |
8 |
Correct |
7 ms |
204 KB |
Output is correct |
9 |
Correct |
11 ms |
288 KB |
Output is correct |
10 |
Correct |
17 ms |
292 KB |
Output is correct |
11 |
Correct |
20 ms |
268 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
17 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
20 ms |
284 KB |
Output is correct |
21 |
Correct |
20 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
21 ms |
288 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
20 ms |
284 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
20 ms |
204 KB |
Output is correct |
29 |
Correct |
20 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
20 ms |
204 KB |
Output is correct |
32 |
Correct |
20 ms |
288 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
57 ms |
204 KB |
Output is correct |
35 |
Correct |
57 ms |
264 KB |
Output is correct |
36 |
Correct |
6 ms |
204 KB |
Output is correct |
37 |
Correct |
56 ms |
204 KB |
Output is correct |
38 |
Correct |
6 ms |
204 KB |
Output is correct |
39 |
Correct |
15 ms |
296 KB |
Output is correct |
40 |
Correct |
56 ms |
204 KB |
Output is correct |
41 |
Correct |
56 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
1 ms |
296 KB |
Output is correct |
45 |
Correct |
1 ms |
204 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
56 ms |
268 KB |
Output is correct |
50 |
Correct |
6 ms |
204 KB |
Output is correct |
51 |
Correct |
56 ms |
204 KB |
Output is correct |
52 |
Correct |
1 ms |
204 KB |
Output is correct |
53 |
Correct |
1 ms |
204 KB |
Output is correct |
54 |
Correct |
58 ms |
204 KB |
Output is correct |
55 |
Correct |
1 ms |
204 KB |
Output is correct |
56 |
Correct |
56 ms |
204 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
56 ms |
204 KB |
Output is correct |
59 |
Correct |
56 ms |
268 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
56 ms |
204 KB |
Output is correct |
62 |
Correct |
56 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
204 KB |
Output is correct |
3 |
Correct |
6 ms |
204 KB |
Output is correct |
4 |
Correct |
9 ms |
288 KB |
Output is correct |
5 |
Correct |
15 ms |
280 KB |
Output is correct |
6 |
Correct |
20 ms |
288 KB |
Output is correct |
7 |
Correct |
21 ms |
288 KB |
Output is correct |
8 |
Correct |
7 ms |
204 KB |
Output is correct |
9 |
Correct |
11 ms |
288 KB |
Output is correct |
10 |
Correct |
17 ms |
292 KB |
Output is correct |
11 |
Correct |
20 ms |
268 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
17 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
20 ms |
284 KB |
Output is correct |
21 |
Correct |
20 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
21 ms |
288 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
20 ms |
284 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
20 ms |
204 KB |
Output is correct |
29 |
Correct |
20 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
20 ms |
204 KB |
Output is correct |
32 |
Correct |
20 ms |
288 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
57 ms |
204 KB |
Output is correct |
35 |
Correct |
57 ms |
264 KB |
Output is correct |
36 |
Correct |
6 ms |
204 KB |
Output is correct |
37 |
Correct |
56 ms |
204 KB |
Output is correct |
38 |
Correct |
6 ms |
204 KB |
Output is correct |
39 |
Correct |
15 ms |
296 KB |
Output is correct |
40 |
Correct |
56 ms |
204 KB |
Output is correct |
41 |
Correct |
56 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
1 ms |
296 KB |
Output is correct |
45 |
Correct |
1 ms |
204 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
56 ms |
268 KB |
Output is correct |
50 |
Correct |
6 ms |
204 KB |
Output is correct |
51 |
Correct |
56 ms |
204 KB |
Output is correct |
52 |
Correct |
1 ms |
204 KB |
Output is correct |
53 |
Correct |
1 ms |
204 KB |
Output is correct |
54 |
Correct |
58 ms |
204 KB |
Output is correct |
55 |
Correct |
1 ms |
204 KB |
Output is correct |
56 |
Correct |
56 ms |
204 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
56 ms |
204 KB |
Output is correct |
59 |
Correct |
56 ms |
268 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
56 ms |
204 KB |
Output is correct |
62 |
Correct |
56 ms |
204 KB |
Output is correct |
63 |
Correct |
872 ms |
58872 KB |
Output is correct |
64 |
Execution timed out |
1022 ms |
43332 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |