Submission #402551

# Submission time Handle Problem Language Result Execution time Memory
402551 2021-05-11T23:25:41 Z AmineWeslati Remittance (JOI19_remittance) C++14
15 / 100
1000 ms 296 KB
#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){
			while(X[i] && 2<=a[i]){
				a[i]-=2; X[i]--;

				int nxt=i+1; 
				if(i==N) nxt=1;
				a[nxt]++;
			}
		}
	}
	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 2 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 4 ms 284 KB Output is correct
6 Correct 5 ms 204 KB Output is correct
7 Correct 5 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 4 ms 204 KB Output is correct
10 Correct 5 ms 284 KB Output is correct
11 Correct 5 ms 284 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 5 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 7 ms 204 KB Output is correct
21 Correct 7 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 6 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 10 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 5 ms 204 KB Output is correct
29 Correct 5 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 8 ms 204 KB Output is correct
32 Correct 5 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 4 ms 284 KB Output is correct
6 Correct 5 ms 204 KB Output is correct
7 Correct 5 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 4 ms 204 KB Output is correct
10 Correct 5 ms 284 KB Output is correct
11 Correct 5 ms 284 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 5 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 7 ms 204 KB Output is correct
21 Correct 7 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 6 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 10 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 5 ms 204 KB Output is correct
29 Correct 5 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 8 ms 204 KB Output is correct
32 Correct 5 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 15 ms 296 KB Output is correct
35 Correct 15 ms 204 KB Output is correct
36 Execution timed out 1088 ms 204 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 4 ms 284 KB Output is correct
6 Correct 5 ms 204 KB Output is correct
7 Correct 5 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 4 ms 204 KB Output is correct
10 Correct 5 ms 284 KB Output is correct
11 Correct 5 ms 284 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 5 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 7 ms 204 KB Output is correct
21 Correct 7 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 6 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 10 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 5 ms 204 KB Output is correct
29 Correct 5 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 8 ms 204 KB Output is correct
32 Correct 5 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 15 ms 296 KB Output is correct
35 Correct 15 ms 204 KB Output is correct
36 Execution timed out 1088 ms 204 KB Time limit exceeded
37 Halted 0 ms 0 KB -