Submission #231857

# Submission time Handle Problem Language Result Execution time Memory
231857 2020-05-15T05:23:08 Z jiahng Remittance (JOI19_remittance) C++14
100 / 100
862 ms 75656 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 1000001
typedef long double ld;
#define int ll
int N;
ld X[maxn],Y[maxn];
ld A[maxn],B[maxn];

bool equal(ld a,ld b){
	if (abs(a - b) < 0.000001) return 1;
	else return 0;
}
int32_t main(){
	fast;
	
	cin>>N;
	
	FOR(i,0,N-1) cin>>X[i]>>Y[i];
	
	int fi=-1;
	
	FOR(i,0,N-1){
		if (X[i] - Y[i] >= 0){
			fi = i;
			break;
		}
	}
	if (fi == -1){
		cout<<"No";
		return 0;
	}
	
	rotate(X,X+fi,X+N);
	rotate(Y,Y+fi,Y+N);
	
	B[0] = X[0] - Y[0];
	A[1] = (X[0] - Y[0]) / 2;
	
	FOR(i,1,N - 1){
		B[i] = X[i] - Y[i] + A[i];
		A[(i + 1) % N] = B[i]/2;
	}

	ld z = - B[0] + A[0] - Y[0] + X[0];
	if (z == 0){
		FOR(i,0,N-1){
			if (ll(B[i]) % 2 != 0 || !equal(ll(B[i]),B[i]) || B[i] < 0){
				cout<<"No";
				return 0;
			}
		}
		cout<<"Yes";
		return 0;
	}
	
	ld a = 1;
	FOR(i,1,N) a /= 2;
	
	ld k = 1/z - (a * (1/z));
	k = 1/k;
	

	FOR(i,0,N-1){
		B[i] += k;
		k /= 2;
	}
	//int num = 0;

	FOR(i,0,N-1){
		A[i] = B[(i - 1 + N) % N] / 2;
		
		if (!equal(round(B[i]),B[i]) || (ll)round(B[i]) % 2 != 0 || B[i] < 0 || !equal(round(A[i]),A[i])){
			cout<<"No";
			return 0;
		}
		B[i] = round(B[i]);
		A[i] = round(A[i]);
	}
	
	bool done = 0;
	while (!done){
		done = 1;
		FOR(i,0,N-1){
			ll send = (ll(min(X[i],B[i])) / 2) * 2;
			if (send > 0) done = 0;
			B[i] -= send;
			X[i] -= send;
			X[(i+1) % N] += send / 2;
		}
	}
	
	FOR(i,0,N-1){
		if (X[i] != Y[i]){
			cout<<"No";
			return 0;
		}
	}
			
	cout<<"Yes";

}

# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 4 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 4 ms 384 KB Output is correct
47 Correct 4 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 4 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 4 ms 384 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 5 ms 384 KB Output is correct
57 Correct 4 ms 384 KB Output is correct
58 Correct 5 ms 384 KB Output is correct
59 Correct 4 ms 384 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 4 ms 384 KB Output is correct
62 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 4 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 4 ms 384 KB Output is correct
47 Correct 4 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 4 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 4 ms 384 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 5 ms 384 KB Output is correct
57 Correct 4 ms 384 KB Output is correct
58 Correct 5 ms 384 KB Output is correct
59 Correct 4 ms 384 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 4 ms 384 KB Output is correct
62 Correct 4 ms 384 KB Output is correct
63 Correct 720 ms 64260 KB Output is correct
64 Correct 401 ms 66936 KB Output is correct
65 Correct 824 ms 64248 KB Output is correct
66 Correct 416 ms 66808 KB Output is correct
67 Correct 564 ms 68500 KB Output is correct
68 Correct 593 ms 70764 KB Output is correct
69 Correct 862 ms 64504 KB Output is correct
70 Correct 402 ms 66804 KB Output is correct
71 Correct 514 ms 68344 KB Output is correct
72 Correct 559 ms 70648 KB Output is correct
73 Correct 738 ms 64248 KB Output is correct
74 Correct 426 ms 66936 KB Output is correct
75 Correct 464 ms 68216 KB Output is correct
76 Correct 502 ms 70628 KB Output is correct
77 Correct 739 ms 64248 KB Output is correct
78 Correct 681 ms 74616 KB Output is correct
79 Correct 611 ms 74496 KB Output is correct
80 Correct 728 ms 74584 KB Output is correct
81 Correct 683 ms 74616 KB Output is correct
82 Correct 471 ms 67064 KB Output is correct
83 Correct 380 ms 35576 KB Output is correct
84 Correct 328 ms 66936 KB Output is correct
85 Correct 856 ms 64248 KB Output is correct
86 Correct 826 ms 64192 KB Output is correct
87 Correct 707 ms 75640 KB Output is correct
88 Correct 756 ms 75656 KB Output is correct