#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;
int n;
int dp[MAXN][6];
int A[MAXN], B[MAXN];
string a, b;
int main()
{
cin >> n >> a >> b;
for(int i = 1 ; i <= n ; i++)
{
A[i] = a[i - 1] - '0';
B[i] = b[i - 1] - '0';
}
dp[0][4] = 1;
dp[0][0] = dp[0][1] = 1;
dp[0][2] = dp[0][3] = 2;
for(int i = 1 ; i <= n ; i++)
{
for(int k = 0 ; k < 4 ; k++)
{
int s = 0;
if( k == 1 || k == 2 ) s = 1;
if( B[i] == s ) dp[i][k] = min( dp[i - 1][k] , dp[i - 1][3 - k] + 3 );
else dp[i][k] = min( dp[i - 1][k^2] + 1 , dp[i - 1][k^1] + 2 );
}
if( A[i] == B[i] ) dp[i][4] = min( dp[i - 1][5] + 1 , dp[i - 1][1 - B[i] + 2] + 1 );
else dp[i][4] = min( dp[i - 1][4] , dp[i - 1][ B[i] ] + 2 );
if( A[i] == B[i] ) dp[i][5] = min( dp[i - 1][5] , dp[i - 1][ 1 - B[i] + 2 ] + 2 );
else dp[i][5] = min( dp[i - 1][4] + 1 , dp[i - 1][ B[i] ] + 1 );
}
printf("%d\n",dp[n][5]/2);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
73 ms |
33756 KB |
Output is correct |
8 |
Correct |
73 ms |
33756 KB |
Output is correct |
9 |
Correct |
73 ms |
33760 KB |
Output is correct |
10 |
Correct |
73 ms |
33756 KB |
Output is correct |
11 |
Correct |
75 ms |
33760 KB |
Output is correct |
12 |
Correct |
73 ms |
33760 KB |
Output is correct |
13 |
Correct |
74 ms |
33756 KB |
Output is correct |
14 |
Correct |
73 ms |
33756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |