#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 1e6 + 7, inf = 1e9 + 7;
int n, dp[mxN][10];
string s, t;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
cin >> n;
cin >> s;
cin >> t;
s = '0' + s;
t = '0' + t;
for (int i = 0; i <= n; i++)
{
for (int j = 0; j < 8; j++)
dp[i][j] = inf;
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++)
{
if (s[i] == t[i])
dp[i][0] = dp[i - 1][0];
else
dp[i][3] = min(dp[i - 1][0] + 1, dp[i - 1][3]);
if (t[i] == '1')
{
dp[i][1] = min({dp[i - 1][0] + 1, dp[i - 1][1]});
dp[i][4] = min({dp[i - 1][1] + 1, dp[i - 1][3] + 1, dp[i - 1][4]});
dp[i][7] = min({dp[i - 1][2] + 1, dp[i - 1][3] + 1, dp[i - 1][7]});
}
else
{
dp[i][2] = min(dp[i - 1][0] + 1, dp[i - 1][2]);
dp[i][5] = min({dp[i - 1][3] + 1, dp[i - 1][2] + 1, dp[i - 1][5]});
dp[i][6] = min({dp[i - 1][1] + 1, dp[i - 1][3] + 1, dp[i - 1][6]});
}
for (int j = 4; j <= 7; j++)
dp[i][3] = min(dp[i][3], dp[i][j]);
dp[i][2] = min({dp[i][2], dp[i][5], dp[i][7]});
dp[i][1] = min({dp[i][1], dp[i][4], dp[i][6]});
dp[i][0] = min({dp[i][0], dp[i][1], dp[i][2], dp[i][3]});
}
cout << dp[n][0];
}
# | 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... |