This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |