#include <bits/stdc++.h>
using namespace std ;
const int MAX = 1e6 + 10 ;
int arr[MAX] ;
int n ;
int dp[MAX][3] ;
string s , t ;
int solve(int idx , int cur)
{
if(idx == n)
return 0 ;
int &ret = dp[idx][cur] ;
if(ret != -1)
return ret ;
ret = 1e9 ;
bool prvflip = false ;
char c = '0' + cur ;
if(idx && cur == 2)
c = s[idx-1] ;
if(idx && c != t[idx-1])
prvflip = true ;
for(int i = 0 ; i <= 2 ; ++i)
{
c = '0' + i ;
if(i == 2)
c = s[idx] ;
bool curflip = (c != t[idx]) ;
ret = min(ret , solve(idx+1 , i) + (curflip && !prvflip) + (i != 2 && i != cur)) ;
}
return ret ;
}
int main()
{
memset(dp , -1 , sizeof(dp)) ;
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n ;
cin>>s ;
cin>>t ;
return cout<<solve(0 , 2)<<"\n" , 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
11988 KB |
Output is correct |
2 |
Correct |
5 ms |
11988 KB |
Output is correct |
3 |
Correct |
5 ms |
11988 KB |
Output is correct |
4 |
Correct |
5 ms |
12080 KB |
Output is correct |
5 |
Correct |
4 ms |
12072 KB |
Output is correct |
6 |
Correct |
4 ms |
11988 KB |
Output is correct |
7 |
Correct |
5 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
12116 KB |
Output is correct |
9 |
Correct |
5 ms |
11988 KB |
Output is correct |
10 |
Correct |
5 ms |
12076 KB |
Output is correct |
11 |
Correct |
5 ms |
11988 KB |
Output is correct |
12 |
Correct |
5 ms |
11988 KB |
Output is correct |
13 |
Correct |
5 ms |
12056 KB |
Output is correct |
14 |
Correct |
5 ms |
11988 KB |
Output is correct |
15 |
Correct |
5 ms |
11988 KB |
Output is correct |
16 |
Correct |
5 ms |
11988 KB |
Output is correct |
17 |
Correct |
5 ms |
11988 KB |
Output is correct |
18 |
Correct |
5 ms |
11988 KB |
Output is correct |
19 |
Correct |
6 ms |
12076 KB |
Output is correct |
20 |
Correct |
5 ms |
11988 KB |
Output is correct |
21 |
Correct |
6 ms |
11988 KB |
Output is correct |
22 |
Correct |
5 ms |
11988 KB |
Output is correct |
23 |
Correct |
4 ms |
11988 KB |
Output is correct |
24 |
Correct |
5 ms |
12072 KB |
Output is correct |
25 |
Correct |
5 ms |
11988 KB |
Output is correct |
26 |
Correct |
5 ms |
11988 KB |
Output is correct |
27 |
Correct |
5 ms |
12076 KB |
Output is correct |
28 |
Correct |
4 ms |
11988 KB |
Output is correct |
29 |
Correct |
5 ms |
12076 KB |
Output is correct |
30 |
Correct |
5 ms |
12072 KB |
Output is correct |
31 |
Correct |
6 ms |
11988 KB |
Output is correct |
32 |
Correct |
6 ms |
12076 KB |
Output is correct |
33 |
Correct |
4 ms |
11988 KB |
Output is correct |
34 |
Correct |
4 ms |
12080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
11988 KB |
Output is correct |
2 |
Correct |
5 ms |
11988 KB |
Output is correct |
3 |
Correct |
5 ms |
11988 KB |
Output is correct |
4 |
Correct |
5 ms |
12080 KB |
Output is correct |
5 |
Correct |
4 ms |
12072 KB |
Output is correct |
6 |
Correct |
4 ms |
11988 KB |
Output is correct |
7 |
Correct |
5 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
12116 KB |
Output is correct |
9 |
Correct |
5 ms |
11988 KB |
Output is correct |
10 |
Correct |
5 ms |
12076 KB |
Output is correct |
11 |
Correct |
5 ms |
11988 KB |
Output is correct |
12 |
Correct |
5 ms |
11988 KB |
Output is correct |
13 |
Correct |
5 ms |
12056 KB |
Output is correct |
14 |
Correct |
5 ms |
11988 KB |
Output is correct |
15 |
Correct |
5 ms |
11988 KB |
Output is correct |
16 |
Correct |
5 ms |
11988 KB |
Output is correct |
17 |
Correct |
5 ms |
11988 KB |
Output is correct |
18 |
Correct |
5 ms |
11988 KB |
Output is correct |
19 |
Correct |
6 ms |
12076 KB |
Output is correct |
20 |
Correct |
5 ms |
11988 KB |
Output is correct |
21 |
Correct |
6 ms |
11988 KB |
Output is correct |
22 |
Correct |
5 ms |
11988 KB |
Output is correct |
23 |
Correct |
4 ms |
11988 KB |
Output is correct |
24 |
Correct |
5 ms |
12072 KB |
Output is correct |
25 |
Correct |
5 ms |
11988 KB |
Output is correct |
26 |
Correct |
5 ms |
11988 KB |
Output is correct |
27 |
Correct |
5 ms |
12076 KB |
Output is correct |
28 |
Correct |
4 ms |
11988 KB |
Output is correct |
29 |
Correct |
5 ms |
12076 KB |
Output is correct |
30 |
Correct |
5 ms |
12072 KB |
Output is correct |
31 |
Correct |
6 ms |
11988 KB |
Output is correct |
32 |
Correct |
6 ms |
12076 KB |
Output is correct |
33 |
Correct |
4 ms |
11988 KB |
Output is correct |
34 |
Correct |
4 ms |
12080 KB |
Output is correct |
35 |
Correct |
5 ms |
12204 KB |
Output is correct |
36 |
Correct |
5 ms |
12116 KB |
Output is correct |
37 |
Correct |
5 ms |
12116 KB |
Output is correct |
38 |
Correct |
6 ms |
12116 KB |
Output is correct |
39 |
Correct |
5 ms |
12116 KB |
Output is correct |
40 |
Correct |
5 ms |
12116 KB |
Output is correct |
41 |
Correct |
5 ms |
12116 KB |
Output is correct |
42 |
Correct |
5 ms |
12116 KB |
Output is correct |
43 |
Correct |
5 ms |
12116 KB |
Output is correct |
44 |
Correct |
5 ms |
12200 KB |
Output is correct |
45 |
Correct |
6 ms |
12120 KB |
Output is correct |
46 |
Correct |
5 ms |
12208 KB |
Output is correct |
47 |
Correct |
6 ms |
12116 KB |
Output is correct |
48 |
Correct |
6 ms |
12116 KB |
Output is correct |
49 |
Correct |
6 ms |
12204 KB |
Output is correct |
50 |
Correct |
5 ms |
12116 KB |
Output is correct |
51 |
Correct |
5 ms |
12200 KB |
Output is correct |
52 |
Correct |
5 ms |
12116 KB |
Output is correct |
53 |
Correct |
5 ms |
12204 KB |
Output is correct |
54 |
Correct |
5 ms |
12116 KB |
Output is correct |
55 |
Correct |
5 ms |
12208 KB |
Output is correct |
56 |
Correct |
4 ms |
12244 KB |
Output is correct |
57 |
Correct |
5 ms |
12116 KB |
Output is correct |
58 |
Correct |
5 ms |
12116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
12080 KB |
Output is correct |
2 |
Correct |
4 ms |
11988 KB |
Output is correct |
3 |
Correct |
5 ms |
11988 KB |
Output is correct |
4 |
Correct |
4 ms |
12080 KB |
Output is correct |
5 |
Correct |
5 ms |
12076 KB |
Output is correct |
6 |
Correct |
5 ms |
11988 KB |
Output is correct |
7 |
Correct |
99 ms |
94404 KB |
Output is correct |
8 |
Correct |
88 ms |
94448 KB |
Output is correct |
9 |
Correct |
89 ms |
94396 KB |
Output is correct |
10 |
Correct |
87 ms |
94392 KB |
Output is correct |
11 |
Correct |
86 ms |
94276 KB |
Output is correct |
12 |
Correct |
86 ms |
94288 KB |
Output is correct |
13 |
Correct |
88 ms |
94364 KB |
Output is correct |
14 |
Correct |
96 ms |
94408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
11988 KB |
Output is correct |
2 |
Correct |
5 ms |
11988 KB |
Output is correct |
3 |
Correct |
5 ms |
11988 KB |
Output is correct |
4 |
Correct |
5 ms |
12080 KB |
Output is correct |
5 |
Correct |
4 ms |
12072 KB |
Output is correct |
6 |
Correct |
4 ms |
11988 KB |
Output is correct |
7 |
Correct |
5 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
12116 KB |
Output is correct |
9 |
Correct |
5 ms |
11988 KB |
Output is correct |
10 |
Correct |
5 ms |
12076 KB |
Output is correct |
11 |
Correct |
5 ms |
11988 KB |
Output is correct |
12 |
Correct |
5 ms |
11988 KB |
Output is correct |
13 |
Correct |
5 ms |
12056 KB |
Output is correct |
14 |
Correct |
5 ms |
11988 KB |
Output is correct |
15 |
Correct |
5 ms |
11988 KB |
Output is correct |
16 |
Correct |
5 ms |
11988 KB |
Output is correct |
17 |
Correct |
5 ms |
11988 KB |
Output is correct |
18 |
Correct |
5 ms |
11988 KB |
Output is correct |
19 |
Correct |
6 ms |
12076 KB |
Output is correct |
20 |
Correct |
5 ms |
11988 KB |
Output is correct |
21 |
Correct |
6 ms |
11988 KB |
Output is correct |
22 |
Correct |
5 ms |
11988 KB |
Output is correct |
23 |
Correct |
4 ms |
11988 KB |
Output is correct |
24 |
Correct |
5 ms |
12072 KB |
Output is correct |
25 |
Correct |
5 ms |
11988 KB |
Output is correct |
26 |
Correct |
5 ms |
11988 KB |
Output is correct |
27 |
Correct |
5 ms |
12076 KB |
Output is correct |
28 |
Correct |
4 ms |
11988 KB |
Output is correct |
29 |
Correct |
5 ms |
12076 KB |
Output is correct |
30 |
Correct |
5 ms |
12072 KB |
Output is correct |
31 |
Correct |
6 ms |
11988 KB |
Output is correct |
32 |
Correct |
6 ms |
12076 KB |
Output is correct |
33 |
Correct |
4 ms |
11988 KB |
Output is correct |
34 |
Correct |
4 ms |
12080 KB |
Output is correct |
35 |
Correct |
5 ms |
12204 KB |
Output is correct |
36 |
Correct |
5 ms |
12116 KB |
Output is correct |
37 |
Correct |
5 ms |
12116 KB |
Output is correct |
38 |
Correct |
6 ms |
12116 KB |
Output is correct |
39 |
Correct |
5 ms |
12116 KB |
Output is correct |
40 |
Correct |
5 ms |
12116 KB |
Output is correct |
41 |
Correct |
5 ms |
12116 KB |
Output is correct |
42 |
Correct |
5 ms |
12116 KB |
Output is correct |
43 |
Correct |
5 ms |
12116 KB |
Output is correct |
44 |
Correct |
5 ms |
12200 KB |
Output is correct |
45 |
Correct |
6 ms |
12120 KB |
Output is correct |
46 |
Correct |
5 ms |
12208 KB |
Output is correct |
47 |
Correct |
6 ms |
12116 KB |
Output is correct |
48 |
Correct |
6 ms |
12116 KB |
Output is correct |
49 |
Correct |
6 ms |
12204 KB |
Output is correct |
50 |
Correct |
5 ms |
12116 KB |
Output is correct |
51 |
Correct |
5 ms |
12200 KB |
Output is correct |
52 |
Correct |
5 ms |
12116 KB |
Output is correct |
53 |
Correct |
5 ms |
12204 KB |
Output is correct |
54 |
Correct |
5 ms |
12116 KB |
Output is correct |
55 |
Correct |
5 ms |
12208 KB |
Output is correct |
56 |
Correct |
4 ms |
12244 KB |
Output is correct |
57 |
Correct |
5 ms |
12116 KB |
Output is correct |
58 |
Correct |
5 ms |
12116 KB |
Output is correct |
59 |
Correct |
4 ms |
12080 KB |
Output is correct |
60 |
Correct |
4 ms |
11988 KB |
Output is correct |
61 |
Correct |
5 ms |
11988 KB |
Output is correct |
62 |
Correct |
4 ms |
12080 KB |
Output is correct |
63 |
Correct |
5 ms |
12076 KB |
Output is correct |
64 |
Correct |
5 ms |
11988 KB |
Output is correct |
65 |
Correct |
99 ms |
94404 KB |
Output is correct |
66 |
Correct |
88 ms |
94448 KB |
Output is correct |
67 |
Correct |
89 ms |
94396 KB |
Output is correct |
68 |
Correct |
87 ms |
94392 KB |
Output is correct |
69 |
Correct |
86 ms |
94276 KB |
Output is correct |
70 |
Correct |
86 ms |
94288 KB |
Output is correct |
71 |
Correct |
88 ms |
94364 KB |
Output is correct |
72 |
Correct |
96 ms |
94408 KB |
Output is correct |
73 |
Correct |
86 ms |
94392 KB |
Output is correct |
74 |
Correct |
86 ms |
94396 KB |
Output is correct |
75 |
Correct |
89 ms |
94488 KB |
Output is correct |
76 |
Correct |
84 ms |
94388 KB |
Output is correct |
77 |
Correct |
89 ms |
94332 KB |
Output is correct |
78 |
Correct |
90 ms |
94396 KB |
Output is correct |
79 |
Correct |
88 ms |
94380 KB |
Output is correct |
80 |
Correct |
98 ms |
94404 KB |
Output is correct |
81 |
Correct |
79 ms |
94368 KB |
Output is correct |
82 |
Correct |
86 ms |
94336 KB |
Output is correct |
83 |
Correct |
83 ms |
94276 KB |
Output is correct |
84 |
Correct |
84 ms |
94400 KB |
Output is correct |
85 |
Correct |
90 ms |
94344 KB |
Output is correct |
86 |
Correct |
85 ms |
94380 KB |
Output is correct |
87 |
Correct |
99 ms |
94300 KB |
Output is correct |
88 |
Correct |
87 ms |
94400 KB |
Output is correct |
89 |
Correct |
86 ms |
94396 KB |
Output is correct |
90 |
Correct |
92 ms |
94360 KB |
Output is correct |
91 |
Correct |
86 ms |
94360 KB |
Output is correct |
92 |
Correct |
90 ms |
94324 KB |
Output is correct |
93 |
Correct |
84 ms |
94276 KB |
Output is correct |
94 |
Correct |
100 ms |
94400 KB |
Output is correct |
95 |
Correct |
89 ms |
94272 KB |
Output is correct |
96 |
Correct |
85 ms |
94380 KB |
Output is correct |
97 |
Correct |
86 ms |
94324 KB |
Output is correct |
98 |
Correct |
89 ms |
94340 KB |
Output is correct |
99 |
Correct |
90 ms |
94396 KB |
Output is correct |
100 |
Correct |
90 ms |
94508 KB |
Output is correct |
101 |
Correct |
90 ms |
94340 KB |
Output is correct |
102 |
Correct |
82 ms |
94396 KB |
Output is correct |