답안 #260391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260391 2020-08-10T08:13:51 Z patrikpavic2 Lamps (JOI19_lamps) C++17
100 / 100
591 ms 229372 KB
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 1e6 + 500;

int A[N], B[N], dp[N][2][8], n;

int f(int x, int inv, int msk){
	if(x == n) return 0;
	if(dp[x][inv][msk] != -1) return dp[x][inv][msk];
	int ret = N;
	if(msk & 1) 
		ret = min(ret, f(x, inv, msk - 1));
	if(msk & 2) 
		ret = min(ret, f(x, inv, msk - 2));
	if(msk & 4)
		 ret = min(ret, f(x, inv, msk - 4));
	if(msk == 4)
		ret = min(ret, f(x, inv, 1));
	int zlm = B[x] ^ inv, jos = 0, ol = msk;
	if(A[x] == 0 && zlm == 0){
		if(msk & 4) msk -= 4;
		if((msk & 3) == 1)
			msk = 0;
	}
	if(A[x] == 1 && zlm == 1){
		if((msk & 6) == 2)
			msk -= 2;
	}
	if(A[x] == 1 && zlm == 0){
		if(msk & 4) msk -= 4;
		if(!(msk & 2))
			msk += 2, jos++;
		
	}
	if(A[x] == 0 && zlm == 1){
		if(msk == 3)
			msk = 1;
		if(msk == 2)
			msk += 4, jos++;
		if(msk == 0)
			msk = 1, jos++;
	}
	ret = min(ret, jos + min(f(x + 1, inv, msk), f(x + 1, !inv, msk) + (!inv)));
	return dp[x][inv][ol] = ret;
}

int main(){
	memset(dp, -1, sizeof(dp));
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		char c; scanf(" %c", &c);
		A[i] = c - '0';
	}
	for(int i = 0;i < n;i++){
		char c; scanf(" %c", &c);
		B[i] = c - '0';
	}
	printf("%d\n", min(f(0, 0, 0), 1 + f(0, 1, 0)));
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
lamp.cpp:55:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   char c; scanf(" %c", &c);
           ~~~~~^~~~~~~~~~~
lamp.cpp:59:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   char c; scanf(" %c", &c);
           ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 62944 KB Output is correct
