# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
134474 |
2019-07-22T18:31:32 Z |
doowey |
Lamps (JOI19_lamps) |
C++14 |
|
106 ms |
27980 KB |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e6 + 9;
int dp[N][3][2];
int main(){
fastIO;
int n;
cin >> n;
for(int i = 0 ; i < N ;i ++ ){
for(int j = 0 ; j < 3 ; j ++ )
for(int z = 0; z < 2 ;z ++ )
dp[i][j][z] = 12124141;
}
string a, b;
cin >> a >> b;
int from, to;
int nw;
int sum;
dp[0][0][0] = 0;
for(int i = 1 ; i <= n; i ++ ){
from = a[i-1] - '0';
to = b[i-1] - '0';
for(int j = 0 ; j < 3; j ++ ){
for(int z = 0 ;z < 2; z ++ ){
nw = from;
if(j) nw = j - 1;
if(z) nw ^= 1;
if(nw == to){
for(int v = 0; v < 3 ;v ++ ){
for(int q = 0 ;q < 2; q ++ ){
sum = dp[i-1][v][q];
if(j > 0 && j != v) sum ++ ;
if(z > 0 && z != q) sum ++ ;
dp[i][j][z] = min(dp[i][j][z], sum);
}
}
}
}
}
}
int res = 124214124;
for(int i = 0 ; i < 3; i ++ )
for(int j = 0 ; j < 2; j ++ ){
res = min(res, dp[n][i][j]);
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23928 KB |
Output is correct |
2 |
Correct |
21 ms |
23800 KB |
Output is correct |
3 |
Correct |
21 ms |
23800 KB |
Output is correct |
4 |
Correct |
21 ms |
23800 KB |
Output is correct |
5 |
Correct |
21 ms |
23800 KB |
Output is correct |
6 |
Correct |
20 ms |
23800 KB |
Output is correct |
7 |
Correct |
20 ms |
23800 KB |
Output is correct |
8 |
Correct |
20 ms |
23800 KB |
Output is correct |
9 |
Correct |
24 ms |
23800 KB |
Output is correct |
10 |
Correct |
24 ms |
23800 KB |
Output is correct |
11 |
Correct |
20 ms |
23800 KB |
Output is correct |
12 |
Correct |
21 ms |
23796 KB |
Output is correct |
13 |
Correct |
20 ms |
23800 KB |
Output is correct |
14 |
Correct |
20 ms |
23800 KB |
Output is correct |
15 |
Correct |
21 ms |
23816 KB |
Output is correct |
16 |
Correct |
21 ms |
23800 KB |
Output is correct |
17 |
Correct |
20 ms |
23800 KB |
Output is correct |
18 |
Correct |
21 ms |
23772 KB |
Output is correct |
19 |
Correct |
21 ms |
23808 KB |
Output is correct |
20 |
Correct |
25 ms |
23772 KB |
Output is correct |
21 |
Correct |
21 ms |
23800 KB |
Output is correct |
22 |
Correct |
21 ms |
23896 KB |
Output is correct |
23 |
Correct |
21 ms |
23772 KB |
Output is correct |
24 |
Correct |
21 ms |
23772 KB |
Output is correct |
25 |
Correct |
20 ms |
23800 KB |
Output is correct |
26 |
Correct |
21 ms |
23800 KB |
Output is correct |
27 |
Correct |
21 ms |
23864 KB |
Output is correct |
28 |
Correct |
21 ms |
23800 KB |
Output is correct |
29 |
Correct |
21 ms |
23808 KB |
Output is correct |
30 |
Correct |
20 ms |
23800 KB |
Output is correct |
31 |
Correct |
21 ms |
23780 KB |
Output is correct |
32 |
Correct |
21 ms |
23800 KB |
Output is correct |
33 |
Correct |
21 ms |
23800 KB |
Output is correct |
34 |
Correct |
21 ms |
23800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23928 KB |
Output is correct |
2 |
Correct |
21 ms |
23800 KB |
Output is correct |
3 |
Correct |
21 ms |
23800 KB |
Output is correct |
4 |
Correct |
21 ms |
23800 KB |
Output is correct |
5 |
Correct |
21 ms |
23800 KB |
Output is correct |
6 |
Correct |
20 ms |
23800 KB |
Output is correct |
7 |
Correct |
20 ms |
23800 KB |
Output is correct |
8 |
Correct |
20 ms |
23800 KB |
Output is correct |
9 |
Correct |
24 ms |
23800 KB |
Output is correct |
10 |
Correct |
24 ms |
23800 KB |
Output is correct |
11 |
Correct |
20 ms |
23800 KB |
Output is correct |
12 |
Correct |
21 ms |
23796 KB |
Output is correct |
13 |
Correct |
20 ms |
23800 KB |
Output is correct |
14 |
Correct |
20 ms |
23800 KB |
Output is correct |
15 |
Correct |
21 ms |
23816 KB |
Output is correct |
16 |
Correct |
21 ms |
23800 KB |
Output is correct |
17 |
Correct |
20 ms |
23800 KB |
Output is correct |
18 |
Correct |
21 ms |
23772 KB |
Output is correct |
19 |
Correct |
21 ms |
23808 KB |
Output is correct |
20 |
Correct |
25 ms |
23772 KB |
Output is correct |
21 |
Correct |
21 ms |
23800 KB |
Output is correct |
22 |
Correct |
21 ms |
23896 KB |
Output is correct |
23 |
Correct |
21 ms |
23772 KB |
Output is correct |
24 |
Correct |
21 ms |
23772 KB |
Output is correct |
25 |
Correct |
20 ms |
23800 KB |
Output is correct |
26 |
Correct |
21 ms |
23800 KB |
Output is correct |
27 |
Correct |
21 ms |
23864 KB |
Output is correct |
28 |
Correct |
21 ms |
23800 KB |
Output is correct |
29 |
Correct |
21 ms |
23808 KB |
Output is correct |
30 |
Correct |
20 ms |
23800 KB |
Output is correct |
31 |
Correct |
21 ms |
23780 KB |
Output is correct |
32 |
Correct |
21 ms |
23800 KB |
Output is correct |
33 |
Correct |
21 ms |
23800 KB |
Output is correct |
34 |
Correct |
21 ms |
23800 KB |
Output is correct |
35 |
Correct |
21 ms |
23800 KB |
Output is correct |
36 |
Correct |
20 ms |
23800 KB |
Output is correct |
37 |
Correct |
21 ms |
23800 KB |
Output is correct |
38 |
Correct |
22 ms |
23816 KB |
Output is correct |
39 |
Correct |
21 ms |
23800 KB |
Output is correct |
40 |
Correct |
21 ms |
23800 KB |
Output is correct |
41 |
Correct |
22 ms |
23880 KB |
Output is correct |
42 |
Correct |
21 ms |
23800 KB |
Output is correct |
43 |
Correct |
21 ms |
23800 KB |
Output is correct |
44 |
Correct |
21 ms |
23800 KB |
Output is correct |
45 |
Correct |
21 ms |
23800 KB |
Output is correct |
46 |
Correct |
21 ms |
23800 KB |
Output is correct |
47 |
Correct |
22 ms |
23928 KB |
Output is correct |
48 |
Correct |
21 ms |
23804 KB |
Output is correct |
49 |
Correct |
21 ms |
23772 KB |
Output is correct |
50 |
Correct |
21 ms |
23800 KB |
Output is correct |
51 |
Correct |
25 ms |
23800 KB |
Output is correct |
52 |
Correct |
21 ms |
23800 KB |
Output is correct |
53 |
Correct |
21 ms |
23800 KB |
Output is correct |
54 |
Correct |
25 ms |
23800 KB |
Output is correct |
55 |
Correct |
21 ms |
23812 KB |
Output is correct |
56 |
Correct |
21 ms |
23800 KB |
Output is correct |
57 |
Correct |
21 ms |
23804 KB |
Output is correct |
58 |
Correct |
21 ms |
23828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23848 KB |
Output is correct |
2 |
Correct |
21 ms |
23800 KB |
Output is correct |
3 |
Correct |
21 ms |
23800 KB |
Output is correct |
4 |
Correct |
21 ms |
23800 KB |
Output is correct |
5 |
Correct |
21 ms |
23800 KB |
Output is correct |
6 |
Correct |
21 ms |
23800 KB |
Output is correct |
7 |
Correct |
68 ms |
27924 KB |
Output is correct |
8 |
Correct |
68 ms |
27936 KB |
Output is correct |
9 |
Correct |
74 ms |
27920 KB |
Output is correct |
10 |
Correct |
68 ms |
27940 KB |
Output is correct |
11 |
Correct |
68 ms |
27920 KB |
Output is correct |
12 |
Correct |
68 ms |
27932 KB |
Output is correct |
13 |
Correct |
76 ms |
27924 KB |
Output is correct |
14 |
Correct |
106 ms |
27924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23928 KB |
Output is correct |
2 |
Correct |
21 ms |
23800 KB |
Output is correct |
3 |
Correct |
21 ms |
23800 KB |
Output is correct |
4 |
Correct |
21 ms |
23800 KB |
Output is correct |
5 |
Correct |
21 ms |
23800 KB |
Output is correct |
6 |
Correct |
20 ms |
23800 KB |
Output is correct |
7 |
Correct |
20 ms |
23800 KB |
Output is correct |
8 |
Correct |
20 ms |
23800 KB |
Output is correct |
9 |
Correct |
24 ms |
23800 KB |
Output is correct |
10 |
Correct |
24 ms |
23800 KB |
Output is correct |
11 |
Correct |
20 ms |
23800 KB |
Output is correct |
12 |
Correct |
21 ms |
23796 KB |
Output is correct |
13 |
Correct |
20 ms |
23800 KB |
Output is correct |
14 |
Correct |
20 ms |
23800 KB |
Output is correct |
15 |
Correct |
21 ms |
23816 KB |
Output is correct |
16 |
Correct |
21 ms |
23800 KB |
Output is correct |
17 |
Correct |
20 ms |
23800 KB |
Output is correct |
18 |
Correct |
21 ms |
23772 KB |
Output is correct |
19 |
Correct |
21 ms |
23808 KB |
Output is correct |
20 |
Correct |
25 ms |
23772 KB |
Output is correct |
21 |
Correct |
21 ms |
23800 KB |
Output is correct |
22 |
Correct |
21 ms |
23896 KB |
Output is correct |
23 |
Correct |
21 ms |
23772 KB |
Output is correct |
24 |
Correct |
21 ms |
23772 KB |
Output is correct |
25 |
Correct |
20 ms |
23800 KB |
Output is correct |
26 |
Correct |
21 ms |
23800 KB |
Output is correct |
27 |
Correct |
21 ms |
23864 KB |
Output is correct |
28 |
Correct |
21 ms |
23800 KB |
Output is correct |
29 |
Correct |
21 ms |
23808 KB |
Output is correct |
30 |
Correct |
20 ms |
23800 KB |
Output is correct |
31 |
Correct |
21 ms |
23780 KB |
Output is correct |
32 |
Correct |
21 ms |
23800 KB |
Output is correct |
33 |
Correct |
21 ms |
23800 KB |
Output is correct |
34 |
Correct |
21 ms |
23800 KB |
Output is correct |
35 |
Correct |
21 ms |
23800 KB |
Output is correct |
36 |
Correct |
20 ms |
23800 KB |
Output is correct |
37 |
Correct |
21 ms |
23800 KB |
Output is correct |
38 |
Correct |
22 ms |
23816 KB |
Output is correct |
39 |
Correct |
21 ms |
23800 KB |
Output is correct |
40 |
Correct |
21 ms |
23800 KB |
Output is correct |
41 |
Correct |
22 ms |
23880 KB |
Output is correct |
42 |
Correct |
21 ms |
23800 KB |
Output is correct |
43 |
Correct |
21 ms |
23800 KB |
Output is correct |
44 |
Correct |
21 ms |
23800 KB |
Output is correct |
45 |
Correct |
21 ms |
23800 KB |
Output is correct |
46 |
Correct |
21 ms |
23800 KB |
Output is correct |
47 |
Correct |
22 ms |
23928 KB |
Output is correct |
48 |
Correct |
21 ms |
23804 KB |
Output is correct |
49 |
Correct |
21 ms |
23772 KB |
Output is correct |
50 |
Correct |
21 ms |
23800 KB |
Output is correct |
51 |
Correct |
25 ms |
23800 KB |
Output is correct |
52 |
Correct |
21 ms |
23800 KB |
Output is correct |
53 |
Correct |
21 ms |
23800 KB |
Output is correct |
54 |
Correct |
25 ms |
23800 KB |
Output is correct |
55 |
Correct |
21 ms |
23812 KB |
Output is correct |
56 |
Correct |
21 ms |
23800 KB |
Output is correct |
57 |
Correct |
21 ms |
23804 KB |
Output is correct |
58 |
Correct |
21 ms |
23828 KB |
Output is correct |
59 |
Correct |
21 ms |
23848 KB |
Output is correct |
60 |
Correct |
21 ms |
23800 KB |
Output is correct |
61 |
Correct |
21 ms |
23800 KB |
Output is correct |
62 |
Correct |
21 ms |
23800 KB |
Output is correct |
63 |
Correct |
21 ms |
23800 KB |
Output is correct |
64 |
Correct |
21 ms |
23800 KB |
Output is correct |
65 |
Correct |
68 ms |
27924 KB |
Output is correct |
66 |
Correct |
68 ms |
27936 KB |
Output is correct |
67 |
Correct |
74 ms |
27920 KB |
Output is correct |
68 |
Correct |
68 ms |
27940 KB |
Output is correct |
69 |
Correct |
68 ms |
27920 KB |
Output is correct |
70 |
Correct |
68 ms |
27932 KB |
Output is correct |
71 |
Correct |
76 ms |
27924 KB |
Output is correct |
72 |
Correct |
106 ms |
27924 KB |
Output is correct |
73 |
Correct |
70 ms |
27924 KB |
Output is correct |
74 |
Correct |
73 ms |
27928 KB |
Output is correct |
75 |
Correct |
70 ms |
27924 KB |
Output is correct |
76 |
Correct |
70 ms |
27940 KB |
Output is correct |
77 |
Correct |
70 ms |
27900 KB |
Output is correct |
78 |
Correct |
69 ms |
27980 KB |
Output is correct |
79 |
Correct |
67 ms |
27920 KB |
Output is correct |
80 |
Correct |
71 ms |
27924 KB |
Output is correct |
81 |
Correct |
69 ms |
27924 KB |
Output is correct |
82 |
Correct |
69 ms |
27924 KB |
Output is correct |
83 |
Correct |
84 ms |
27924 KB |
Output is correct |
84 |
Correct |
84 ms |
27924 KB |
Output is correct |
85 |
Correct |
77 ms |
27924 KB |
Output is correct |
86 |
Correct |
77 ms |
27920 KB |
Output is correct |
87 |
Correct |
77 ms |
27920 KB |
Output is correct |
88 |
Correct |
77 ms |
27924 KB |
Output is correct |
89 |
Correct |
77 ms |
27944 KB |
Output is correct |
90 |
Correct |
79 ms |
27924 KB |
Output is correct |
91 |
Correct |
80 ms |
27920 KB |
Output is correct |
92 |
Correct |
81 ms |
27920 KB |
Output is correct |
93 |
Correct |
82 ms |
27920 KB |
Output is correct |
94 |
Correct |
81 ms |
27924 KB |
Output is correct |
95 |
Correct |
90 ms |
27912 KB |
Output is correct |
96 |
Correct |
81 ms |
27924 KB |
Output is correct |
97 |
Correct |
88 ms |
27928 KB |
Output is correct |
98 |
Correct |
95 ms |
27924 KB |
Output is correct |
99 |
Correct |
86 ms |
27924 KB |
Output is correct |
100 |
Correct |
82 ms |
27924 KB |
Output is correct |
101 |
Correct |
89 ms |
27920 KB |
Output is correct |
102 |
Correct |
88 ms |
27920 KB |
Output is correct |