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;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string s1, s2;
cin >> s1 >> s2;
s1 = "." + s1;
s2 = "." + s2;
ll dp[n + 10][3][2];
for (int i = 0; i <= n; i++)
for (int j = 0; j < 3; j++)
for (int l = 0; l < 2; l++) dp[i][j][l] = 1e12;
dp[0][0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 3; j++) {
for (int l = 0; l < 2; l++) {
int val = s1[i] - '0';
if (j == 1) val = 0;
if (j == 2) val = 1;
if (l == 1) val ^= 1;
if (val != s2[i] - '0') continue;
for (int prevJ = 0; prevJ < 3; prevJ++)
for (int prevL = 0; prevL < 2; prevL++)
dp[i][j][l] = min(dp[i][j][l], dp[i - 1][prevJ][prevL] + (j > 0 && j != prevJ) + (l > 0 && l != prevL));
}
}
}
ll ans = 1e12;
for (int j = 0; j < 3; j++)
for (int l = 0; l < 2; l++) ans = min(ans, dp[n][j][l]);
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... |