#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=1e6;
int n, dp[mxN][3]; // use 0, use 1, use nothing
string a, b;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
memset(dp, 0x3f, sizeof(dp));
dp[0][0]=(a[0]!=b[0]);
dp[0][1]=1+(b[0]=='1');
dp[0][2]=1+(b[0]=='0');
for (int i=1; i<n; ++i) {
for (int j=0; j<3; ++j) {
for (int k=0; k<3; ++k) {
int dif1=j==1?b[i-1]=='1':j==2?b[i-1]=='0':b[i-1]!=a[i-1];
int dif2=k==1?b[i]=='1':k==2?b[i]=='0':b[i]!=a[i];
dp[i][k]=min(dp[i][k], dp[i-1][j]+(k>0&&j!=k)+(dif2&&!dif1));
}
}
}
cout << min({dp[n-1][0], dp[n-1][1], dp[n-2][2]});
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
11988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
11988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11944 KB |
Output is correct |
2 |
Incorrect |
5 ms |
11976 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
11988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |