Submission #701492

#TimeUsernameProblemLanguageResultExecution timeMemory
701492WeIlIaNLamps (JOI19_lamps)C++14
100 / 100
170 ms59172 KiB
#include <bits/stdc++.h>
using namespace std;
 
 
int n, dp[1000005][3]; string A, B;
 
int main(){
    cin >> n >> A >> B;
    //this allows the indexes to aline.
    A = " " + A; B = " " + B;
    vector<vector<int> > dp(n+5, vector<int>(3, 1e9));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 3; j++){
          bool eq = (j == 0 && A[i] == B[i]) || (j - 1 == B[i] - '0');
          dp[i][j] = min(dp[i][j], dp[i - 1][0] + (A[i - 1] == B[i - 1]) * !eq + (j == 1 || j == 2));
          dp[i][j] = min(dp[i][j], dp[i - 1][1] + (B[i - 1] == '0') * !eq + (j == 2));
          dp[i][j] = min(dp[i][j], dp[i - 1][2] + (B[i - 1] == '1') * !eq + (j == 1));
        }
    }
    cout<<min({dp[n][0], dp[n][1], dp[n][2]})<<endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...