# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
102125 |
2019-03-22T16:42:25 Z |
tpoppo |
Lamps (JOI19_lamps) |
C++14 |
|
72 ms |
26084 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 100;
int n;
string a,b;
int dp[MAXN][2][3];
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cin >> n;
cin >> a >> b;
memset(dp,0x66,sizeof(dp));
for(int inv=0;inv<2;inv++) {
for(int z=0;z<3;z++) {
dp[0][inv][z] = (inv == 1) + (z != 2);
}
}
for(int i=0;i<=n;i++) {
for(int inv=0;inv<2;inv++) {
for(int z=0;z<3;z++) {
//cout<<setw(10)<<dp[i][inv][z]<<" ";
if(b[i] == '0') dp[i+1][inv][0] = min(dp[i+1][inv][0],dp[i][inv][z] + (z != 0) );
if(b[i] == '0') dp[i+1][!inv][0] = min(dp[i+1][!inv][0],dp[i][!inv][z] + 1 + (z != 0) );
if(b[i] == '1') dp[i+1][inv][1] = min(dp[i+1][inv][1],dp[i][inv][z] + (z != 1) );
if(b[i] == '1') dp[i+1][!inv][1] = min(dp[i+1][!inv][1],dp[i][inv][z] + 1 + (z != 1) );
if(b[i] == a[i]) dp[i+1][0][2] = min(dp[i+1][0][2],dp[i][inv][z] );
else dp[i+1][1][2] = min(dp[i+1][1][2],dp[i][inv][z] + (inv != 1) );
}
}//cout<<endl;
}
int rs = 1e9;
for(int inv=0;inv<2;inv++) {
for(int z=0;z<3;z++) {
rs = min(rs,dp[n][inv][z]);
}
}
cout<<rs<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23800 KB |
Output is correct |
3 |
Correct |
22 ms |
23800 KB |
Output is correct |
4 |
Correct |
25 ms |
23808 KB |
Output is correct |
5 |
Correct |
24 ms |
23828 KB |
Output is correct |
6 |
Correct |
31 ms |
23800 KB |
Output is correct |
7 |
Correct |
22 ms |
23884 KB |
Output is correct |
8 |
Correct |
22 ms |
23808 KB |
Output is correct |
9 |
Correct |
22 ms |
23808 KB |
Output is correct |
10 |
Correct |
22 ms |
23800 KB |
Output is correct |
11 |
Correct |
22 ms |
23808 KB |
Output is correct |
12 |
Correct |
20 ms |
23808 KB |
Output is correct |
13 |
Correct |
20 ms |
23800 KB |
Output is correct |
14 |
Correct |
21 ms |
23808 KB |
Output is correct |
15 |
Correct |
22 ms |
23800 KB |
Output is correct |
16 |
Incorrect |
24 ms |
23808 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23800 KB |
Output is correct |
3 |
Correct |
22 ms |
23800 KB |
Output is correct |
4 |
Correct |
25 ms |
23808 KB |
Output is correct |
5 |
Correct |
24 ms |
23828 KB |
Output is correct |
6 |
Correct |
31 ms |
23800 KB |
Output is correct |
7 |
Correct |
22 ms |
23884 KB |
Output is correct |
8 |
Correct |
22 ms |
23808 KB |
Output is correct |
9 |
Correct |
22 ms |
23808 KB |
Output is correct |
10 |
Correct |
22 ms |
23800 KB |
Output is correct |
11 |
Correct |
22 ms |
23808 KB |
Output is correct |
12 |
Correct |
20 ms |
23808 KB |
Output is correct |
13 |
Correct |
20 ms |
23800 KB |
Output is correct |
14 |
Correct |
21 ms |
23808 KB |
Output is correct |
15 |
Correct |
22 ms |
23800 KB |
Output is correct |
16 |
Incorrect |
24 ms |
23808 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
23780 KB |
Output is correct |
2 |
Correct |
19 ms |
23780 KB |
Output is correct |
3 |
Correct |
20 ms |
23800 KB |
Output is correct |
4 |
Correct |
29 ms |
23800 KB |
Output is correct |
5 |
Correct |
21 ms |
23808 KB |
Output is correct |
6 |
Correct |
20 ms |
23808 KB |
Output is correct |
7 |
Correct |
57 ms |
25940 KB |
Output is correct |
8 |
Correct |
65 ms |
25940 KB |
Output is correct |
9 |
Correct |
55 ms |
25936 KB |
Output is correct |
10 |
Correct |
66 ms |
26084 KB |
Output is correct |
11 |
Correct |
72 ms |
26060 KB |
Output is correct |
12 |
Correct |
60 ms |
25972 KB |
Output is correct |
13 |
Correct |
63 ms |
26052 KB |
Output is correct |
14 |
Correct |
65 ms |
25968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23800 KB |
Output is correct |
3 |
Correct |
22 ms |
23800 KB |
Output is correct |
4 |
Correct |
25 ms |
23808 KB |
Output is correct |
5 |
Correct |
24 ms |
23828 KB |
Output is correct |
6 |
Correct |
31 ms |
23800 KB |
Output is correct |
7 |
Correct |
22 ms |
23884 KB |
Output is correct |
8 |
Correct |
22 ms |
23808 KB |
Output is correct |
9 |
Correct |
22 ms |
23808 KB |
Output is correct |
10 |
Correct |
22 ms |
23800 KB |
Output is correct |
11 |
Correct |
22 ms |
23808 KB |
Output is correct |
12 |
Correct |
20 ms |
23808 KB |
Output is correct |
13 |
Correct |
20 ms |
23800 KB |
Output is correct |
14 |
Correct |
21 ms |
23808 KB |
Output is correct |
15 |
Correct |
22 ms |
23800 KB |
Output is correct |
16 |
Incorrect |
24 ms |
23808 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |