# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
102080 |
2019-03-22T07:07:25 Z |
ainta |
Lamps (JOI19_lamps) |
C++17 |
|
72 ms |
25848 KB |
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, w[1010000][2], D[1010000][2][2];
char p[1010000], q[1010000];
int cnt;
int res, cc = 0;
vector<int>V;
int main() {
int i, j, k;
scanf("%d", &n);
scanf("%s", p + 1);
scanf("%s", q + 1);
p[0] = p[n + 1] = '0';
q[0] = q[n + 1] = '0';
for (i = 1; i <= n+1; i++) {
w[i][0] = p[i] - '0';
w[i][1] = q[i] - '0';
}
for(int ii=0;ii<=n;ii++)for (i = 0; i < 2; i++)for (j = 0; j < 2; j++)D[ii][i][j] = 1e9;
D[0][0][0] = 0;
for (i = 1; i <= n; i++) {
D[i - 1][0][0] = min(D[i - 1][0][0], D[i - 1][1][0]);
D[i - 1][0][1] = min(D[i - 1][0][1], D[i - 1][1][1]);
for (j = 0; j < 2; j++) {
for (k = 0; k < 2; k++) {
if (D[i - 1][j][k] > 1e8)continue;
int d = D[i - 1][j][k];
if (j == 0 && k == 0) {
if (w[i][0] == w[i][1]) {
D[i][0][0] = min(D[i][0][0], d);
}
else {
D[i][0][1] = min(D[i][0][1], d + 1);
D[i][1][0] = min(D[i][1][0], d + 1);
}
continue;
}
if (j == 0 && k == 1) {
if (w[i][0] != w[i][1]) {
D[i][0][1] = min(D[i][0][1], d);
}
else {
D[i][0][0] = min(D[i][0][0], d);
D[i][1][1] = min(D[i][1][1], d + 1);
}
}
if (j == 1 && k == 0) {
if (w[i-1][1] == w[i][1]) {
D[i][1][0] = min(D[i][1][0], d);
}
else {
if (w[i][0] == w[i][1]) {
D[i][0][0] = min(D[i][0][0], d);
}
else {
D[i][0][1] = min(D[i][0][1], d + 1);
}
D[i][1][1] = min(D[i][1][1], d + 1);
}
continue;
}
if (j == 1 && k == 1) {
if (w[i - 1][1] == w[i][1]) {
D[i][1][1] = min(D[i][1][1], d);
}
else {
if (w[i][0] != w[i][1]) {
D[i][0][1] = min(D[i][0][1], d);
}
else {
D[i][0][0] = min(D[i][0][0], d + 1);
}
D[i][1][0] = min(D[i][1][0], d);
}
continue;
}
}
}
}
int r = 1e9;
for (i = 0; i < 2; i++)for (j = 0; j < 2; j++)r = min(r, D[n][i][j]);
printf("%d\n", r);
return 0;
}
Compilation message
lamp.cpp: In function 'int main()':
lamp.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
lamp.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", p + 1);
~~~~~^~~~~~~~~~~~~
lamp.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", q + 1);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
304 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
3 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
256 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
256 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
256 KB |
Output is correct |
30 |
Correct |
2 ms |
256 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
304 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
3 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
256 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
256 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
256 KB |
Output is correct |
30 |
Correct |
2 ms |
256 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
2 ms |
384 KB |
Output is correct |
35 |
Correct |
3 ms |
384 KB |
Output is correct |
36 |
Correct |
2 ms |
384 KB |
Output is correct |
37 |
Correct |
2 ms |
384 KB |
Output is correct |
38 |
Correct |
2 ms |
384 KB |
Output is correct |
39 |
Correct |
2 ms |
384 KB |
Output is correct |
40 |
Correct |
2 ms |
384 KB |
Output is correct |
41 |
Correct |
3 ms |
384 KB |
Output is correct |
42 |
Correct |
2 ms |
384 KB |
Output is correct |
43 |
Correct |
3 ms |
384 KB |
Output is correct |
44 |
Correct |
3 ms |
384 KB |
Output is correct |
45 |
Correct |
2 ms |
384 KB |
Output is correct |
46 |
Correct |
2 ms |
384 KB |
Output is correct |
47 |
Correct |
2 ms |
384 KB |
Output is correct |
48 |
Correct |
3 ms |
384 KB |
Output is correct |
49 |
Correct |
2 ms |
384 KB |
Output is correct |
50 |
Correct |
2 ms |
384 KB |
Output is correct |
51 |
Correct |
2 ms |
384 KB |
Output is correct |
52 |
Correct |
2 ms |
384 KB |
Output is correct |
53 |
Correct |
3 ms |
384 KB |
Output is correct |
54 |
Correct |
2 ms |
384 KB |
Output is correct |
55 |
Correct |
2 ms |
384 KB |
Output is correct |
56 |
Correct |
3 ms |
384 KB |
Output is correct |
57 |
Correct |
2 ms |
384 KB |
Output is correct |
58 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
356 KB |
Output is correct |
7 |
Correct |
50 ms |
25728 KB |
Output is correct |
8 |
Correct |
48 ms |
25680 KB |
Output is correct |
9 |
Correct |
52 ms |
25692 KB |
Output is correct |
10 |
Correct |
48 ms |
25720 KB |
Output is correct |
11 |
Correct |
54 ms |
25728 KB |
Output is correct |
12 |
Correct |
46 ms |
25720 KB |
Output is correct |
13 |
Correct |
50 ms |
25720 KB |
Output is correct |
14 |
Correct |
50 ms |
25728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
304 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
3 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
256 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
256 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
256 KB |
Output is correct |
30 |
Correct |
2 ms |
256 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
2 ms |
384 KB |
Output is correct |
35 |
Correct |
3 ms |
384 KB |
Output is correct |
36 |
Correct |
2 ms |
384 KB |
Output is correct |
37 |
Correct |
2 ms |
384 KB |
Output is correct |
38 |
Correct |
2 ms |
384 KB |
Output is correct |
39 |
Correct |
2 ms |
384 KB |
Output is correct |
40 |
Correct |
2 ms |
384 KB |
Output is correct |
41 |
Correct |
3 ms |
384 KB |
Output is correct |
42 |
Correct |
2 ms |
384 KB |
Output is correct |
43 |
Correct |
3 ms |
384 KB |
Output is correct |
44 |
Correct |
3 ms |
384 KB |
Output is correct |
45 |
Correct |
2 ms |
384 KB |
Output is correct |
46 |
Correct |
2 ms |
384 KB |
Output is correct |
47 |
Correct |
2 ms |
384 KB |
Output is correct |
48 |
Correct |
3 ms |
384 KB |
Output is correct |
49 |
Correct |
2 ms |
384 KB |
Output is correct |
50 |
Correct |
2 ms |
384 KB |
Output is correct |
51 |
Correct |
2 ms |
384 KB |
Output is correct |
52 |
Correct |
2 ms |
384 KB |
Output is correct |
53 |
Correct |
3 ms |
384 KB |
Output is correct |
54 |
Correct |
2 ms |
384 KB |
Output is correct |
55 |
Correct |
2 ms |
384 KB |
Output is correct |
56 |
Correct |
3 ms |
384 KB |
Output is correct |
57 |
Correct |
2 ms |
384 KB |
Output is correct |
58 |
Correct |
2 ms |
384 KB |
Output is correct |
59 |
Correct |
3 ms |
256 KB |
Output is correct |
60 |
Correct |
2 ms |
256 KB |
Output is correct |
61 |
Correct |
2 ms |
256 KB |
Output is correct |
62 |
Correct |
2 ms |
256 KB |
Output is correct |
63 |
Correct |
2 ms |
256 KB |
Output is correct |
64 |
Correct |
3 ms |
356 KB |
Output is correct |
65 |
Correct |
50 ms |
25728 KB |
Output is correct |
66 |
Correct |
48 ms |
25680 KB |
Output is correct |
67 |
Correct |
52 ms |
25692 KB |
Output is correct |
68 |
Correct |
48 ms |
25720 KB |
Output is correct |
69 |
Correct |
54 ms |
25728 KB |
Output is correct |
70 |
Correct |
46 ms |
25720 KB |
Output is correct |
71 |
Correct |
50 ms |
25720 KB |
Output is correct |
72 |
Correct |
50 ms |
25728 KB |
Output is correct |
73 |
Correct |
59 ms |
25696 KB |
Output is correct |
74 |
Correct |
54 ms |
25848 KB |
Output is correct |
75 |
Correct |
47 ms |
25720 KB |
Output is correct |
76 |
Correct |
50 ms |
25728 KB |
Output is correct |
77 |
Correct |
57 ms |
25720 KB |
Output is correct |
78 |
Correct |
61 ms |
25848 KB |
Output is correct |
79 |
Correct |
49 ms |
25720 KB |
Output is correct |
80 |
Correct |
62 ms |
25708 KB |
Output is correct |
81 |
Correct |
57 ms |
25848 KB |
Output is correct |
82 |
Correct |
49 ms |
25728 KB |
Output is correct |
83 |
Correct |
51 ms |
25720 KB |
Output is correct |
84 |
Correct |
60 ms |
25808 KB |
Output is correct |
85 |
Correct |
59 ms |
25728 KB |
Output is correct |
86 |
Correct |
52 ms |
25848 KB |
Output is correct |
87 |
Correct |
51 ms |
25756 KB |
Output is correct |
88 |
Correct |
59 ms |
25772 KB |
Output is correct |
89 |
Correct |
49 ms |
25720 KB |
Output is correct |
90 |
Correct |
54 ms |
25720 KB |
Output is correct |
91 |
Correct |
69 ms |
25804 KB |
Output is correct |
92 |
Correct |
59 ms |
25720 KB |
Output is correct |
93 |
Correct |
62 ms |
25792 KB |
Output is correct |
94 |
Correct |
59 ms |
25720 KB |
Output is correct |
95 |
Correct |
70 ms |
25848 KB |
Output is correct |
96 |
Correct |
68 ms |
25720 KB |
Output is correct |
97 |
Correct |
61 ms |
25832 KB |
Output is correct |
98 |
Correct |
58 ms |
25720 KB |
Output is correct |
99 |
Correct |
67 ms |
25768 KB |
Output is correct |
100 |
Correct |
67 ms |
25720 KB |
Output is correct |
101 |
Correct |
72 ms |
25796 KB |
Output is correct |
102 |
Correct |
70 ms |
25724 KB |
Output is correct |