답안 #747038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747038 2023-05-23T13:00:29 Z stevancv Lamps (JOI19_lamps) C++14
4 / 100
74 ms 35780 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e6 + 2;
const int inf = 1e9;
int dp[N][2][3], a[N], b[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    string A, B;
    cin >> A >> B;
    for (int i = 0; i < n; i++) {
        a[i + 1] = A[i] - '0';
        b[i + 1] = B[i] - '0';
    }
    for (int i = 0; i <= n; i++) for (int j = 0; j < 6; j++) dp[i][j / 3][j % 3] = inf;
    dp[0][0][0] = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == b[i]) for (int j = 0; j < 6; j++) smin(dp[i][0][0], dp[i - 1][j / 3][j % 3]);
        if (b[i] == 0) for (int j = 0; j < 6; j++) smin(dp[i][0][1], dp[i - 1][j / 3][j % 3] + (j % 3 != 1));
        if (b[i] == 1) for (int j = 0; j < 6; j++) smin(dp[i][0][2], dp[i - 1][j / 3][j % 3] + (j % 3 != 2));
        if (a[i] != b[i]) for (int j = 0; j < 6; j++) smin(dp[i][1][0], dp[i - 1][j / 3][j % 3] + (j < 3));
        if (b[i] == 0) for (int j = 0; j < 6; j++) smin(dp[i][1][1], dp[i - 1][j / 3][j % 3] + (j % 3 != 1) + (j < 3));
        if (b[i] == 1) for (int j = 0; j < 6; j++) smin(dp[i][1][2], dp[i - 1][j / 3][j % 3] + (j % 3 != 2) + (j < 3));
    }
    int ans = inf;
    for (int j = 0; j < 6; j++) smin(ans, dp[n][j / 3][j % 3]);
    cout << ans << en;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 332 KB Output is correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 332 KB Output is correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 63 ms 35684 KB Output is correct
8 Correct 69 ms 35692 KB Output is correct
9 Correct 74 ms 35628 KB Output is correct
10 Correct 68 ms 35612 KB Output is correct
11 Correct 63 ms 35680 KB Output is correct
12 Correct 65 ms 35600 KB Output is correct
13 Correct 60 ms 35684 KB Output is correct
14 Correct 64 ms 35780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 332 KB Output is correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Halted 0 ms 0 KB -