답안 #428825

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
428825 2021-06-15T14:43:14 Z tengiz05 Lamps (JOI19_lamps) C++17
4 / 100
131 ms 35596 KB
#include <bits/stdc++.h>
constexpr int N = 1000000;
int dp[N + 1][2][2][2];
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;
    std::cin >> n;
    std::string a, b;
    std::cin >> a >> b;
    a = "#" + a;
    b = "#" + b;
    // [pos][0][1][xor]
    memset(dp, 0x3f, sizeof dp);
    dp[0][0][0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int a0 = 0; a0 < 2; a0++)
            for (int a1 = 0; a1 < 2; a1++)
                for (int xr = 0; xr < 2; xr++) {
                    char t = a[i];
                    if (a0) t = '0';
                    if (a1) t = '1';
                    if (xr) t ^= 1;
                    if (t != b[i]) {
                        continue;
                    }
                    int &ret = dp[i][a0][a1][xr];
                    ret = dp[i - 1][a0][a1][xr] - a0 - a1 - xr;
                    ret = std::min(ret, dp[i - 1][0][a1][xr] - a1 - xr);
                    ret = std::min(ret, dp[i - 1][a0][0][xr] - a0 - xr);
                    ret = std::min(ret, dp[i - 1][0][0][xr] - xr);
                    ret = std::min(ret, dp[i - 1][0][a1][0] - a1);
                    ret = std::min(ret, dp[i - 1][a0][0][0] - a0);
                    ret = std::min(ret, dp[i - 1][0][0][0]);
                    ret = std::min(ret, dp[i - 1][1][a1][xr] - (a0 == 1) - a1 - xr);
                    ret = std::min(ret, dp[i - 1][a0][1][xr] - a0 - (a1 == 1) - xr);
                    ret = std::min(ret, dp[i - 1][1][1][xr] - (a0 == 1) - (a1 == 1) - xr);
                    ret = std::min(ret, dp[i - 1][1][a1][1] - (a0 == 1) - a1 - (xr == 1));
                    ret = std::min(ret, dp[i - 1][a0][1][1] - a0 - (a1 == 1) - (xr == 1));
                    ret = std::min(ret, dp[i - 1][1][1][1] - (a0 == 1) - (a1 == 1) - (xr == 1));
                    ret += a0 + a1 + xr;
                }
    }
    int ans = n;
    for (int a0 = 0; a0 < 2; a0++)
        for (int a1 = 0; a1 < 2; a1++)
            for (int xr = 0; xr < 2; xr++)
                ans = std::min(ans, dp[n][a0][a1][xr]);
    std::cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 31556 KB Output is correct
2 Correct 18 ms 31564 KB Output is correct
3 Correct 14 ms 31564 KB Output is correct
4 Correct 14 ms 31508 KB Output is correct
5 Correct 15 ms 31556 KB Output is correct
6 Correct 17 ms 31516 KB Output is correct
7 Correct 16 ms 31564 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 17 ms 31508 KB Output is correct
10 Correct 15 ms 31564 KB Output is correct
11 Correct 18 ms 31560 KB Output is correct
12 Correct 15 ms 31604 KB Output is correct
13 Correct 17 ms 31568 KB Output is correct
14 Correct 16 ms 31576 KB Output is correct
15 Correct 17 ms 31564 KB Output is correct
16 Incorrect 15 ms 31628 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 31556 KB Output is correct
2 Correct 18 ms 31564 KB Output is correct
3 Correct 14 ms 31564 KB Output is correct
4 Correct 14 ms 31508 KB Output is correct
5 Correct 15 ms 31556 KB Output is correct
6 Correct 17 ms 31516 KB Output is correct
7 Correct 16 ms 31564 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 17 ms 31508 KB Output is correct
10 Correct 15 ms 31564 KB Output is correct
11 Correct 18 ms 31560 KB Output is correct
12 Correct 15 ms 31604 KB Output is correct
13 Correct 17 ms 31568 KB Output is correct
14 Correct 16 ms 31576 KB Output is correct
15 Correct 17 ms 31564 KB Output is correct
16 Incorrect 15 ms 31628 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 31592 KB Output is correct
2 Correct 15 ms 31544 KB Output is correct
3 Correct 18 ms 31572 KB Output is correct
4 Correct 15 ms 31584 KB Output is correct
5 Correct 18 ms 31580 KB Output is correct
6 Correct 16 ms 31596 KB Output is correct
7 Correct 104 ms 35512 KB Output is correct
8 Correct 104 ms 35528 KB Output is correct
9 Correct 131 ms 35412 KB Output is correct
10 Correct 99 ms 35444 KB Output is correct
11 Correct 113 ms 35596 KB Output is correct
12 Correct 109 ms 35472 KB Output is correct
13 Correct 100 ms 35516 KB Output is correct
14 Correct 100 ms 35536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 31556 KB Output is correct
2 Correct 18 ms 31564 KB Output is correct
3 Correct 14 ms 31564 KB Output is correct
4 Correct 14 ms 31508 KB Output is correct
5 Correct 15 ms 31556 KB Output is correct
6 Correct 17 ms 31516 KB Output is correct
7 Correct 16 ms 31564 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 17 ms 31508 KB Output is correct
10 Correct 15 ms 31564 KB Output is correct
11 Correct 18 ms 31560 KB Output is correct
12 Correct 15 ms 31604 KB Output is correct
13 Correct 17 ms 31568 KB Output is correct
14 Correct 16 ms 31576 KB Output is correct
15 Correct 17 ms 31564 KB Output is correct
16 Incorrect 15 ms 31628 KB Output isn't correct
17 Halted 0 ms 0 KB -