답안 #265597

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
265597 2020-08-15T03:03:21 Z easrui 송금 (JOI19_remittance) C++14
100 / 100
497 ms 31736 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 1e6+35;
const int MOD = 1e9+7;

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

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

int main()
{
    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<5; 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";

}

# 결과 실행 시간 메모리 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 0 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 0 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 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 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 1 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 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 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 0 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 0 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 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 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 1 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 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 640 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 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 0 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 0 ms 384 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 0 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 0 ms 384 KB Output is correct
50 Correct 1 ms 288 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 0 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
54 Correct 0 ms 384 KB Output is correct
55 Correct 0 ms 384 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 0 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 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 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 0 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 0 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 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 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 1 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 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 640 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 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 0 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 0 ms 384 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 0 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 0 ms 384 KB Output is correct
50 Correct 1 ms 288 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 0 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
54 Correct 0 ms 384 KB Output is correct
55 Correct 0 ms 384 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 0 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 0 ms 384 KB Output is correct
63 Correct 435 ms 23772 KB Output is correct
64 Correct 248 ms 31608 KB Output is correct
65 Correct 472 ms 31684 KB Output is correct
66 Correct 275 ms 31608 KB Output is correct
67 Correct 254 ms 31736 KB Output is correct
68 Correct 305 ms 31736 KB Output is correct
69 Correct 467 ms 31608 KB Output is correct
70 Correct 206 ms 23800 KB Output is correct
71 Correct 229 ms 23928 KB Output is correct
72 Correct 283 ms 23956 KB Output is correct
73 Correct 485 ms 23796 KB Output is correct
74 Correct 210 ms 26268 KB Output is correct
75 Correct 229 ms 24824 KB Output is correct
76 Correct 278 ms 25464 KB Output is correct
77 Correct 440 ms 24056 KB Output is correct
78 Correct 431 ms 31624 KB Output is correct
79 Correct 401 ms 23800 KB Output is correct
80 Correct 424 ms 31736 KB Output is correct
81 Correct 391 ms 23928 KB Output is correct
82 Correct 225 ms 31608 KB Output is correct
83 Correct 173 ms 23800 KB Output is correct
84 Correct 226 ms 31736 KB Output is correct
85 Correct 497 ms 31736 KB Output is correct
86 Correct 464 ms 23800 KB Output is correct
87 Correct 297 ms 31736 KB Output is correct
88 Correct 297 ms 31736 KB Output is correct