2 Correct 32 ms 62968 KB Output is correct
3 Correct 36 ms 62976 KB Output is correct
4 Correct 31 ms 62968 KB Output is correct
5 Correct 31 ms 62976 KB Output is correct
6 Correct 32 ms 62968 KB Output is correct
7 Correct 32 ms 62976 KB Output is correct
8 Correct 32 ms 62976 KB Output is correct
9 Correct 31 ms 62968 KB Output is correct
10 Correct 31 ms 62984 KB Output is correct
11 Correct 32 ms 62968 KB Output is correct
12 Correct 36 ms 62968 KB Output is correct
13 Correct 32 ms 62976 KB Output is correct
14 Correct 34 ms 62976 KB Output is correct
15 Correct 35 ms 62972 KB Output is correct
16 Correct 31 ms 62976 KB Output is correct
17 Correct 31 ms 62968 KB Output is correct
18 Correct 37 ms 62976 KB Output is correct
19 Correct 31 ms 62976 KB Output is correct
20 Correct 30 ms 62968 KB Output is correct
21 Correct 38 ms 62968 KB Output is correct
22 Correct 33 ms 62952 KB Output is correct
23 Correct 36 ms 63096 KB Output is correct
24 Correct 30 ms 62976 KB Output is correct
25 Correct 32 ms 62976 KB Output is correct
26 Correct 33 ms 62968 KB Output is correct
27 Correct 31 ms 62976 KB Output is correct
28 Correct 31 ms 62976 KB Output is correct
29 Correct 39 ms 62976 KB Output is correct
30 Correct 41 ms 62968 KB Output is correct
31 Correct 31 ms 62968 KB Output is correct
32 Correct 37 ms 62968 KB Output is correct
33 Correct 31 ms 62968 KB Output is correct
34 Correct 33 ms 62968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 62944 KB Output is correct
2 Correct 32 ms 62968 KB Output is correct
3 Correct 36 ms 62976 KB Output is correct
4 Correct 31 ms 62968 KB Output is correct
5 Correct 31 ms 62976 KB Output is correct
6 Correct 32 ms 62968 KB Output is correct
7 Correct 32 ms 62976 KB Output is correct
8 Correct 32 ms 62976 KB Output is correct
9 Correct 31 ms 62968 KB Output is correct
10 Correct 31 ms 62984 KB Output is correct
11 Correct 32 ms 62968 KB Output is correct
12 Correct 36 ms 62968 KB Output is correct
13 Correct 32 ms 62976 KB Output is correct
14 Correct 34 ms 62976 KB Output is correct
15 Correct 35 ms 62972 KB Output is correct
16 Correct 31 ms 62976 KB Output is correct
17 Correct 31 ms 62968 KB Output is correct
18 Correct 37 ms 62976 KB Output is correct
19 Correct 31 ms 62976 KB Output is correct
20 Correct 30 ms 62968 KB Output is correct
21 Correct 38 ms 62968 KB Output is correct
22 Correct 33 ms 62952 KB Output is correct
23 Correct 36 ms 63096 KB Output is correct
24 Correct 30 ms 62976 KB Output is correct
25 Correct 32 ms 62976 KB Output is correct
26 Correct 33 ms 62968 KB Output is correct
27 Correct 31 ms 62976 KB Output is correct
28 Correct 31 ms 62976 KB Output is correct
29 Correct 39 ms 62976 KB Output is correct
30 Correct 41 ms 62968 KB Output is correct
31 Correct 31 ms 62968 KB Output is correct
32 Correct 37 ms 62968 KB Output is correct
33 Correct 31 ms 62968 KB Output is correct
34 Correct 33 ms 62968 KB Output is correct
35 Correct 31 ms 63232 KB Output is correct
36 Correct 37 ms 63224 KB Output is correct
37 Correct 32 ms 63096 KB Output is correct
38 Correct 35 ms 63096 KB Output is correct
39 Correct 32 ms 63224 KB Output is correct
40 Correct 38 ms 63224 KB Output is correct
41 Correct 32 ms 63232 KB Output is correct
42 Correct 37 ms 63224 KB Output is correct
43 Correct 41 ms 63224 KB Output is correct
44 Correct 36 ms 63224 KB Output is correct
45 Correct 37 ms 63224 KB Output is correct
46 Correct 39 ms 63224 KB Output is correct
47 Correct 41 ms 63224 KB Output is correct
48 Correct 37 ms 63228 KB Output is correct
49 Correct 39 ms 63224 KB Output is correct
50 Correct 36 ms 63224 KB Output is correct
51 Correct 31 ms 63224 KB Output is correct
52 Correct 38 ms 63224 KB Output is correct
53 Correct 35 ms 63232 KB Output is correct
54 Correct 36 ms 63224 KB Output is correct
55 Correct 32 ms 63224 KB Output is correct
56 Correct 32 ms 63224 KB Output is correct
57 Correct 32 ms 63232 KB Output is correct
58 Correct 32 ms 63224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 62972 KB Output is correct
2 Correct 37 ms 62968 KB Output is correct
3 Correct 33 ms 62908 KB Output is correct
4 Correct 32 ms 62976 KB Output is correct
5 Correct 38 ms 62968 KB Output is correct
6 Correct 36 ms 62968 KB Output is correct
7 Correct 270 ms 188152 KB Output is correct
8 Correct 260 ms 148984 KB Output is correct
9 Correct 285 ms 148984 KB Output is correct
10 Correct 294 ms 227380 KB Output is correct
11 Correct 313 ms 227260 KB Output is correct
12 Correct 288 ms 188152 KB Output is correct
13 Correct 277 ms 188240 KB Output is correct
14 Correct 299 ms 188152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 62944 KB Output is correct
2 Correct 32 ms 62968 KB Output is correct
3 Correct 36 ms 62976 KB Output is correct
4 Correct 31 ms 62968 KB Output is correct
5 Correct 31 ms 62976 KB Output is correct
6 Correct 32 ms 62968 KB Output is correct
7 Correct 32 ms 62976 KB Output is correct
8 Correct 32 ms 62976 KB Output is correct
9 Correct 31 ms 62968 KB Output is correct
10 Correct 31 ms 62984 KB Output is correct
11 Correct 32 ms 62968 KB Output is correct
12 Correct 36 ms 62968 KB Output is correct
13 Correct 32 ms 62976 KB Output is correct
14 Correct 34 ms 62976 KB Output is correct
15 Correct 35 ms 62972 KB Output is correct
16 Correct 31 ms 62976 KB Output is correct
17 Correct 31 ms 62968 KB Output is correct
18 Correct 37 ms 62976 KB Output is correct
19 Correct 31 ms 62976 KB Output is correct
20 Correct 30 ms 62968 KB Output is correct
21 Correct 38 ms 62968 KB Output is correct
22 Correct 33 ms 62952 KB Output is correct
23 Correct 36 ms 63096 KB Output is correct
24 Correct 30 ms 62976 KB Output is correct
25 Correct 32 ms 62976 KB Output is correct
26 Correct 33 ms 62968 KB Output is correct
27 Correct 31 ms 62976 KB Output is correct
28 Correct 31 ms 62976 KB Output is correct
29 Correct 39 ms 62976 KB Output is correct
30 Correct 41 ms 62968 KB Output is correct
31 Correct 31 ms 62968 KB Output is correct
32 Correct 37 ms 62968 KB Output is correct
33 Correct 31 ms 62968 KB Output is correct
34 Correct 33 ms 62968 KB Output is correct
35 Correct 31 ms 63232 KB Output is correct
36 Correct 37 ms 63224 KB Output is correct
37 Correct 32 ms 63096 KB Output is correct
38 Correct 35 ms 63096 KB Output is correct
39 Correct 32 ms 63224 KB Output is correct
40 Correct 38 ms 63224 KB Output is correct
41 Correct 32 ms 63232 KB Output is correct
42 Correct 37 ms 63224 KB Output is correct
43 Correct 41 ms 63224 KB Output is correct
44 Correct 36 ms 63224 KB Output is correct
45 Correct 37 ms 63224 KB Output is correct
46 Correct 39 ms 63224 KB Output is correct
47 Correct 41 ms 63224 KB Output is correct
48 Correct 37 ms 63228 KB Output is correct
49 Correct 39 ms 63224 KB Output is correct
50 Correct 36 ms 63224 KB Output is correct
51 Correct 31 ms 63224 KB Output is correct
52 Correct 38 ms 63224 KB Output is correct
53 Correct 35 ms 63232 KB Output is correct
54 Correct 36 ms 63224 KB Output is correct
55 Correct 32 ms 63224 KB Output is correct
56 Correct 32 ms 63224 KB Output is correct
57 Correct 32 ms 63232 KB Output is correct
58 Correct 32 ms 63224 KB Output is correct
59 Correct 37 ms 62972 KB Output is correct
60 Correct 37 ms 62968 KB Output is correct
61 Correct 33 ms 62908 KB Output is correct
62 Correct 32 ms 62976 KB Output is correct
63 Correct 38 ms 62968 KB Output is correct
64 Correct 36 ms 62968 KB Output is correct
65 Correct 270 ms 188152 KB Output is correct
66 Correct 260 ms 148984 KB Output is correct
67 Correct 285 ms 148984 KB Output is correct
68 Correct 294 ms 227380 KB Output is correct
69 Correct 313 ms 227260 KB Output is correct
70 Correct 288 ms 188152 KB Output is correct
71 Correct 277 ms 188240 KB Output is correct
72 Correct 299 ms 188152 KB Output is correct
73 Correct 402 ms 150976 KB Output is correct
74 Correct 422 ms 190200 KB Output is correct
75 Correct 417 ms 190200 KB Output is correct
76 Correct 417 ms 190176 KB Output is correct
77 Correct 311 ms 229264 KB Output is correct
78 Correct 269 ms 150948 KB Output is correct
79 Correct 418 ms 190072 KB Output is correct
80 Correct 421 ms 190200 KB Output is correct
81 Correct 309 ms 229372 KB Output is correct
82 Correct 270 ms 151032 KB Output is correct
83 Correct 537 ms 190256 KB Output is correct
84 Correct 428 ms 190200 KB Output is correct
85 Correct 453 ms 190072 KB Output is correct
86 Correct 591 ms 190200 KB Output is correct
87 Correct 435 ms 190152 KB Output is correct
88 Correct 445 ms 190244 KB Output is correct
89 Correct 464 ms 190172 KB Output is correct
90 Correct 456 ms 190272 KB Output is correct
91 Correct 450 ms 190200 KB Output is correct
92 Correct 485 ms 190200 KB Output is correct
93 Correct 462 ms 190272 KB Output is correct
94 Correct 479 ms 190200 KB Output is correct
95 Correct 477 ms 190220 KB Output is correct
96 Correct 485 ms 190200 KB Output is correct
97 Correct 493 ms 190200 KB Output is correct
98 Correct 482 ms 190232 KB Output is correct
99 Correct 487 ms 190180 KB Output is correct
100 Correct 546 ms 190272 KB Output is correct
101 Correct 512 ms 190072 KB Output is correct
102 Correct 462 ms 190180 KB Output is correct