Submission #105055

# Submission time Handle Problem Language Result Execution time Memory
105055 2019-04-10T11:01:13 Z antimirage Lamps (JOI19_lamps) C++14
100 / 100
106 ms 67064 KB
# include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1e6 + 5;
 
int n, dp[N][4][4];
 
char a[N], b[N];

main(){ 
	memset( dp, 0x3f3f3f3f, sizeof(dp) );

	cin >> n;
	scanf("\n%s", a + 1);
	scanf("\n%s", b + 1);

	dp[0][2][0] = 0;
	for (int i = 1; i <= n; i++){
	
		for (int j = 0; j < 3; j++){
		
			if (b[i] - 48 == j){
			
				dp[i][j][0] = min(dp[i - 1][j][1], dp[i - 1][j][0]);
				
				for (int l = 0; l < 3; l++){
	
					dp[i][j][0] = min( dp[i][j][0], dp[i - 1][l][0] + 1);
					dp[i][j][0] = min( dp[i][j][0], dp[i - 1][l][1] + 1);
				}
			}
			if (b[i] - 48 == (j ^ 1) ){
				
				dp[i][j][1] = min( dp[i - 1][j][0] + 1, dp[i - 1][j][1]);
				
				for (int l = 0; l < 3; l++){
					
					dp[i][j][1] = min( dp[i][j][1], dp[i - 1][l][1] + 1);
				}
			}
			if (j == 2 && b[i] == a[i]){
				
				for (int l = 0; l < 3; l++){
					
					dp[i][j][0] = min( dp[i][j][0], dp[i - 1][l][0]);
					dp[i][j][0] = min( dp[i][j][0], dp[i - 1][l][1]);
				}
			}
			if (j == 2 && b[i] != a[i]){
				
				for (int l = 0; l < 3; l++){
					
					dp[i][j][1] = min( dp[i][j][1], dp[i - 1][l][1]);
					dp[i][j][1] = min( dp[i][j][1], dp[i - 1][l][0] + 1);
				}
			}
		}
	}
	int ans = n + 1;
	
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 2; j++)
			ans = min(ans, dp[n][i][j]);
			
	cout << ans << endl;
}
/**
13
0101100101001
1011111000000

13
0001101001101
0101100011011

8
11011100
01101001
**/

Compilation message

