#include <bits/stdc++.h>
#define N 1000005
#define INF 1000000000
using namespace std;
void chmin(int& a, int v) {
a = min(a,v);
}
/*
0 - none
1 - flip
2 - ons
3 - offs
4 - flip, ons
5 - flip, offs
6 - ons, flip
7 - offs, flip
*/
int n, dp[N][8];
string A, B;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> A >> B;
for(auto&i: dp) for(auto&j: i) j = INF;
dp[0][0] = 0;
for(int i = 0; i < n; i ++) {
if(A[i] == B[i]) {
chmin(dp[i+1][0],min({dp[i][0],dp[i][1],dp[i][2],dp[i][3],dp[i][4],dp[i][5],dp[i][6],dp[i][7]}));
} else {
chmin(dp[i+1][1],min({dp[i][0]+1,dp[i][1],dp[i][2]+1,dp[i][3]+1,dp[i][4],dp[i][5],dp[i][6],dp[i][7]}));
}
if(B[i] == '1') {
chmin(dp[i+1][2],min({dp[i][0]+1,dp[i][1]+1,dp[i][2],dp[i][3]+1,dp[i][4],dp[i][5]+1,dp[i][6],dp[i][7]+1}));
chmin(dp[i+1][6],min({dp[i][0]+2,dp[i][1]+1,dp[i][2]+2,dp[i][3]+2,dp[i][4]+1,dp[i][5]+1,dp[i][6],dp[i][7]+1}));
chmin(dp[i+1][5],min({dp[i][0]+2,dp[i][1]+2,dp[i][2]+2,dp[i][3]+1,dp[i][4]+2,dp[i][5],dp[i][6]+2,dp[i][7]+1}));
} else {
chmin(dp[i+1][3],min({dp[i][0]+1,dp[i][1]+1,dp[i][2]+1,dp[i][3],dp[i][4]+1,dp[i][5],dp[i][6]+1,dp[i][7]}));
chmin(dp[i+1][4],min({dp[i][0]+2,dp[i][1]+2,dp[i][2]+1,dp[i][3]+2,dp[i][4],dp[i][5]+2,dp[i][6]+1,dp[i][7]+2}));
chmin(dp[i+1][7],min({dp[i][0]+2,dp[i][1]+1,dp[i][2]+2,dp[i][3]+2,dp[i][4]+1,dp[i][5]+1,dp[i][6]+1,dp[i][7]}));
}
}
int ans = INF;
for(int i = 0; i < 8; i ++) {
ans = min(ans, dp[n][i]);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
31584 KB |
Output is correct |
2 |
Correct |
11 ms |
31584 KB |
Output is correct |
3 |
Correct |
13 ms |
31576 KB |
Output is correct |
4 |
Correct |
13 ms |
31580 KB |
Output is correct |
5 |
Correct |
13 ms |
31580 KB |
Output is correct |
6 |
Correct |
16 ms |
31532 KB |
Output is correct |
7 |
Correct |
14 ms |
31832 KB |
Output is correct |
8 |
Correct |
13 ms |
31580 KB |
Output is correct |
9 |
Correct |
11 ms |
31580 KB |
Output is correct |
10 |
Correct |
12 ms |
31772 KB |
Output is correct |
11 |
Correct |
13 ms |
31576 KB |
Output is correct |
12 |
Correct |
11 ms |
31580 KB |
Output is correct |
13 |
Correct |
15 ms |
31664 KB |
Output is correct |
14 |
Correct |
11 ms |
31580 KB |
Output is correct |
15 |
Correct |
12 ms |
31580 KB |
Output is correct |
16 |
Correct |
13 ms |
31760 KB |
Output is correct |
17 |
Correct |
12 ms |
31576 KB |
Output is correct |
18 |
Correct |
11 ms |
31580 KB |
Output is correct |
19 |
Correct |
12 ms |
31588 KB |
Output is correct |
20 |
Correct |
13 ms |
31580 KB |
Output is correct |
21 |
Correct |
11 ms |
31664 KB |
Output is correct |
22 |
Correct |
11 ms |
31580 KB |
Output is correct |
23 |
Correct |
14 ms |
31696 KB |
Output is correct |
24 |
Correct |
12 ms |
31580 KB |
Output is correct |
25 |
Correct |
13 ms |
31664 KB |
Output is correct |
26 |
Correct |
13 ms |
31580 KB |
Output is correct |
27 |
Correct |
16 ms |
31704 KB |
Output is correct |
28 |
Correct |
13 ms |
31580 KB |
Output is correct |
29 |
Correct |
13 ms |
31684 KB |
Output is correct |
30 |
Correct |
12 ms |
31764 KB |
Output is correct |
31 |
Correct |
13 ms |
31580 KB |
Output is correct |
32 |
Correct |
12 ms |
31552 KB |
Output is correct |
33 |
Correct |
12 ms |
31592 KB |
Output is correct |
34 |
Correct |
12 ms |
31580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
31584 KB |
Output is correct |
2 |
Correct |
11 ms |
31584 KB |
Output is correct |
3 |
Correct |
13 ms |
31576 KB |
Output is correct |
4 |
Correct |
13 ms |
31580 KB |
Output is correct |
5 |
Correct |
13 ms |
31580 KB |
Output is correct |
6 |
Correct |
16 ms |
31532 KB |
Output is correct |
7 |
Correct |
14 ms |
31832 KB |
Output is correct |
8 |
Correct |
13 ms |
31580 KB |
Output is correct |
9 |
Correct |
11 ms |
31580 KB |
Output is correct |
10 |
Correct |
12 ms |
31772 KB |
Output is correct |
11 |
Correct |
13 ms |
31576 KB |
Output is correct |
12 |
Correct |
11 ms |
31580 KB |
Output is correct |
13 |
Correct |
15 ms |
31664 KB |
Output is correct |
14 |
Correct |
11 ms |
31580 KB |
Output is correct |
15 |
Correct |
12 ms |
31580 KB |
Output is correct |
16 |
Correct |
13 ms |
31760 KB |
Output is correct |
17 |
Correct |
12 ms |
31576 KB |
Output is correct |
18 |
Correct |
11 ms |
31580 KB |
Output is correct |
19 |
Correct |
12 ms |
31588 KB |
Output is correct |
20 |
Correct |
13 ms |
31580 KB |
Output is correct |
21 |
Correct |
11 ms |
31664 KB |
Output is correct |
22 |
Correct |
11 ms |
31580 KB |
Output is correct |
23 |
Correct |
14 ms |
31696 KB |
Output is correct |
24 |
Correct |
12 ms |
31580 KB |
Output is correct |
25 |
Correct |
13 ms |
31664 KB |
Output is correct |
26 |
Correct |
13 ms |
31580 KB |
Output is correct |
27 |
Correct |
16 ms |
31704 KB |
Output is correct |
28 |
Correct |
13 ms |
31580 KB |
Output is correct |
29 |
Correct |
13 ms |
31684 KB |
Output is correct |
30 |
Correct |
12 ms |
31764 KB |
Output is correct |
31 |
Correct |
13 ms |
31580 KB |
Output is correct |
32 |
Correct |
12 ms |
31552 KB |
Output is correct |
33 |
Correct |
12 ms |
31592 KB |
Output is correct |
34 |
Correct |
12 ms |
31580 KB |
Output is correct |
35 |
Correct |
13 ms |
31580 KB |
Output is correct |
36 |
Correct |
12 ms |
31572 KB |
Output is correct |
37 |
Correct |
12 ms |
31580 KB |
Output is correct |
38 |
Correct |
13 ms |
31580 KB |
Output is correct |
39 |
Correct |
13 ms |
31576 KB |
Output is correct |
40 |
Incorrect |
13 ms |
31580 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
31580 KB |
Output is correct |
2 |
Correct |
13 ms |
31580 KB |
Output is correct |
3 |
Correct |
12 ms |
31676 KB |
Output is correct |
4 |
Correct |
12 ms |
31580 KB |
Output is correct |
5 |
Correct |
12 ms |
31536 KB |
Output is correct |
6 |
Correct |
13 ms |
31576 KB |
Output is correct |
7 |
Correct |
35 ms |
35744 KB |
Output is correct |
8 |
Correct |
37 ms |
35708 KB |
Output is correct |
9 |
Correct |
32 ms |
35752 KB |
Output is correct |
10 |
Correct |
34 ms |
35756 KB |
Output is correct |
11 |
Correct |
32 ms |
35748 KB |
Output is correct |
12 |
Correct |
33 ms |
35760 KB |
Output is correct |
13 |
Correct |
34 ms |
35744 KB |
Output is correct |
14 |
Correct |
34 ms |
35748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
31584 KB |
Output is correct |
2 |
Correct |
11 ms |
31584 KB |
Output is correct |
3 |
Correct |
13 ms |
31576 KB |
Output is correct |
4 |
Correct |
13 ms |
31580 KB |
Output is correct |
5 |
Correct |
13 ms |
31580 KB |
Output is correct |
6 |
Correct |
16 ms |
31532 KB |
Output is correct |
7 |
Correct |
14 ms |
31832 KB |
Output is correct |
8 |
Correct |
13 ms |
31580 KB |
Output is correct |
9 |
Correct |
11 ms |
31580 KB |
Output is correct |
10 |
Correct |
12 ms |
31772 KB |
Output is correct |
11 |
Correct |
13 ms |
31576 KB |
Output is correct |
12 |
Correct |
11 ms |
31580 KB |
Output is correct |
13 |
Correct |
15 ms |
31664 KB |
Output is correct |
14 |
Correct |
11 ms |
31580 KB |
Output is correct |
15 |
Correct |
12 ms |
31580 KB |
Output is correct |
16 |
Correct |
13 ms |
31760 KB |
Output is correct |
17 |
Correct |
12 ms |
31576 KB |
Output is correct |
18 |
Correct |
11 ms |
31580 KB |
Output is correct |
19 |
Correct |
12 ms |
31588 KB |
Output is correct |
20 |
Correct |
13 ms |
31580 KB |
Output is correct |
21 |
Correct |
11 ms |
31664 KB |
Output is correct |
22 |
Correct |
11 ms |
31580 KB |
Output is correct |
23 |
Correct |
14 ms |
31696 KB |
Output is correct |
24 |
Correct |
12 ms |
31580 KB |
Output is correct |
25 |
Correct |
13 ms |
31664 KB |
Output is correct |
26 |
Correct |
13 ms |
31580 KB |
Output is correct |
27 |
Correct |
16 ms |
31704 KB |
Output is correct |
28 |
Correct |
13 ms |
31580 KB |
Output is correct |
29 |
Correct |
13 ms |
31684 KB |
Output is correct |
30 |
Correct |
12 ms |
31764 KB |
Output is correct |
31 |
Correct |
13 ms |
31580 KB |
Output is correct |
32 |
Correct |
12 ms |
31552 KB |
Output is correct |
33 |
Correct |
12 ms |
31592 KB |
Output is correct |
34 |
Correct |
12 ms |
31580 KB |
Output is correct |
35 |
Correct |
13 ms |
31580 KB |
Output is correct |
36 |
Correct |
12 ms |
31572 KB |
Output is correct |
37 |
Correct |
12 ms |
31580 KB |
Output is correct |
38 |
Correct |
13 ms |
31580 KB |
Output is correct |
39 |
Correct |
13 ms |
31576 KB |
Output is correct |
40 |
Incorrect |
13 ms |
31580 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |