#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
string x, y;
int dp[1001000];
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n;
cin >> n >> x >> y;
int pt[2]={-1, -1}, pt2=-1;
if (x[0]!=y[0]) dp[0]=1;
else pt2=0;
pt[y[0]-'0']=0;
for (int i=1;i<n;i++){
//printf("%d %d %d\n", pt[0], pt[1], pt2);
if (x[i]==y[i]){
dp[i] = dp[i-1];
pt[y[i]-'0'] = i;
pt2 = i;
continue;
}
dp[i] = 1e9;
if (pt2==-1) dp[i] = 1;
else dp[i] = min(dp[i], dp[pt2]+1);
if (pt[(y[i]-'0')^1]==-1) dp[i] = 1;
else dp[i] = min(dp[i], dp[pt[(y[i]-'0')^1]]+1);
pt[y[i]-'0'] = i;
}
cout << dp[n-1];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
11 ms |
8220 KB |
Output is correct |
8 |
Correct |
12 ms |
8304 KB |
Output is correct |
9 |
Correct |
12 ms |
8276 KB |
Output is correct |
10 |
Correct |
12 ms |
8220 KB |
Output is correct |
11 |
Correct |
11 ms |
8192 KB |
Output is correct |
12 |
Correct |
11 ms |
8220 KB |
Output is correct |
13 |
Correct |
11 ms |
8236 KB |
Output is correct |
14 |
Correct |
13 ms |
8216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |