답안 #143623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
143623 2019-08-14T18:35:16 Z osaaateiasavtnl Lamps (JOI19_lamps) C++14
100 / 100
331 ms 51600 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
const int N = 1e6 + 7, INF = 1e9 + 7;
int n;
string a, b;
int dp[N][3][2];
bool check(char c1, char c2, int i, int j) {
    if (i == 0 && j == 0) return c1 == c2;
    if (i == 0) return c1 != c2;
    if (i == 1 && j == 0) return c2 == '0';
    if (i == 1) return c2 == '1';
    if (i == 2 && j == 0) return c2 == '1';
    return c2 == '0';
}   
void upd(int p, int i, int j, int c) {
    if (check(a[p - 1], b[p - 1], i, j)) {
        dp[p][i][j] = min(dp[p][i][j], c);
    }   
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) for (int k = 0; k < 2; ++k) dp[i][j][k] = INF;
    cin >> n >> a >> b;
    dp[0][0][0] = 0;
    for (int p = 0; p < n; ++p) {
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 2; ++j) {

                for (int ii = 0; ii < 3; ++ii) {
                    for (int jj = 0; jj < 2; ++jj) {
                        upd(p + 1, ii, jj, dp[p][i][j] + (ii && ii != i) + (jj && jj != j));
                    }
                }

            }
        }
    }   
    int ans = INF;
    for (int i = 0; i < 3; ++i) for (int j = 0; j < 2; ++j) ans = min(ans, dp[n][i][j]);
    cout << ans << '\n';
}                        
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 47352 KB Output is correct
2 Correct 39 ms 47224 KB Output is correct
3 Correct 39 ms 47224 KB Output is correct
4 Correct 39 ms 47328 KB Output is correct
5 Correct 39 ms 47348 KB Output is correct
6 Correct 39 ms 47352 KB Output is correct
7 Correct 39 ms 47224 KB Output is correct
8 Correct 39 ms 47228 KB Output is correct
9 Correct 39 ms 47352 KB Output is correct
10 Correct 39 ms 47224 KB Output is correct
11 Correct 39 ms 47312 KB Output is correct
12 Correct 39 ms 47352 KB Output is correct
13 Correct 39 ms 47224 KB Output is correct
14 Correct 39 ms 47352 KB Output is correct
15 Correct 39 ms 47352 KB Output is correct
16 Correct 39 ms 47224 KB Output is correct
17 Correct 39 ms 47224 KB Output is correct
18 Correct 39 ms 47224 KB Output is correct
19 Correct 39 ms 47224 KB Output is correct
20 Correct 39 ms 47352 KB Output is correct
21 Correct 39 ms 47228 KB Output is correct
22 Correct 39 ms 47224 KB Output is correct
23 Correct 39 ms 47264 KB Output is correct
24 Correct 39 ms 47228 KB Output is correct
25 Correct 39 ms 47324 KB Output is correct
26 Correct 39 ms 47356 KB Output is correct
27 Correct 39 ms 47224 KB Output is correct
28 Correct 39 ms 47352 KB Output is correct
29 Correct 39 ms 47228 KB Output is correct
30 Correct 39 ms 47224 KB Output is correct
31 Correct 39 ms 47328 KB Output is correct
32 Correct 39 ms 47228 KB Output is correct
33 Correct 39 ms 47336 KB Output is correct
34 Correct 39 ms 47224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 47352 KB Output is correct
2 Correct 39 ms 47224 KB Output is correct
3 Correct 39 ms 47224 KB Output is correct
4 Correct 39 ms 47328 KB Output is correct
5 Correct 39 ms 47348 KB Output is correct
6 Correct 39 ms 47352 KB Output is correct
7 Correct 39 ms 47224 KB Output is correct
8 Correct 39 ms 47228 KB Output is correct
9 Correct 39 ms 47352 KB Output is correct
10 Correct 39 ms 47224 KB Output is correct
11 Correct 39 ms 47312 KB Output is correct
12 Correct 39 ms 47352 KB Output is correct
13 Correct 39 ms 47224 KB Output is correct
14 Correct 39 ms 47352 KB Output is correct
15 Correct 39 ms 47352 KB Output is correct
16 Correct 39 ms 47224 KB Output is correct
17 Correct 39 ms 47224 KB Output is correct
18 Correct 39 ms 47224 KB Output is correct
19 Correct 39 ms 47224 KB Output is correct
20 Correct 39 ms 47352 KB Output is correct
21 Correct 39 ms 47228 KB Output is correct
22 Correct 39 ms 47224 KB Output is correct
23 Correct 39 ms 47264 KB Output is correct
24 Correct 39 ms 47228 KB Output is correct
25 Correct 39 ms 47324 KB Output is correct
26 Correct 39 ms 47356 KB Output is correct
27 Correct 39 ms 47224 KB Output is correct
28 Correct 39 ms 47352 KB Output is correct
29 Correct 39 ms 47228 KB Output is correct
30 Correct 39 ms 47224 KB Output is correct
31 Correct 39 ms 47328 KB Output is correct
32 Correct 39 ms 47228 KB Output is correct
33 Correct 39 ms 47336 KB Output is correct
34 Correct 39 ms 47224 KB Output is correct
35 Correct 39 ms 47352 KB Output is correct
36 Correct 39 ms 47316 KB Output is correct
37 Correct 40 ms 47352 KB Output is correct
38 Correct 40 ms 47352 KB Output is correct
39 Correct 39 ms 47300 KB Output is correct
40 Correct 39 ms 47352 KB Output is correct
41 Correct 39 ms 47224 KB Output is correct
42 Correct 46 ms 47352 KB Output is correct
43 Correct 39 ms 47324 KB Output is correct
44 Correct 40 ms 47352 KB Output is correct
45 Correct 39 ms 47324 KB Output is correct
46 Correct 39 ms 47352 KB Output is correct
47 Correct 40 ms 47352 KB Output is correct
48 Correct 39 ms 47352 KB Output is correct
49 Correct 46 ms 47352 KB Output is correct
50 Correct 43 ms 47352 KB Output is correct
51 Correct 39 ms 47284 KB Output is correct
52 Correct 39 ms 47352 KB Output is correct
53 Correct 39 ms 47228 KB Output is correct
54 Correct 39 ms 47352 KB Output is correct
55 Correct 40 ms 47316 KB Output is correct
56 Correct 40 ms 47352 KB Output is correct
57 Correct 39 ms 47228 KB Output is correct
58 Correct 40 ms 47240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 47228 KB Output is correct
2 Correct 38 ms 47228 KB Output is correct
3 Correct 40 ms 47352 KB Output is correct
4 Correct 39 ms 47316 KB Output is correct
5 Correct 39 ms 47384 KB Output is correct
6 Correct 39 ms 47356 KB Output is correct
7 Correct 312 ms 51500 KB Output is correct
8 Correct 318 ms 51532 KB Output is correct
9 Correct 316 ms 51532 KB Output is correct
10 Correct 317 ms 51404 KB Output is correct
11 Correct 317 ms 51472 KB Output is correct
12 Correct 315 ms 51528 KB Output is correct
13 Correct 320 ms 51408 KB Output is correct
14 Correct 312 ms 51400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 47352 KB Output is correct
2 Correct 39 ms 47224 KB Output is correct
3 Correct 39 ms 47224 KB Output is correct
4 Correct 39 ms 47328 KB Output is correct
5 Correct 39 ms 47348 KB Output is correct
6 Correct 39 ms 47352 KB Output is correct
7 Correct 39 ms 47224 KB Output is correct
8 Correct 39 ms 47228 KB Output is correct
9 Correct 39 ms 47352 KB Output is correct
10 Correct 39 ms 47224 KB Output is correct
11 Correct 39 ms 47312 KB Output is correct
12 Correct 39 ms 47352 KB Output is correct
13 Correct 39 ms 47224 KB Output is correct
14 Correct 39 ms 47352 KB Output is correct
15 Correct 39 ms 47352 KB Output is correct
16 Correct 39 ms 47224 KB Output is correct
17 Correct 39 ms 47224 KB Output is correct
18 Correct 39 ms 47224 KB Output is correct
19 Correct 39 ms 47224 KB Output is correct
20 Correct 39 ms 47352 KB Output is correct
21 Correct 39 ms 47228 KB Output is correct
22 Correct 39 ms 47224 KB Output is correct
23 Correct 39 ms 47264 KB Output is correct
24 Correct 39 ms 47228 KB Output is correct
25 Correct 39 ms 47324 KB Output is correct
26 Correct 39 ms 47356 KB Output is correct
27 Correct 39 ms 47224 KB Output is correct
28 Correct 39 ms 47352 KB Output is correct
29 Correct 39 ms 47228 KB Output is correct
30 Correct 39 ms 47224 KB Output is correct
31 Correct 39 ms 47328 KB Output is correct
32 Correct 39 ms 47228 KB Output is correct
33 Correct 39 ms 47336 KB Output is correct
34 Correct 39 ms 47224 KB Output is correct
35 Correct 39 ms 47352 KB Output is correct
36 Correct 39 ms 47316 KB Output is correct
37 Correct 40 ms 47352 KB Output is correct
38 Correct 40 ms 47352 KB Output is correct
39 Correct 39 ms 47300 KB Output is correct
40 Correct 39 ms 47352 KB Output is correct
41 Correct 39 ms 47224 KB Output is correct
42 Correct 46 ms 47352 KB Output is correct
43 Correct 39 ms 47324 KB Output is correct
44 Correct 40 ms 47352 KB Output is correct
45 Correct 39 ms 47324 KB Output is correct
46 Correct 39 ms 47352 KB Output is correct
47 Correct 40 ms 47352 KB Output is correct
48 Correct 39 ms 47352 KB Output is correct
49 Correct 46 ms 47352 KB Output is correct
50 Correct 43 ms 47352 KB Output is correct
51 Correct 39 ms 47284 KB Output is correct
52 Correct 39 ms 47352 KB Output is correct
53 Correct 39 ms 47228 KB Output is correct
54 Correct 39 ms 47352 KB Output is correct
55 Correct 40 ms 47316 KB Output is correct
56 Correct 40 ms 47352 KB Output is correct
57 Correct 39 ms 47228 KB Output is correct
58 Correct 40 ms 47240 KB Output is correct
59 Correct 39 ms 47228 KB Output is correct
60 Correct 38 ms 47228 KB Output is correct
61 Correct 40 ms 47352 KB Output is correct
62 Correct 39 ms 47316 KB Output is correct
63 Correct 39 ms 47384 KB Output is correct
64 Correct 39 ms 47356 KB Output is correct
65 Correct 312 ms 51500 KB Output is correct
66 Correct 318 ms 51532 KB Output is correct
67 Correct 316 ms 51532 KB Output is correct
68 Correct 317 ms 51404 KB Output is correct
69 Correct 317 ms 51472 KB Output is correct
70 Correct 315 ms 51528 KB Output is correct
71 Correct 320 ms 51408 KB Output is correct
72 Correct 312 ms 51400 KB Output is correct
73 Correct 311 ms 51460 KB Output is correct
74 Correct 314 ms 51476 KB Output is correct
75 Correct 308 ms 51396 KB Output is correct
76 Correct 310 ms 51408 KB Output is correct
77 Correct 316 ms 51408 KB Output is correct
78 Correct 314 ms 51432 KB Output is correct
79 Correct 322 ms 51400 KB Output is correct
80 Correct 312 ms 51396 KB Output is correct
81 Correct 315 ms 51400 KB Output is correct
82 Correct 314 ms 51404 KB Output is correct
83 Correct 320 ms 51400 KB Output is correct
84 Correct 320 ms 51348 KB Output is correct
85 Correct 321 ms 51404 KB Output is correct
86 Correct 330 ms 51476 KB Output is correct
87 Correct 321 ms 51600 KB Output is correct
88 Correct 321 ms 51348 KB Output is correct
89 Correct 322 ms 51524 KB Output is correct
90 Correct 322 ms 51480 KB Output is correct
91 Correct 331 ms 51404 KB Output is correct
92 Correct 323 ms 51500 KB Output is correct
93 Correct 329 ms 51528 KB Output is correct
94 Correct 324 ms 51480 KB Output is correct
95 Correct 323 ms 51496 KB Output is correct
96 Correct 324 ms 51396 KB Output is correct
97 Correct 325 ms 51476 KB Output is correct
98 Correct 326 ms 51524 KB Output is correct
99 Correct 324 ms 51404 KB Output is correct
100 Correct 324 ms 51528 KB Output is correct
101 Correct 326 ms 51480 KB Output is correct
102 Correct 327 ms 51532 KB Output is correct