Submission #794644

#TimeUsernameProblemLanguageResultExecution timeMemory
794644phoenixLamps (JOI19_lamps)C++17
100 / 100
136 ms4468 KiB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

const int INF = 1e9;

int n;
string s, t;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n;
    cin >> s;
    cin >> t;
    vector<vector<int>> dp(3, vector<int>(2, INF));
    dp[0][0] = 0;
    for(int i = 0; i < n; i++) {
        vector<vector<int>> newdp(3, vector<int>(2, INF));
        for(int op1 = 0; op1 < 3; op1++) {
            for(int x1 = 0; x1 < 2; x1++) {
                char x = s[i];
                if(op1) x = op1 - 1 + '0';
                if(x1) x = (x == '0' ? '1' : '0');
                if(x != t[i]) continue;
                for(int op2 = 0; op2 < 3; op2++) {
                    for(int x2 = 0; x2 < 2; x2++) {
                        int w = (op1 && op1 != op2) + (x1 && x1 != x2);
                        newdp[op1][x1] = min(dp[op2][x2] + w, newdp[op1][x1]);
                    }
                }
            }
        }
        dp = newdp;
    }
    int ans = INF;
    for(int x = 0; x < 3; x++) {
        for(int y = 0; y < 2; y++) {
            ans = min(ans, dp[x][y]);
        }
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...