답안 #261065

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261065 2020-08-11T10:52:32 Z keko37 Lamps (JOI19_lamps) C++14
100 / 100
235 ms 106352 KB
#include<bits/stdc++.h>

using namespace std;

const int MAXN = 1000005;

int n, sol = 1e9;
string a, b;
int dp[MAXN][3][2];

char f (char c, int tip, int toggle) {
    if (tip == 0) c = '0'; else if (tip == 1) c = '1';
    if (toggle) {
        if (c == '0') c = '1'; else c = '0';
    }
    return c;
}

int calc (int pos, int tip, int toggle) {
    if (pos == n) return 0;
    if (dp[pos][tip][toggle] != -1) return dp[pos][tip][toggle];
    int res = 1e9;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 2; j++) {
            int cost = 0;
            if (i <= 1 && tip != i) cost++;
            if (j == 1 && toggle == 0) cost++;
            if (b[pos] == f(a[pos], i, j)) res =  min(res, cost + calc(pos + 1, i, j));
        }
    }
    return dp[pos][tip][toggle] = res;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> a >> b;
    memset(dp, -1, sizeof dp);
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 2; j++) {
            int cost = 0;
            if (i <= 1) cost++;
            if (j == 1) cost++;
            sol = min(sol, cost + calc(0, i, j));
        }
    }
    cout << sol;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 ms 23808 KB Output is correct
