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 <iostream>
#include <vector>
#include <algorithm>
#include <array>
using namespace std;
const int MAXN = 1000007;
int N;
string A, B;
int dp[2][3];
bool toggle[2][3];
void minimize(int &x, int y) { x = (x < y ? x : y); }
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> A >> B;
dp[0][0] = dp[0][1] = MAXN, dp[0][2] = 0;
for (int i = 0; i < N; ++i) {
bool k = i & 1;
dp[k ^ 1][0] = dp[k ^ 1][1] = dp[k ^ 1][2] = MAXN;
toggle[k ^ 1][0] = (B[i] == '1'), toggle[k ^ 1][1] = (B[i] == '0'), toggle[k ^ 1][2] = (A[i] != B[i]);
for (int x = 0; x < 3; ++x) {
for (int y = 0; y < 3; ++y) {
minimize(dp[k ^ 1][y], dp[k][x] + (x != y && y != 2) + (toggle[k][x] == 0 && toggle[k ^ 1][y] == 1));
}
}
}
cout << min({dp[N & 1][0], dp[N & 1][1], dp[N & 1][2]}) << endl;
}
# | 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... |