답안 #1083052

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083052 2024-09-02T10:54:09 Z Sharky Lamps (JOI19_lamps) C++17
4 / 100
329 ms 4360 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;
const int inf = 1e9;

int n, dp[2][4][4][4];
char a[N], b[N];

void ckmin(int &x, int y) {
    x = min(x, y);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                for (int l = 0; l < 4; l++) {
                    dp[i][j][k][l] = inf;
                }
            }
        }
    }
    dp[0][3][3][3] = 0;
    vector<array<int, 3>> st;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                if (i == 3 && j < 3) continue;
                if (j == 3 && k < 3) continue;
                if (i != 3 && j != 3 && i == j) continue;
                if (i != 3 && k != 3 && i == k) continue;
                if (j != 3 && k != 3 && j == k) continue;
                st.push_back({i, j, k});
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        int cur = i&1, prev = 1 - cur;
        for (auto& arr : st) {
            int x = arr[0], y = arr[1], z = arr[2];
            dp[cur][x][y][z] = inf;
        }
        for (auto& arr : st) {
            int x = arr[0], y = arr[1], z = arr[2];
            vector<bool> ok(4, 1);
            if (b[i] == '1') ok[0] = 0;
            if (b[i] == '0') ok[1] = 0;
            if (a[i] == b[i]) ok[2] = 0;
            if (a[i] != b[i]) ok[3] = 0;
            for (int j = 0; j < 3; j++) {
                if (!ok[j]) continue;
                if (x == 3) ckmin(dp[cur][j][y][z], dp[prev][x][y][z] + 1);
                else if (j != x && y == 3) ckmin(dp[cur][x][j][z], dp[prev][x][y][z] + 1);
                else if (j != x && j != y && z == 3) ckmin(dp[cur][x][y][j], dp[prev][x][y][z] + 1);
            }
            if (x < 3 && y < 3 && z < 3 && ok[z]) ckmin(dp[cur][x][y][z], dp[prev][x][y][z]);
            else if (x < 3 && y < 3 && z == 3 && ok[y]) ckmin(dp[cur][x][y][z], dp[prev][x][y][z]);
            else if (x < 3 && y == 3 && z == 3 && ok[x]) ckmin(dp[cur][x][y][z], dp[prev][x][y][z]);
            else if (x == 3 && y == 3 && z == 3 && ok[3]) ckmin(dp[cur][x][y][z], dp[prev][x][y][z]);
            if (x < 3 && y < 3 && z < 3 && ok[y]) {
                ckmin(dp[cur][x][y][3], dp[prev][x][y][z]);
            } else if (x < 3 && y < 3 && z == 3 && ok[x]) {
                ckmin(dp[cur][x][3][z], dp[prev][x][y][z]);
            } else if (x < 3 && y == 3 && z == 3 && ok[3]) {
                ckmin(dp[cur][3][y][z], dp[prev][x][y][z]);
            }
        }
    }
    int ans = inf;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                ans = min(ans, dp[n & 1][i][j][k]);
            }
        }
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 472 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Incorrect 0 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 472 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Incorrect 0 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 329 ms 4360 KB Output is correct
8 Correct 317 ms 4188 KB Output is correct
9 Correct 311 ms 4188 KB Output is correct
10 Correct 318 ms 4184 KB Output is correct
11 Correct 316 ms 4180 KB Output is correct
12 Correct 324 ms 4180 KB Output is correct
13 Correct 307 ms 4188 KB Output is correct
14 Correct 313 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 472 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Incorrect 0 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -