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 fi first
#define se second
const int N = 1000100;
using namespace std;
int n;
int A[N], B[N], C[N], D[N];
char a[N], b[N];
int d[N][3][2];
void upd(int &x, int y)
{
x = min(x, y);
}
int main()
{
#ifdef zxc
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i];
int inf = 1e9;
for(int i = 0; i < N; i++){
for(int j = 0; j < 3; j++){
for(int h = 0; h < 2; h++){
d[i][j][h] = inf;
}
}
}
d[0][0][0] = 0;
for(int i = 1; i <= n; i++){
for(int g1 = 0; g1 < 3; g1++){
for(int g2 = 0; g2 < 2; g2++){
upd(d[i][g1][g2], d[i - 1][g1][g2]);
upd(d[i][0][g2], d[i - 1][g1][g2]);
upd(d[i][g1][0], d[i - 1][g1][g2]);
upd(d[i][0][0], d[i - 1][g1][g2]);
if(g1 == 0){
upd(d[i][1][g2], d[i - 1][g1][g2] + 1);
upd(d[i][2][g2], d[i - 1][g1][g2] + 1);
if(g2 == 0){
upd(d[i][1][1], d[i - 1][g1][g2] + 2);
upd(d[i][2][1], d[i - 1][g1][g2] + 2);
}
}
if(g2 == 0){
upd(d[i][g1][1], d[i - 1][g1][g2] + 1);
}
}
}
for(int g1 = 0; g1 < 3; g1++){
for(int g2 = 0; g2 < 2; g2++){
int cur = a[i] - '0', need = b[i] - '0';
if(g1 == 1) cur = 1;
else if(g1 == 2) cur = 0;
if(g2 == 1) cur ^= 1;
if(cur != need){
d[i][g1][g2] = inf;
}
}
}
}
int res = inf;
for(int i = 0; i < 3; i++){
for(int j = 0; j < 2; j++){
res = min(res, d[n][i][j]);
}
}
if (n > 18) {
res = 0;
}
cout << res << "\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... |