7 Correct 13 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23808 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 15 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 14 ms 23808 KB Output is correct
16 Correct 13 ms 23808 KB Output is correct
17 Correct 13 ms 23808 KB Output is correct
18 Correct 14 ms 23808 KB Output is correct
19 Correct 13 ms 23808 KB Output is correct
20 Correct 13 ms 23808 KB Output is correct
21 Correct 13 ms 23824 KB Output is correct
22 Correct 14 ms 23808 KB Output is correct
23 Correct 14 ms 23808 KB Output is correct
24 Correct 14 ms 23808 KB Output is correct
25 Correct 14 ms 23808 KB Output is correct
26 Correct 14 ms 23808 KB Output is correct
27 Correct 14 ms 23936 KB Output is correct
28 Correct 15 ms 23808 KB Output is correct
29 Correct 14 ms 23880 KB Output is correct
30 Correct 14 ms 23808 KB Output is correct
31 Correct 14 ms 23808 KB Output is correct
32 Correct 14 ms 23808 KB Output is correct
33 Correct 14 ms 23808 KB Output is correct
34 Correct 14 ms 23808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 ms 23808 KB Output is correct
7 Correct 13 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23808 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 15 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 14 ms 23808 KB Output is correct
16 Correct 13 ms 23808 KB Output is correct
17 Correct 13 ms 23808 KB Output is correct
18 Correct 14 ms 23808 KB Output is correct
19 Correct 13 ms 23808 KB Output is correct
20 Correct 13 ms 23808 KB Output is correct
21 Correct 13 ms 23824 KB Output is correct
22 Correct 14 ms 23808 KB Output is correct
23 Correct 14 ms 23808 KB Output is correct
24 Correct 14 ms 23808 KB Output is correct
25 Correct 14 ms 23808 KB Output is correct
26 Correct 14 ms 23808 KB Output is correct
27 Correct 14 ms 23936 KB Output is correct
28 Correct 15 ms 23808 KB Output is correct
29 Correct 14 ms 23880 KB Output is correct
30 Correct 14 ms 23808 KB Output is correct
31 Correct 14 ms 23808 KB Output is correct
32 Correct 14 ms 23808 KB Output is correct
33 Correct 14 ms 23808 KB Output is correct
34 Correct 14 ms 23808 KB Output is correct
35 Correct 14 ms 23936 KB Output is correct
36 Correct 15 ms 23936 KB Output is correct
37 Correct 15 ms 23936 KB Output is correct
38 Correct 17 ms 23936 KB Output is correct
39 Correct 14 ms 23936 KB Output is correct
40 Correct 14 ms 23936 KB Output is correct
41 Correct 14 ms 23936 KB Output is correct
42 Correct 14 ms 23936 KB Output is correct
43 Correct 14 ms 23936 KB Output is correct
44 Correct 14 ms 23936 KB Output is correct
45 Correct 14 ms 23936 KB Output is correct
46 Correct 15 ms 23936 KB Output is correct
47 Correct 14 ms 23936 KB Output is correct
48 Correct 15 ms 23936 KB Output is correct
49 Correct 14 ms 23936 KB Output is correct
50 Correct 14 ms 23936 KB Output is correct
51 Correct 14 ms 23936 KB Output is correct
52 Correct 15 ms 23936 KB Output is correct
53 Correct 14 ms 23936 KB Output is correct
54 Correct 15 ms 23936 KB Output is correct
55 Correct 16 ms 23936 KB Output is correct
56 Correct 15 ms 23936 KB Output is correct
57 Correct 14 ms 23936 KB Output is correct
58 Correct 14 ms 23936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 ms 23828 KB Output is correct
7 Correct 179 ms 105036 KB Output is correct
8 Correct 179 ms 106312 KB Output is correct
9 Correct 178 ms 106188 KB Output is correct
10 Correct 177 ms 106312 KB Output is correct
11 Correct 172 ms 106188 KB Output is correct
12 Correct 169 ms 106176 KB Output is correct
13 Correct 170 ms 106180 KB Output is correct
14 Correct 177 ms 106184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 ms 23808 KB Output is correct
7 Correct 13 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23808 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 15 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 14 ms 23808 KB Output is correct
16 Correct 13 ms 23808 KB Output is correct
17 Correct 13 ms 23808 KB Output is correct
18 Correct 14 ms 23808 KB Output is correct
19 Correct 13 ms 23808 KB Output is correct
20 Correct 13 ms 23808 KB Output is correct
21 Correct 13 ms 23824 KB Output is correct
22 Correct 14 ms 23808 KB Output is correct
23 Correct 14 ms 23808 KB Output is correct
24 Correct 14 ms 23808 KB Output is correct
25 Correct 14 ms 23808 KB Output is correct
26 Correct 14 ms 23808 KB Output is correct
27 Correct 14 ms 23936 KB Output is correct
28 Correct 15 ms 23808 KB Output is correct
29 Correct 14 ms 23880 KB Output is correct
30 Correct 14 ms 23808 KB Output is correct
31 Correct 14 ms 23808 KB Output is correct
32 Correct 14 ms 23808 KB Output is correct
33 Correct 14 ms 23808 KB Output is correct
34 Correct 14 ms 23808 KB Output is correct
35 Correct 14 ms 23936 KB Output is correct
36 Correct 15 ms 23936 KB Output is correct
37 Correct 15 ms 23936 KB Output is correct
38 Correct 17 ms 23936 KB Output is correct
39 Correct 14 ms 23936 KB Output is correct
40 Correct 14 ms 23936 KB Output is correct
41 Correct 14 ms 23936 KB Output is correct
42 Correct 14 ms 23936 KB Output is correct
43 Correct 14 ms 23936 KB Output is correct
44 Correct 14 ms 23936 KB Output is correct
45 Correct 14 ms 23936 KB Output is correct
46 Correct 15 ms 23936 KB Output is correct
47 Correct 14 ms 23936 KB Output is correct
48 Correct 15 ms 23936 KB Output is correct
49 Correct 14 ms 23936 KB Output is correct
50 Correct 14 ms 23936 KB Output is correct
51 Correct 14 ms 23936 KB Output is correct
52 Correct 15 ms 23936 KB Output is correct
53 Correct 14 ms 23936 KB Output is correct
54 Correct 15 ms 23936 KB Output is correct
55 Correct 16 ms 23936 KB Output is correct
56 Correct 15 ms 23936 KB Output is correct
57 Correct 14 ms 23936 KB Output is correct
58 Correct 14 ms 23936 KB Output is correct
59 Correct 14 ms 23808 KB Output is correct
60 Correct 16 ms 23808 KB Output is correct
61 Correct 15 ms 23808 KB Output is correct
62 Correct 15 ms 23808 KB Output is correct
63 Correct 14 ms 23808 KB Output is correct
64 Correct 14 ms 23828 KB Output is correct
65 Correct 179 ms 105036 KB Output is correct
66 Correct 179 ms 106312 KB Output is correct
67 Correct 178 ms 106188 KB Output is correct
68 Correct 177 ms 106312 KB Output is correct
69 Correct 172 ms 106188 KB Output is correct
70 Correct 169 ms 106176 KB Output is correct
71 Correct 170 ms 106180 KB Output is correct
72 Correct 177 ms 106184 KB Output is correct
73 Correct 191 ms 106188 KB Output is correct
74 Correct 176 ms 106184 KB Output is correct
75 Correct 182 ms 106220 KB Output is correct
76 Correct 183 ms 106216 KB Output is correct
77 Correct 184 ms 106192 KB Output is correct
78 Correct 188 ms 106184 KB Output is correct
79 Correct 179 ms 106184 KB Output is correct
80 Correct 181 ms 106184 KB Output is correct
81 Correct 194 ms 106188 KB Output is correct
82 Correct 200 ms 106220 KB Output is correct
83 Correct 188 ms 106220 KB Output is correct
84 Correct 184 ms 106228 KB Output is correct
85 Correct 190 ms 106352 KB Output is correct
86 Correct 203 ms 106180 KB Output is correct
87 Correct 197 ms 106176 KB Output is correct
88 Correct 199 ms 106312 KB Output is correct
89 Correct 202 ms 106112 KB Output is correct
90 Correct 201 ms 106204 KB Output is correct
91 Correct 228 ms 106216 KB Output is correct
92 Correct 217 ms 106188 KB Output is correct
93 Correct 235 ms 106184 KB Output is correct
94 Correct 228 ms 106240 KB Output is correct
95 Correct 231 ms 106152 KB Output is correct
96 Correct 216 ms 106216 KB Output is correct
97 Correct 218 ms 106304 KB Output is correct
98 Correct 220 ms 106168 KB Output is correct
99 Correct 214 ms 106216 KB Output is correct
100 Correct 213 ms 106180 KB Output is correct
101 Correct 233 ms 106216 KB Output is correct
102 Correct 222 ms 106188 KB Output is correct