답안 #729736

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729736 2023-04-24T12:39:57 Z _callmelucian Lamps (JOI19_lamps) C++14
100 / 100
415 ms 74756 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define NL "\n"
#define SP " "
#define fmax(a, b) a = max(a, b)
#define fmin(a, b) a = min(a, b)
#define all(v) v.begin(), v.end()

const int mn = 1e6 + 1;
int dp[mn][3][2][3];
bool A[mn], B[mn];

int cost1 (int a, int b) {
    if (b == 0 || a == b) return 0;
    return 1;
}

int cost2 (int a, int b) {
    if (b == 2 || a == b) return 0;
    return 1;
}

void update (int i, int j, int k, int l) {
    for (int j2 = 0; j2 < 3; j2++) {
        for (int k2 = 0; k2 < 2; k2++) {
            for (int l2 = 0; l2 < 3; l2++) {
                if (dp[i - 1][j2][k2][l2] == INT_MAX) continue;
                dp[i][j][k][l] = min(dp[i][j][k][l], dp[i - 1][j2][k2][l2] + cost2(j2, j) + cost1(k2, k) + cost2(l2, l));
            }
        }
    }
    return;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        char c; cin >> c;
        if (c == '1') A[i] = 1;
    }
    for (int i = 1; i <= n; i++) {
        char c; cin >> c;
        if (c == '1') B[i] = 1;
    }

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 2; k++) {
                for (int l = 0; l < 3; l++) dp[i][j][k][l] = INT_MAX;
            }
        }
    }
    dp[0][2][0][2] = 0;
    for (int i = 1; i <= n; i++) {
        // xor
        update(i, !B[i], 1, 2);
        update(i, 0, 1, B[i]);
        update(i, 1, 1, B[i]);
        update(i, 2, 1, B[i]);
        if (A[i] != B[i]) update(i, 2, 1, 2);

        // not xor
        update(i, B[i], 0, 2);
        update(i, 0, 0, B[i]);
        update(i, 1, 1, B[i]);
        update(i, 2, 1, B[i]);
        if (A[i] == B[i]) update(i, 2, 0, 2);
    }

    int ans = INT_MAX;
    for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 2; k++) {
            for (int l = 0; l < 3; l++) ans = min(ans, dp[n][j][k][l]);
        }
    }
    cout << ans;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 464 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 464 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 2 ms 464 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 2 ms 464 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 2 ms 456 KB Output is correct
52 Correct 2 ms 468 KB Output is correct
53 Correct 2 ms 452 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 383 ms 71140 KB Output is correct
8 Correct 362 ms 72012 KB Output is correct
9 Correct 366 ms 72124 KB Output is correct
10 Correct 363 ms 72120 KB Output is correct
11 Correct 382 ms 72124 KB Output is correct
12 Correct 362 ms 72108 KB Output is correct
13 Correct 371 ms 71960 KB Output is correct
14 Correct 372 ms 72120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 464 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 464 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 2 ms 464 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 2 ms 464 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 2 ms 456 KB Output is correct
52 Correct 2 ms 468 KB Output is correct
53 Correct 2 ms 452 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 2 ms 468 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 328 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 383 ms 71140 KB Output is correct
66 Correct 362 ms 72012 KB Output is correct
67 Correct 366 ms 72124 KB Output is correct
68 Correct 363 ms 72120 KB Output is correct
69 Correct 382 ms 72124 KB Output is correct
70 Correct 362 ms 72108 KB Output is correct
71 Correct 371 ms 71960 KB Output is correct
72 Correct 372 ms 72120 KB Output is correct
73 Correct 398 ms 73812 KB Output is correct
74 Correct 379 ms 74572 KB Output is correct
75 Correct 377 ms 74700 KB Output is correct
76 Correct 369 ms 74672 KB Output is correct
77 Correct 368 ms 74660 KB Output is correct
78 Correct 364 ms 74572 KB Output is correct
79 Correct 391 ms 74720 KB Output is correct
80 Correct 374 ms 74572 KB Output is correct
81 Correct 371 ms 74700 KB Output is correct
82 Correct 372 ms 74696 KB Output is correct
83 Correct 390 ms 74672 KB Output is correct
84 Correct 402 ms 74672 KB Output is correct
85 Correct 408 ms 74720 KB Output is correct
86 Correct 392 ms 74676 KB Output is correct
87 Correct 395 ms 74676 KB Output is correct
88 Correct 395 ms 74572 KB Output is correct
89 Correct 401 ms 74680 KB Output is correct
90 Correct 384 ms 74676 KB Output is correct
91 Correct 403 ms 74756 KB Output is correct
92 Correct 404 ms 74700 KB Output is correct
93 Correct 415 ms 74572 KB Output is correct
94 Correct 402 ms 74556 KB Output is correct
95 Correct 402 ms 74672 KB Output is correct
96 Correct 406 ms 74676 KB Output is correct
97 Correct 408 ms 74660 KB Output is correct
98 Correct 407 ms 74700 KB Output is correct
99 Correct 413 ms 74676 KB Output is correct
100 Correct 405 ms 74676 KB Output is correct
101 Correct 401 ms 74612 KB Output is correct
102 Correct 409 ms 74700 KB Output is correct