Submission #529460

#TimeUsernameProblemLanguageResultExecution timeMemory
5294604fectaLamps (JOI19_lamps)C++17
100 / 100
119 ms51316 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)

const int MN = 1000005;

int n, dp[MN][3][2];
char a[MN], b[MN];

int32_t main() {
    boost();

    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    memset(dp, 0x3f, sizeof(dp));
    dp[0][2][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 2; k++) {
                for (int pj = 0; pj < 3; pj++) {
                    for (int pk = 0; pk < 2; pk++) {
                        int cur = j == 2 ? a[i] - '0' : j, tgt = (b[i] - '0') ^ k;
                        if (cur != tgt) continue;
                        int cost = 0;
                        if (j < 2 && j != pj) cost++;
                        if (k && !pk) cost++;
                        dp[i][j][k] = min(dp[i][j][k], dp[i - 1][pj][pk] + cost);
                    }
                }
            }
        }
    }
    int ans = 0x3f3f3f3f;
    for (int j = 0; j < 3; j++) for (int k = 0; k < 2; k++) ans = min(ans, dp[n][j][k]);
    printf("%lld\n", ans);

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...