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>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 1'000'010;
int dp[N][3][2];
string s, t;
int n;
void update(int i, int op, int dif)
{
int x = dp[i][0][ '0' != t[i]] + (op != 0) + (!dif && '0' != t[i]);
int y = dp[i][1][ '1' != t[i]] + (op != 1) + (!dif && '1' != t[i]);
int z = dp[i][2][s[i] != t[i]] + ( 0) + (!dif && s[i] != t[i]);
dp[i+1][op][dif] = min({x, y, z});
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> s >> t;
Loop (i,0,n) {
Loop (op,0,3) {
Loop (dif,0,2) {
update(i, op, dif);
}
}
}
cout << dp[n][2][0] << '\n';
}
# | 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... |