lamp.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){ 
      ^
lamp.cpp: In function 'int main()':
lamp.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("\n%s", a + 1);
  ~~~~~^~~~~~~~~~~~~~~
lamp.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("\n%s", b + 1);
  ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 68 ms 62968 KB Output is correct
2 Correct 63 ms 62968 KB Output is correct
3 Correct 58 ms 62972 KB Output is correct
4 Correct 55 ms 62956 KB Output is correct
5 Correct 55 ms 62968 KB Output is correct
6 Correct 60 ms 62968 KB Output is correct
7 Correct 54 ms 62968 KB Output is correct
8 Correct 60 ms 62968 KB Output is correct
9 Correct 52 ms 62968 KB Output is correct
10 Correct 54 ms 62968 KB Output is correct
11 Correct 58 ms 63072 KB Output is correct
12 Correct 54 ms 62968 KB Output is correct
13 Correct 56 ms 62968 KB Output is correct
14 Correct 51 ms 62972 KB Output is correct
15 Correct 52 ms 62924 KB Output is correct
16 Correct 61 ms 62968 KB Output is correct
17 Correct 53 ms 62968 KB Output is correct
18 Correct 57 ms 62968 KB Output is correct
19 Correct 59 ms 62968 KB Output is correct
20 Correct 56 ms 63096 KB Output is correct
21 Correct 57 ms 62888 KB Output is correct
22 Correct 55 ms 62968 KB Output is correct
23 Correct 58 ms 62968 KB Output is correct
24 Correct 55 ms 62968 KB Output is correct
25 Correct 55 ms 62968 KB Output is correct
26 Correct 55 ms 62980 KB Output is correct
27 Correct 53 ms 63096 KB Output is correct
28 Correct 59 ms 63096 KB Output is correct
29 Correct 56 ms 62968 KB Output is correct
30 Correct 56 ms 62900 KB Output is correct
31 Correct 53 ms 62968 KB Output is correct
32 Correct 56 ms 63096 KB Output is correct
33 Correct 56 ms 62968 KB Output is correct
34 Correct 57 ms 63096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 62968 KB Output is correct
2 Correct 63 ms 62968 KB Output is correct
3 Correct 58 ms 62972 KB Output is correct
4 Correct 55 ms 62956 KB Output is correct
5 Correct 55 ms 62968 KB Output is correct
6 Correct 60 ms 62968 KB Output is correct
7 Correct 54 ms 62968 KB Output is correct
8 Correct 60 ms 62968 KB Output is correct
9 Correct 52 ms 62968 KB Output is correct
10 Correct 54 ms 62968 KB Output is correct
11 Correct 58 ms 63072 KB Output is correct
12 Correct 54 ms 62968 KB Output is correct
13 Correct 56 ms 62968 KB Output is correct
14 Correct 51 ms 62972 KB Output is correct
15 Correct 52 ms 62924 KB Output is correct
16 Correct 61 ms 62968 KB Output is correct
17 Correct 53 ms 62968 KB Output is correct
18 Correct 57 ms 62968 KB Output is correct
19 Correct 59 ms 62968 KB Output is correct
20 Correct 56 ms 63096 KB Output is correct
21 Correct 57 ms 62888 KB Output is correct
22 Correct 55 ms 62968 KB Output is correct
23 Correct 58 ms 62968 KB Output is correct
24 Correct 55 ms 62968 KB Output is correct
25 Correct 55 ms 62968 KB Output is correct
26 Correct 55 ms 62980 KB Output is correct
27 Correct 53 ms 63096 KB Output is correct
28 Correct 59 ms 63096 KB Output is correct
29 Correct 56 ms 62968 KB Output is correct
30 Correct 56 ms 62900 KB Output is correct
31 Correct 53 ms 62968 KB Output is correct
32 Correct 56 ms 63096 KB Output is correct
33 Correct 56 ms 62968 KB Output is correct
34 Correct 57 ms 63096 KB Output is correct
35 Correct 52 ms 62972 KB Output is correct
36 Correct 52 ms 62924 KB Output is correct
37 Correct 60 ms 62968 KB Output is correct
38 Correct 57 ms 62968 KB Output is correct
39 Correct 58 ms 62968 KB Output is correct
40 Correct 56 ms 62968 KB Output is correct
41 Correct 62 ms 62968 KB Output is correct
42 Correct 57 ms 62968 KB Output is correct
43 Correct 61 ms 62968 KB Output is correct
44 Correct 56 ms 62968 KB Output is correct
45 Correct 63 ms 62968 KB Output is correct
46 Correct 57 ms 62904 KB Output is correct
47 Correct 55 ms 62900 KB Output is correct
48 Correct 58 ms 62968 KB Output is correct
49 Correct 55 ms 62888 KB Output is correct
50 Correct 54 ms 62968 KB Output is correct
51 Correct 61 ms 62968 KB Output is correct
52 Correct 57 ms 62968 KB Output is correct
53 Correct 58 ms 62968 KB Output is correct
54 Correct 60 ms 62968 KB Output is correct
55 Correct 58 ms 62972 KB Output is correct
56 Correct 58 ms 62964 KB Output is correct
57 Correct 51 ms 62968 KB Output is correct
58 Correct 54 ms 62968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 62936 KB Output is correct
2 Correct 56 ms 62968 KB Output is correct
3 Correct 54 ms 62940 KB Output is correct
4 Correct 56 ms 62968 KB Output is correct
5 Correct 56 ms 62968 KB Output is correct
6 Correct 56 ms 62968 KB Output is correct
7 Correct 86 ms 65920 KB Output is correct
8 Correct 88 ms 66296 KB Output is correct
9 Correct 99 ms 66332 KB Output is correct
10 Correct 81 ms 66300 KB Output is correct
11 Correct 82 ms 66296 KB Output is correct
12 Correct 83 ms 66324 KB Output is correct
13 Correct 97 ms 66268 KB Output is correct
14 Correct 83 ms 66296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 62968 KB Output is correct
2 Correct 63 ms 62968 KB Output is correct
3 Correct 58 ms 62972 KB Output is correct
4 Correct 55 ms 62956 KB Output is correct
5 Correct 55 ms 62968 KB Output is correct
6 Correct 60 ms 62968 KB Output is correct
7 Correct 54 ms 62968 KB Output is correct
8 Correct 60 ms 62968 KB Output is correct
9 Correct 52 ms 62968 KB Output is correct
10 Correct 54 ms 62968 KB Output is correct
11 Correct 58 ms 63072 KB Output is correct
12 Correct 54 ms 62968 KB Output is correct
13 Correct 56 ms 62968 KB Output is correct
14 Correct 51 ms 62972 KB Output is correct
15 Correct 52 ms 62924 KB Output is correct
16 Correct 61 ms 62968 KB Output is correct
17 Correct 53 ms 62968 KB Output is correct
18 Correct 57 ms 62968 KB Output is correct
19 Correct 59 ms 62968 KB Output is correct
20 Correct 56 ms 63096 KB Output is correct
21 Correct 57 ms 62888 KB Output is correct
22 Correct 55 ms 62968 KB Output is correct
23 Correct 58 ms 62968 KB Output is correct
24 Correct 55 ms 62968 KB Output is correct
25 Correct 55 ms 62968 KB Output is correct
26 Correct 55 ms 62980 KB Output is correct
27 Correct 53 ms 63096 KB Output is correct
28 Correct 59 ms 63096 KB Output is correct
29 Correct 56 ms 62968 KB Output is correct
30 Correct 56 ms 62900 KB Output is correct
31 Correct 53 ms 62968 KB Output is correct
32 Correct 56 ms 63096 KB Output is correct
33 Correct 56 ms 62968 KB Output is correct
34 Correct 57 ms 63096 KB Output is correct
35 Correct 52 ms 62972 KB Output is correct
36 Correct 52 ms 62924 KB Output is correct
37 Correct 60 ms 62968 KB Output is correct
38 Correct 57 ms 62968 KB Output is correct
39 Correct 58 ms 62968 KB Output is correct
40 Correct 56 ms 62968 KB Output is correct
41 Correct 62 ms 62968 KB Output is correct
42 Correct 57 ms 62968 KB Output is correct
43 Correct 61 ms 62968 KB Output is correct
44 Correct 56 ms 62968 KB Output is correct
45 Correct 63 ms 62968 KB Output is correct
46 Correct 57 ms 62904 KB Output is correct
47 Correct 55 ms 62900 KB Output is correct
48 Correct 58 ms 62968 KB Output is correct
49 Correct 55 ms 62888 KB Output is correct
50 Correct 54 ms 62968 KB Output is correct
51 Correct 61 ms 62968 KB Output is correct
52 Correct 57 ms 62968 KB Output is correct
53 Correct 58 ms 62968 KB Output is correct
54 Correct 60 ms 62968 KB Output is correct
55 Correct 58 ms 62972 KB Output is correct
56 Correct 58 ms 62964 KB Output is correct
57 Correct 51 ms 62968 KB Output is correct
58 Correct 54 ms 62968 KB Output is correct
59 Correct 58 ms 62936 KB Output is correct
60 Correct 56 ms 62968 KB Output is correct
61 Correct 54 ms 62940 KB Output is correct
62 Correct 56 ms 62968 KB Output is correct
63 Correct 56 ms 62968 KB Output is correct
64 Correct 56 ms 62968 KB Output is correct
65 Correct 86 ms 65920 KB Output is correct
66 Correct 88 ms 66296 KB Output is correct
67 Correct 99 ms 66332 KB Output is correct
68 Correct 81 ms 66300 KB Output is correct
69 Correct 82 ms 66296 KB Output is correct
70 Correct 83 ms 66324 KB Output is correct
71 Correct 97 ms 66268 KB Output is correct
72 Correct 83 ms 66296 KB Output is correct
73 Correct 87 ms 66336 KB Output is correct
74 Correct 83 ms 66808 KB Output is correct
75 Correct 91 ms 66936 KB Output is correct
76 Correct 86 ms 66964 KB Output is correct
77 Correct 86 ms 67016 KB Output is correct
78 Correct 89 ms 66868 KB Output is correct
79 Correct 84 ms 66808 KB Output is correct
80 Correct 87 ms 66792 KB Output is correct
81 Correct 90 ms 67064 KB Output is correct
82 Correct 86 ms 66780 KB Output is correct
83 Correct 98 ms 66780 KB Output is correct
84 Correct 96 ms 66892 KB Output is correct
85 Correct 99 ms 66812 KB Output is correct
86 Correct 96 ms 66828 KB Output is correct
87 Correct 98 ms 66808 KB Output is correct
88 Correct 95 ms 66896 KB Output is correct
89 Correct 90 ms 66808 KB Output is correct
90 Correct 89 ms 66936 KB Output is correct
91 Correct 94 ms 66808 KB Output is correct
92 Correct 106 ms 66984 KB Output is correct
93 Correct 99 ms 66808 KB Output is correct
94 Correct 97 ms 66804 KB Output is correct
95 Correct 95 ms 66780 KB Output is correct
96 Correct 92 ms 66936 KB Output is correct
97 Correct 99 ms 67000 KB Output is correct
98 Correct 95 ms 66864 KB Output is correct
99 Correct 96 ms 66780 KB Output is correct
100 Correct 96 ms 66808 KB Output is correct
101 Correct 98 ms 66808 KB Output is correct
102 Correct 93 ms 66884 KB Output is correct