# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
235270 |
2020-05-27T14:45:01 Z |
Nodir_Bobiev |
Lamps (JOI19_lamps) |
C++17 |
|
427 ms |
104344 KB |
/*
+----------------------------------------------------------------+
| In the name of Allah, the most Gracious and the most Merciful. |
+----------------------------------------------------------------+
Our hearts quake with fear of you
Our hearts wake with love for you
And to Islam we must be true
In everything we think and do.
--------------------------------
When your heart is breaking
And your pain makes you fall
Remember just remember
Allah Sees it all.
*/
# include <bits/stdc++.h>
# define FILE
using namespace std;
const int N = 1e6 + 100;
const int inf = 1e9;
string A,B;
int n, gettt[30][30];
char precount[2][30];
vector < pair < int, int > > dp[N];
vector < vector < int > > oper= { {}, {1}, {2}, {3}, {1,2},{1,3}, {2,1}, {2,3}, {3,1}, {3,2},
{1,2,3}, {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, {3,2,1}
};
inline char op(int x, char c){
if( x == 0 ) return c;
if( x == 1 ) return '0';
if( x == 2 ) return '1';
if( c == '1' ) return '0';
return '1';
}
inline int get( vector < int >&v1, vector < int >&v2, int i=0, int j=0 ){
if( i == (int)v1.size() || j == (int)v2.size())return 0;
int mx = 0;
if( v1[i] == v2[j] ) mx = get(v1, v2, i+1, j+1) + 1;
mx = max({mx, get(v1, v2, i+1, j), get(v1, v2, i, j+1)});
return mx;
}
int main(){
# ifdef FILEs
freopen( "input.txt", "r", stdin );
freopen( "output.txt", "w", stdout );
# endif
ios_base::sync_with_stdio(false);
cin >> n >> A >> B;
A = '0' + A;
B = '0' + B;
for( size_t i = 0; i < oper.size(); i ++ ){
for( size_t j = 0; j < oper.size(); j ++ ){
gettt[i][j] = get(oper[i], oper[j]);
}
}
for( int i = 0; i < 2; i ++ ){
for( size_t j = 0; j < oper.size(); j ++ ){
precount[i][j] = '0'+i;
for( auto c: oper[j] ){
precount[i][j] = op(c, precount[i][j]);
}
}
}
dp[0].push_back({0, 0});
for( int i = 1; i <= n; i ++ ){
for( size_t j = 0; j < oper.size(); j ++){
if( precount[A[i]-48][j] != B[i] ) continue;
int res = inf;
for( auto v2: dp[i-1] ){
res = min( res, v2.second + (int)oper[j].size() - gettt[j][v2.first] );
}
if( res != inf ){
dp[i].push_back({j,res});
}
}
}
int ans = inf;
for( auto vc: dp[n] )ans = min( ans, vc.second );
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
18 ms |
23808 KB |
Output is correct |
4 |
Correct |
18 ms |
23808 KB |
Output is correct |
5 |
Correct |
18 ms |
23808 KB |
Output is correct |
6 |
Correct |
19 ms |
23808 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
18 ms |
23808 KB |
Output is correct |
9 |
Correct |
18 ms |
23808 KB |
Output is correct |
10 |
Correct |
18 ms |
23860 KB |
Output is correct |
11 |
Correct |
18 ms |
23808 KB |
Output is correct |
12 |
Correct |
18 ms |
23808 KB |
Output is correct |
13 |
Correct |
18 ms |
23808 KB |
Output is correct |
14 |
Correct |
18 ms |
23808 KB |
Output is correct |
15 |
Correct |
19 ms |
23808 KB |
Output is correct |
16 |
Correct |
19 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
18 ms |
23808 KB |
Output is correct |
19 |
Correct |
18 ms |
23808 KB |
Output is correct |
20 |
Correct |
18 ms |
23808 KB |
Output is correct |
21 |
Correct |
20 ms |
23936 KB |
Output is correct |
22 |
Correct |
19 ms |
23808 KB |
Output is correct |
23 |
Correct |
18 ms |
23808 KB |
Output is correct |
24 |
Correct |
20 ms |
23808 KB |
Output is correct |
25 |
Correct |
18 ms |
23808 KB |
Output is correct |
26 |
Correct |
18 ms |
23808 KB |
Output is correct |
27 |
Correct |
18 ms |
23808 KB |
Output is correct |
28 |
Correct |
18 ms |
23808 KB |
Output is correct |
29 |
Correct |
18 ms |
23808 KB |
Output is correct |
30 |
Correct |
18 ms |
23808 KB |
Output is correct |
31 |
Correct |
18 ms |
23808 KB |
Output is correct |
32 |
Correct |
18 ms |
23808 KB |
Output is correct |
33 |
Correct |
19 ms |
23808 KB |
Output is correct |
34 |
Correct |
19 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
18 ms |
23808 KB |
Output is correct |
4 |
Correct |
18 ms |
23808 KB |
Output is correct |
5 |
Correct |
18 ms |
23808 KB |
Output is correct |
6 |
Correct |
19 ms |
23808 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
18 ms |
23808 KB |
Output is correct |
9 |
Correct |
18 ms |
23808 KB |
Output is correct |
10 |
Correct |
18 ms |
23860 KB |
Output is correct |
11 |
Correct |
18 ms |
23808 KB |
Output is correct |
12 |
Correct |
18 ms |
23808 KB |
Output is correct |
13 |
Correct |
18 ms |
23808 KB |
Output is correct |
14 |
Correct |
18 ms |
23808 KB |
Output is correct |
15 |
Correct |
19 ms |
23808 KB |
Output is correct |
16 |
Correct |
19 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
18 ms |
23808 KB |
Output is correct |
19 |
Correct |
18 ms |
23808 KB |
Output is correct |
20 |
Correct |
18 ms |
23808 KB |
Output is correct |
21 |
Correct |
20 ms |
23936 KB |
Output is correct |
22 |
Correct |
19 ms |
23808 KB |
Output is correct |
23 |
Correct |
18 ms |
23808 KB |
Output is correct |
24 |
Correct |
20 ms |
23808 KB |
Output is correct |
25 |
Correct |
18 ms |
23808 KB |
Output is correct |
26 |
Correct |
18 ms |
23808 KB |
Output is correct |
27 |
Correct |
18 ms |
23808 KB |
Output is correct |
28 |
Correct |
18 ms |
23808 KB |
Output is correct |
29 |
Correct |
18 ms |
23808 KB |
Output is correct |
30 |
Correct |
18 ms |
23808 KB |
Output is correct |
31 |
Correct |
18 ms |
23808 KB |
Output is correct |
32 |
Correct |
18 ms |
23808 KB |
Output is correct |
33 |
Correct |
19 ms |
23808 KB |
Output is correct |
34 |
Correct |
19 ms |
23808 KB |
Output is correct |
35 |
Correct |
19 ms |
23936 KB |
Output is correct |
36 |
Correct |
18 ms |
23936 KB |
Output is correct |
37 |
Correct |
21 ms |
23936 KB |
Output is correct |
38 |
Correct |
20 ms |
23936 KB |
Output is correct |
39 |
Correct |
19 ms |
23936 KB |
Output is correct |
40 |
Correct |
19 ms |
23936 KB |
Output is correct |
41 |
Correct |
19 ms |
23936 KB |
Output is correct |
42 |
Correct |
20 ms |
24096 KB |
Output is correct |
43 |
Correct |
19 ms |
23936 KB |
Output is correct |
44 |
Correct |
19 ms |
24064 KB |
Output is correct |
45 |
Correct |
19 ms |
24064 KB |
Output is correct |
46 |
Correct |
19 ms |
23936 KB |
Output is correct |
47 |
Correct |
19 ms |
23936 KB |
Output is correct |
48 |
Correct |
19 ms |
23936 KB |
Output is correct |
49 |
Correct |
19 ms |
23936 KB |
Output is correct |
50 |
Correct |
19 ms |
23936 KB |
Output is correct |
51 |
Correct |
19 ms |
23936 KB |
Output is correct |
52 |
Correct |
19 ms |
23936 KB |
Output is correct |
53 |
Correct |
19 ms |
24064 KB |
Output is correct |
54 |
Correct |
19 ms |
23936 KB |
Output is correct |
55 |
Correct |
19 ms |
24064 KB |
Output is correct |
56 |
Correct |
19 ms |
23936 KB |
Output is correct |
57 |
Correct |
20 ms |
23936 KB |
Output is correct |
58 |
Correct |
19 ms |
23936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
18 ms |
23808 KB |
Output is correct |
4 |
Correct |
18 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
19 ms |
23808 KB |
Output is correct |
7 |
Correct |
364 ms |
104224 KB |
Output is correct |
8 |
Correct |
408 ms |
104128 KB |
Output is correct |
9 |
Correct |
399 ms |
104148 KB |
Output is correct |
10 |
Correct |
398 ms |
104092 KB |
Output is correct |
11 |
Correct |
397 ms |
104096 KB |
Output is correct |
12 |
Correct |
390 ms |
104220 KB |
Output is correct |
13 |
Correct |
374 ms |
104092 KB |
Output is correct |
14 |
Correct |
375 ms |
104092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23808 KB |
Output is correct |
3 |
Correct |
18 ms |
23808 KB |
Output is correct |
4 |
Correct |
18 ms |
23808 KB |
Output is correct |
5 |
Correct |
18 ms |
23808 KB |
Output is correct |
6 |
Correct |
19 ms |
23808 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
18 ms |
23808 KB |
Output is correct |
9 |
Correct |
18 ms |
23808 KB |
Output is correct |
10 |
Correct |
18 ms |
23860 KB |
Output is correct |
11 |
Correct |
18 ms |
23808 KB |
Output is correct |
12 |
Correct |
18 ms |
23808 KB |
Output is correct |
13 |
Correct |
18 ms |
23808 KB |
Output is correct |
14 |
Correct |
18 ms |
23808 KB |
Output is correct |
15 |
Correct |
19 ms |
23808 KB |
Output is correct |
16 |
Correct |
19 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
18 ms |
23808 KB |
Output is correct |
19 |
Correct |
18 ms |
23808 KB |
Output is correct |
20 |
Correct |
18 ms |
23808 KB |
Output is correct |
21 |
Correct |
20 ms |
23936 KB |
Output is correct |
22 |
Correct |
19 ms |
23808 KB |
Output is correct |
23 |
Correct |
18 ms |
23808 KB |
Output is correct |
24 |
Correct |
20 ms |
23808 KB |
Output is correct |
25 |
Correct |
18 ms |
23808 KB |
Output is correct |
26 |
Correct |
18 ms |
23808 KB |
Output is correct |
27 |
Correct |
18 ms |
23808 KB |
Output is correct |
28 |
Correct |
18 ms |
23808 KB |
Output is correct |
29 |
Correct |
18 ms |
23808 KB |
Output is correct |
30 |
Correct |
18 ms |
23808 KB |
Output is correct |
31 |
Correct |
18 ms |
23808 KB |
Output is correct |
32 |
Correct |
18 ms |
23808 KB |
Output is correct |
33 |
Correct |
19 ms |
23808 KB |
Output is correct |
34 |
Correct |
19 ms |
23808 KB |
Output is correct |
35 |
Correct |
19 ms |
23936 KB |
Output is correct |
36 |
Correct |
18 ms |
23936 KB |
Output is correct |
37 |
Correct |
21 ms |
23936 KB |
Output is correct |
38 |
Correct |
20 ms |
23936 KB |
Output is correct |
39 |
Correct |
19 ms |
23936 KB |
Output is correct |
40 |
Correct |
19 ms |
23936 KB |
Output is correct |
41 |
Correct |
19 ms |
23936 KB |
Output is correct |
42 |
Correct |
20 ms |
24096 KB |
Output is correct |
43 |
Correct |
19 ms |
23936 KB |
Output is correct |
44 |
Correct |
19 ms |
24064 KB |
Output is correct |
45 |
Correct |
19 ms |
24064 KB |
Output is correct |
46 |
Correct |
19 ms |
23936 KB |
Output is correct |
47 |
Correct |
19 ms |
23936 KB |
Output is correct |
48 |
Correct |
19 ms |
23936 KB |
Output is correct |
49 |
Correct |
19 ms |
23936 KB |
Output is correct |
50 |
Correct |
19 ms |
23936 KB |
Output is correct |
51 |
Correct |
19 ms |
23936 KB |
Output is correct |
52 |
Correct |
19 ms |
23936 KB |
Output is correct |
53 |
Correct |
19 ms |
24064 KB |
Output is correct |
54 |
Correct |
19 ms |
23936 KB |
Output is correct |
55 |
Correct |
19 ms |
24064 KB |
Output is correct |
56 |
Correct |
19 ms |
23936 KB |
Output is correct |
57 |
Correct |
20 ms |
23936 KB |
Output is correct |
58 |
Correct |
19 ms |
23936 KB |
Output is correct |
59 |
Correct |
20 ms |
23808 KB |
Output is correct |
60 |
Correct |
18 ms |
23808 KB |
Output is correct |
61 |
Correct |
18 ms |
23808 KB |
Output is correct |
62 |
Correct |
18 ms |
23808 KB |
Output is correct |
63 |
Correct |
19 ms |
23808 KB |
Output is correct |
64 |
Correct |
19 ms |
23808 KB |
Output is correct |
65 |
Correct |
364 ms |
104224 KB |
Output is correct |
66 |
Correct |
408 ms |
104128 KB |
Output is correct |
67 |
Correct |
399 ms |
104148 KB |
Output is correct |
68 |
Correct |
398 ms |
104092 KB |
Output is correct |
69 |
Correct |
397 ms |
104096 KB |
Output is correct |
70 |
Correct |
390 ms |
104220 KB |
Output is correct |
71 |
Correct |
374 ms |
104092 KB |
Output is correct |
72 |
Correct |
375 ms |
104092 KB |
Output is correct |
73 |
Correct |
399 ms |
104192 KB |
Output is correct |
74 |
Correct |
404 ms |
104096 KB |
Output is correct |
75 |
Correct |
412 ms |
104092 KB |
Output is correct |
76 |
Correct |
420 ms |
104224 KB |
Output is correct |
77 |
Correct |
399 ms |
104224 KB |
Output is correct |
78 |
Correct |
414 ms |
104216 KB |
Output is correct |
79 |
Correct |
412 ms |
104092 KB |
Output is correct |
80 |
Correct |
400 ms |
104344 KB |
Output is correct |
81 |
Correct |
399 ms |
104088 KB |
Output is correct |
82 |
Correct |
402 ms |
104216 KB |
Output is correct |
83 |
Correct |
405 ms |
104096 KB |
Output is correct |
84 |
Correct |
391 ms |
104096 KB |
Output is correct |
85 |
Correct |
387 ms |
104096 KB |
Output is correct |
86 |
Correct |
397 ms |
104084 KB |
Output is correct |
87 |
Correct |
403 ms |
104092 KB |
Output is correct |
88 |
Correct |
399 ms |
104088 KB |
Output is correct |
89 |
Correct |
402 ms |
104096 KB |
Output is correct |
90 |
Correct |
407 ms |
104224 KB |
Output is correct |
91 |
Correct |
410 ms |
104088 KB |
Output is correct |
92 |
Correct |
427 ms |
104092 KB |
Output is correct |
93 |
Correct |
414 ms |
104092 KB |
Output is correct |
94 |
Correct |
423 ms |
104180 KB |
Output is correct |
95 |
Correct |
411 ms |
104092 KB |
Output is correct |
96 |
Correct |
414 ms |
104216 KB |
Output is correct |
97 |
Correct |
416 ms |
104176 KB |
Output is correct |
98 |
Correct |
421 ms |
104216 KB |
Output is correct |
99 |
Correct |
419 ms |
104056 KB |
Output is correct |
100 |
Correct |
422 ms |
104056 KB |
Output is correct |
101 |
Correct |
417 ms |
104224 KB |
Output is correct |
102 |
Correct |
423 ms |
104084 KB |
Output is correct |