Submission #265594

# Submission time Handle Problem Language Result Execution time Memory
265594 2020-08-15T03:01:56 Z easrui Remittance (JOI19_remittance) C++14
100 / 100
689 ms 52080 KB
#include <bits/stdc++.h>
#define va first
#define vb second
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;

const int MN = 1e6+35;
const int MOD = 1e9+7;
const int INF = 1e9;

ll A[MN],B[MN],C[MN],F[MN],k[30];

void impos()
{
	cout << "No";
	exit(0);
}

int main()
{
	#ifdef L0TUS
    freopen("C:\\Users\\SKYPC364\\Documents\\Coding\\BOJ\\input.txt", "r", stdin);
    freopen("C:\\Users\\SKYPC364\\Documents\\Coding\\BOJ\\output.txt", "w", stdout);
	#endif
	
    ios_base::sync_with_stdio(0),cin.tie(0);

    int N;
    cin >> N;

    for(int i=0; i<N; i++) cin >> A[i] >> B[i];

    k[0] = 1;
    for(int i=1; i<30; i++){
    	k[i] = k[i-1]*2;
    }

    for(int i=N-1; i>=0; i--){
	    for(int j=0; j<30; j++){
	    	if(abs(A[i]-B[i])&k[j]){
	    		if(A[i]>B[i]) F[i+j+1]++;
	    		else F[i+j+1]--;
	    	}
	    }
    }


    for(int i=0; i<N+29; i++){
    	if(F[i]>=0){
    		F[i+1] += F[i]/2;
    		F[i]%=2;
    	}
    	else{
    		F[i+1] -= (1-F[i])/2;
    		F[i]=(-F[i])%2;
    	}
    }
    if(F[N+29]<0) impos();

    for(int i=N+29; i>=N; i--){
    	F[i-N] += F[i];
    	C[N-1] += F[i]*k[i-N];
    	F[i] = 0;
    }

    for(int t=0; t<30; t++){
	    for(int i=0; i<N; i++){
	    	F[i+1] += F[i]/2;
	    	F[i]%=2;
	    }
	    F[0] += F[N];
	    C[N-1] += F[N];
	    F[N] = 0;
	}

	F[0]++;
    for(int i=0; i<N; i++){
    	F[i+1] += F[i]/2;
    	F[i]%=2;
    }	

    ll sum = 0;
	for(int i=0; i<=N; i++){
		sum += F[i];
	}

	if(F[N]) C[N-1]++;
	if(sum!=1) impos();
	if(!F[0]&&!F[N]) impos();
    if(C[N-1]%2) impos();


    for(int i=0; i<N-1; i++){
    	C[i] = A[i]-B[i]+C[(i+N-1)%N]/2;
    	if(C[i]<0||C[i]%2) impos();
    }

    for(int t=0; t<3; t++){
	    for(int i=0; i<N; i++){
	    	ll x = min(C[i]/2,A[i]/2)*2;
	    	A[i] -= x;
	    	A[(i+1)%N] += x/2;
	    	C[i] -= x;
	    }
    }

    for(int i=0; i<N; i++) if(A[i]!=B[i]) impos();
    cout << "Yes";

}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 416 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 416 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 1 ms 512 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 0 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 288 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 0 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 0 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 0 ms 384 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 0 ms 384 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 0 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 416 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 1 ms 512 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 0 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 288 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 0 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 0 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 0 ms 384 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 0 ms 384 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 0 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 435 ms 40480 KB Output is correct
64 Correct 338 ms 35704 KB Output is correct
65 Correct 582 ms 50564 KB Output is correct
66 Correct 337 ms 35576 KB Output is correct
67 Correct 365 ms 36976 KB Output is correct
68 Correct 390 ms 39288 KB Output is correct
69 Correct 642 ms 51016 KB Output is correct
70 Correct 343 ms 27744 KB Output is correct
71 Correct 342 ms 29176 KB Output is correct
72 Correct 385 ms 31528 KB Output is correct
73 Correct 599 ms 43236 KB Output is correct
74 Correct 349 ms 30336 KB Output is correct
75 Correct 345 ms 30072 KB Output is correct
76 Correct 380 ms 33016 KB Output is correct
77 Correct 689 ms 43448 KB Output is correct
78 Correct 547 ms 43372 KB Output is correct
79 Correct 545 ms 35448 KB Output is correct
80 Correct 536 ms 43292 KB Output is correct
81 Correct 504 ms 35448 KB Output is correct
82 Correct 325 ms 35548 KB Output is correct
83 Correct 189 ms 27768 KB Output is correct
84 Correct 324 ms 35588 KB Output is correct
85 Correct 629 ms 52080 KB Output is correct
86 Correct 606 ms 44280 KB Output is correct
87 Correct 398 ms 44376 KB Output is correct
88 Correct 418 ms 44292 KB Output is correct