#include <stdio.h>
#include <string.h>
#define N 1000000
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int main() {
static char aa[N + 1], bb[N + 1];
static int dp[5], dq[5];
int n, i, s, x, ans;
scanf("%d%s%s", &n, aa, bb);
for (i = 0; i < n; i++)
aa[i] -= '0', bb[i] -= '0';
memset(dp, 0x3f, sizeof dp), dp[4] = 0;
for (i = 0; i < n; i++) {
int a = i == 0 ? 0 : aa[i - 1], b = i == 0 ? 0 : bb[i - 1];
memset(dq, 0x3f, sizeof dq);
if ((x = dp[0]) != INF) {
dq[0] = min(dq[0], x + (b == 0 && bb[i] != 0 ? 1 : 0));
dq[3] = min(dq[3], x + (b == 0 && bb[i] != 1 ? 1 : 0) + 1);
dq[4] = min(dq[4], x + (b == 0 && bb[i] != aa[i] ? 1 : 0));
}
if ((x = dp[1]) != INF) {
dq[1] = min(dq[1], x + (b == 0 && bb[i] != 0 ? 1 : 0));
dq[2] = min(dq[2], x + (b == 0 && bb[i] != 1 ? 1 : 0));
dq[4] = min(dq[4], x + (b == 0 && bb[i] != aa[i] ? 1 : 0));
}
if ((x = dp[2]) != INF) {
dq[1] = min(dq[1], x + (b == 1 && bb[i] != 0 ? 1 : 0) + 1);
dq[2] = min(dq[2], x + (b == 1 && bb[i] != 1 ? 1 : 0));
dq[4] = min(dq[4], x + (b == 1 && bb[i] != aa[i] ? 1 : 0));
}
if ((x = dp[3]) != INF) {
dq[0] = min(dq[0], x + (b == 1 && bb[i] != 0 ? 1 : 0));
dq[3] = min(dq[3], x + (b == 1 && bb[i] != 1 ? 1 : 0));
dq[4] = min(dq[4], x + (b == 1 && bb[i] != aa[i] ? 1 : 0));
}
if ((x = dp[4]) != INF) {
dq[0] = min(dq[0], x + (b == a && bb[i] != 0 ? 1 : 0) + 1);
dq[2] = min(dq[2], x + (b == a && bb[i] != 1 ? 1 : 0) + 1);
dq[4] = min(dq[4], x + (b == a && bb[i] != aa[i] ? 1 : 0));
}
memcpy(dp, dq, sizeof dq);
}
ans = INF;
for (s = 0; s < 5; s++)
ans = min(ans, dp[s]);
printf("%d\n", ans);
return 0;
}
Compilation message
lamp.c: In function 'main':
lamp.c:14:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d%s%s", &n, aa, bb);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
292 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
284 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
288 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
292 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
284 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
288 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
292 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
292 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
296 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
296 KB |
Output is correct |
49 |
Correct |
0 ms |
288 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
288 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Correct |
0 ms |
292 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
34 ms |
4136 KB |
Output is correct |
8 |
Correct |
34 ms |
4172 KB |
Output is correct |
9 |
Correct |
32 ms |
4300 KB |
Output is correct |
10 |
Correct |
32 ms |
4180 KB |
Output is correct |
11 |
Correct |
33 ms |
4172 KB |
Output is correct |
12 |
Correct |
33 ms |
4176 KB |
Output is correct |
13 |
Correct |
32 ms |
4172 KB |
Output is correct |
14 |
Correct |
32 ms |
4092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
292 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
284 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
288 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
292 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
292 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
296 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
296 KB |
Output is correct |
49 |
Correct |
0 ms |
288 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
288 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
292 KB |
Output is correct |
61 |
Correct |
0 ms |
292 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
34 ms |
4136 KB |
Output is correct |
66 |
Correct |
34 ms |
4172 KB |
Output is correct |
67 |
Correct |
32 ms |
4300 KB |
Output is correct |
68 |
Correct |
32 ms |
4180 KB |
Output is correct |
69 |
Correct |
33 ms |
4172 KB |
Output is correct |
70 |
Correct |
33 ms |
4176 KB |
Output is correct |
71 |
Correct |
32 ms |
4172 KB |
Output is correct |
72 |
Correct |
32 ms |
4092 KB |
Output is correct |
73 |
Correct |
36 ms |
4180 KB |
Output is correct |
74 |
Correct |
34 ms |
4200 KB |
Output is correct |
75 |
Correct |
34 ms |
4084 KB |
Output is correct |
76 |
Correct |
36 ms |
4088 KB |
Output is correct |
77 |
Correct |
32 ms |
4172 KB |
Output is correct |
78 |
Correct |
33 ms |
4100 KB |
Output is correct |
79 |
Correct |
31 ms |
4080 KB |
Output is correct |
80 |
Correct |
32 ms |
4176 KB |
Output is correct |
81 |
Correct |
32 ms |
4172 KB |
Output is correct |
82 |
Correct |
33 ms |
4120 KB |
Output is correct |
83 |
Correct |
32 ms |
4116 KB |
Output is correct |
84 |
Correct |
32 ms |
4092 KB |
Output is correct |
85 |
Correct |
32 ms |
4100 KB |
Output is correct |
86 |
Correct |
33 ms |
4092 KB |
Output is correct |
87 |
Correct |
33 ms |
4168 KB |
Output is correct |
88 |
Correct |
36 ms |
4076 KB |
Output is correct |
89 |
Correct |
32 ms |
4172 KB |
Output is correct |
90 |
Correct |
32 ms |
4196 KB |
Output is correct |
91 |
Correct |
34 ms |
4256 KB |
Output is correct |
92 |
Correct |
33 ms |
4088 KB |
Output is correct |
93 |
Correct |
33 ms |
4076 KB |
Output is correct |
94 |
Correct |
32 ms |
4096 KB |
Output is correct |
95 |
Correct |
32 ms |
4072 KB |
Output is correct |
96 |
Correct |
33 ms |
4236 KB |
Output is correct |
97 |
Correct |
36 ms |
4128 KB |
Output is correct |
98 |
Correct |
38 ms |
4176 KB |
Output is correct |
99 |
Correct |
33 ms |
4088 KB |
Output is correct |
100 |
Correct |
32 ms |
4096 KB |
Output is correct |
101 |
Correct |
32 ms |
4096 KB |
Output is correct |
102 |
Correct |
32 ms |
4172 KB |
Output is correct |