Submission #1151005

#TimeUsernameProblemLanguageResultExecution timeMemory
1151005weakweakweakLamps (JOI19_lamps)C++20
0 / 100
5 ms4248 KiB
#include <bits/stdc++.h>
using namespace std;

int n;
string a, b;
int dp[2100][2] = {0};

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> a >> b;
    for (char &c : a) c -= '0';
    for (char &c : b) c -= '0';
    a = "$"+a, b = "$"+b;
    memset(dp, 63, sizeof(dp));
    dp[0][0] = 0;

    for (int i = 1; i <= n; i++) {
        if (a[i] == b[i]) {
            int z = min(dp[i-1][1], dp[i-1][0]);
            dp[i][0] = min(dp[i][0], z);
        }
        if (b[i] == 0) {
            for (int j = i; j <= n and b[j] == 0; j++) dp[j][0] = min(dp[j][0], min(dp[i-1][0], dp[i-1][0]) + 1 );
            for (int j = i; j <= n and b[j] == 0; j++) dp[j][1] = min(dp[j][1], min(dp[i-1][1], dp[i-1][1]) + 1 );
        }
        if (b[i] == 1) {
            for (int j = i; j <= n and b[j] == 1; j++) dp[j][0] = min(dp[j][0], min(dp[i-1][0], dp[i-1][0]) + 1 );
            for (int j = i; j <= n and b[j] == 1; j++) dp[j][1] = min(dp[j][1], min(dp[i-1][1], dp[i-1][1]) + 1 );
        }
        if (a[i] != b[i]) {
            for (int j = i; j <= n and b[j] != a[j]; j++) dp[j][1] = min(dp[j][1], min(dp[i-1][1], dp[i-1][0]+1));
        } 
    }

    int ans = min(dp[n][0], dp[n][1]);
    cout << ans << '\n';
}
/*
5
01100
11001


01100
11110
11001
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...