# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
105004 |
2019-04-10T05:37:02 Z |
antimirage |
Lamps (JOI19_lamps) |
C++14 |
|
1000 ms |
18724 KB |
# include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, dp[N][2];
char a[N], b[N];
struct st{
int must, val;
};
st t[4][4][N * 4];
inline int min(int a, int b)
{
return a < b ? a : b;
}
inline void push (const int &i, const int &j, const int &v, const int &tl, const int &tr)
{
t[i][j][v].val += t[i][j][v].must;
if (tl != tr){
t[i][j][v + v].must += t[i][j][v].must,
t[i][j][v + v + 1].must += t[i][j][v].must;
}
t[i][j][v].must = 0;
}
void update (const int &i, const int &j, const int &l, const int &r, const int &val, const int & v = 1, const int & tl = 0, const int & tr = n)
{
push(i, j, v, tl, tr);
if (l > tr || tl > r) return;
if (l <= tl && tr <= r){
t[i][j][v].must += val;
push(i, j, v, tl, tr);
return;
}
int tm = (tl + tr) >> 1;
update(i, j, l, r, val, v + v, tl, tm);
update(i, j, l, r, val, v + v + 1, tm + 1, tr);
t[i][j][v].val = min( t[i][j][v + v].val, t[i][j][v + v + 1].val );
}
int get (const int &i, const int &j, const int &l, const int &r, const int &v = 1, const int &tl = 0, const int &tr = n)
{
push(i, j, v, tl, tr);
if (l > tr || tl > r)
return 1e9 + 7;
if (l <= tl && tr <= r){
return t[i][j][v].val;
}
int tm = (tl + tr) >> 1;
return min( get(i, j, l, r, v + v, tl, tm), get(i, j, l, r, v + v + 1, tm + 1, tr) );
}
main(){
memset( dp, 0x3f3f3f3f, sizeof(dp) );
cin >> n;
scanf("\n%s", a + 1);
scanf("\n%s", b + 1);
dp[0][0] = 0;
update( 1, 0, 0, 0, dp[0][1] );
update( 1, 1, 0, 0, dp[0][1] );
update( 2, 0, 0, 0, dp[0][1] );
update( 0, 2, 0, 0, dp[0][1] );
for (int i = 1; i <= n; i++){
if (b[i] != b[i - 1] && i - 2 >= 0){
update(0, b[i] - 48, 0, i - 2, +1);
update(1, b[i] - 48, 0, i - 2, +1);
if (b[i] == '1')
update(2, 0, 0, i - 2, +1);
if (b[i] == '0')
update(0, 2, 0, i - 2, +1);
}
if (b[i] == '1')
update(2, 0, i - 1, i - 1, -1);
if (b[i] == '0')
update(0, 2, i - 1, i - 1, -1);
if (b[i] == '1')
update(2, 0, i - 1, i - 1, +1);
if (b[i] == '0')
update(0, 2, i - 1, i - 1, +1);
update(0, b[i] - 48, i - 1, i - 1, +1);
update(1, b[i] - 48, i - 1, i - 1, +1);
if (a[i] == b[i])
dp[i][0] = min( dp[i - 1][1], dp[i - 1][0] );
if (a[i] != b[i])
dp[i][1] = min( dp[i - 1][1], dp[i - 1][0] + 1);
dp[i][0] = min( dp[i][0], get(0, 1, 0, i - 1) + 1 );
dp[i][0] = min( dp[i][0], get(0, 0, 0, i - 1) + 1 );
dp[i][1] = min( dp[i][1], get(1, 0, 0, i - 1) + 1 );
dp[i][1] = min( dp[i][1], get(1, 1, 0, i - 1) + 1 );
dp[i][1] = min( dp[i][1], get(0, 0, 0, i - 1) - (b[i] == '0') + 2 );
dp[i][1] = min( dp[i][1], get(0, 1, 0, i - 1) - (b[i] == '1') + 2 );
dp[i][0] = min( dp[i][0], get(2, 0, 0, i - 1) + 1 );
dp[i][0] = min( dp[i][0], get(0, 2, 0, i - 1) + 1 );
dp[i][1] = min( dp[i][1], get(0, 2, 0, i - 1) - (b[i] == '0') + 2 );
dp[i][1] = min( dp[i][1], get(2, 0, 0, i - 1) - (b[i] == '1') + 2 );
update( 0, 0, i, i, dp[i][0] );
update( 0, 1, i, i, dp[i][0] );
update( 1, 0, i, i, dp[i][1] );
update( 1, 1, i, i, dp[i][1] );
update( 2, 0, i, i, dp[i][1] );
update( 0, 2, i, i, dp[i][1] );
}
cout << min( dp[n][0], dp[n][1] ) << endl;
}
/**
13
0101100101001
1011111000000
13
0001101001101
0101100011011
8
11011100
01101001
**/
Compilation message
lamp.cpp:67:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
lamp.cpp: In function 'int main()':
lamp.cpp:72:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("\n%s", a + 1);
~~~~~^~~~~~~~~~~~~~~
lamp.cpp:73:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("\n%s", b + 1);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8192 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
8 ms |
8192 KB |
Output is correct |
4 |
Correct |
10 ms |
8192 KB |
Output is correct |
5 |
Correct |
9 ms |
8164 KB |
Output is correct |
6 |
Correct |
9 ms |
8192 KB |
Output is correct |
7 |
Correct |
8 ms |
8192 KB |
Output is correct |
8 |
Correct |
9 ms |
8192 KB |
Output is correct |
9 |
Correct |
9 ms |
8192 KB |
Output is correct |
10 |
Correct |
10 ms |
8184 KB |
Output is correct |
11 |
Correct |
9 ms |
8192 KB |
Output is correct |
12 |
Correct |
8 ms |
8192 KB |
Output is correct |
13 |
Correct |
8 ms |
8192 KB |
Output is correct |
14 |
Correct |
9 ms |
8164 KB |
Output is correct |
15 |
Correct |
10 ms |
8192 KB |
Output is correct |
16 |
Correct |
11 ms |
8192 KB |
Output is correct |
17 |
Correct |
8 ms |
8192 KB |
Output is correct |
18 |
Correct |
9 ms |
8192 KB |
Output is correct |
19 |
Correct |
8 ms |
8192 KB |
Output is correct |
20 |
Correct |
11 ms |
8192 KB |
Output is correct |
21 |
Correct |
9 ms |
8320 KB |
Output is correct |
22 |
Correct |
8 ms |
8192 KB |
Output is correct |
23 |
Correct |
9 ms |
8164 KB |
Output is correct |
24 |
Correct |
9 ms |
8192 KB |
Output is correct |
25 |
Correct |
9 ms |
8192 KB |
Output is correct |
26 |
Correct |
8 ms |
8192 KB |
Output is correct |
27 |
Correct |
9 ms |
8192 KB |
Output is correct |
28 |
Correct |
9 ms |
8192 KB |
Output is correct |
29 |
Correct |
8 ms |
8192 KB |
Output is correct |
30 |
Correct |
10 ms |
8280 KB |
Output is correct |
31 |
Correct |
9 ms |
8192 KB |
Output is correct |
32 |
Correct |
9 ms |
8192 KB |
Output is correct |
33 |
Correct |
8 ms |
8192 KB |
Output is correct |
34 |
Correct |
8 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8192 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
8 ms |
8192 KB |
Output is correct |
4 |
Correct |
10 ms |
8192 KB |
Output is correct |
5 |
Correct |
9 ms |
8164 KB |
Output is correct |
6 |
Correct |
9 ms |
8192 KB |
Output is correct |
7 |
Correct |
8 ms |
8192 KB |
Output is correct |
8 |
Correct |
9 ms |
8192 KB |
Output is correct |
9 |
Correct |
9 ms |
8192 KB |
Output is correct |
10 |
Correct |
10 ms |
8184 KB |
Output is correct |
11 |
Correct |
9 ms |
8192 KB |
Output is correct |
12 |
Correct |
8 ms |
8192 KB |
Output is correct |
13 |
Correct |
8 ms |
8192 KB |
Output is correct |
14 |
Correct |
9 ms |
8164 KB |
Output is correct |
15 |
Correct |
10 ms |
8192 KB |
Output is correct |
16 |
Correct |
11 ms |
8192 KB |
Output is correct |
17 |
Correct |
8 ms |
8192 KB |
Output is correct |
18 |
Correct |
9 ms |
8192 KB |
Output is correct |
19 |
Correct |
8 ms |
8192 KB |
Output is correct |
20 |
Correct |
11 ms |
8192 KB |
Output is correct |
21 |
Correct |
9 ms |
8320 KB |
Output is correct |
22 |
Correct |
8 ms |
8192 KB |
Output is correct |
23 |
Correct |
9 ms |
8164 KB |
Output is correct |
24 |
Correct |
9 ms |
8192 KB |
Output is correct |
25 |
Correct |
9 ms |
8192 KB |
Output is correct |
26 |
Correct |
8 ms |
8192 KB |
Output is correct |
27 |
Correct |
9 ms |
8192 KB |
Output is correct |
28 |
Correct |
9 ms |
8192 KB |
Output is correct |
29 |
Correct |
8 ms |
8192 KB |
Output is correct |
30 |
Correct |
10 ms |
8280 KB |
Output is correct |
31 |
Correct |
9 ms |
8192 KB |
Output is correct |
32 |
Correct |
9 ms |
8192 KB |
Output is correct |
33 |
Correct |
8 ms |
8192 KB |
Output is correct |
34 |
Correct |
8 ms |
8192 KB |
Output is correct |
35 |
Correct |
27 ms |
8420 KB |
Output is correct |
36 |
Correct |
21 ms |
8420 KB |
Output is correct |
37 |
Correct |
22 ms |
8448 KB |
Output is correct |
38 |
Correct |
26 ms |
8440 KB |
Output is correct |
39 |
Correct |
19 ms |
8448 KB |
Output is correct |
40 |
Correct |
27 ms |
8420 KB |
Output is correct |
41 |
Correct |
20 ms |
8440 KB |
Output is correct |
42 |
Correct |
30 ms |
8448 KB |
Output is correct |
43 |
Correct |
22 ms |
8440 KB |
Output is correct |
44 |
Correct |
28 ms |
8444 KB |
Output is correct |
45 |
Correct |
21 ms |
8448 KB |
Output is correct |
46 |
Correct |
21 ms |
8444 KB |
Output is correct |
47 |
Correct |
22 ms |
8472 KB |
Output is correct |
48 |
Correct |
21 ms |
8448 KB |
Output is correct |
49 |
Correct |
25 ms |
8448 KB |
Output is correct |
50 |
Correct |
22 ms |
8480 KB |
Output is correct |
51 |
Correct |
20 ms |
8448 KB |
Output is correct |
52 |
Correct |
21 ms |
8448 KB |
Output is correct |
53 |
Correct |
26 ms |
8440 KB |
Output is correct |
54 |
Correct |
26 ms |
8336 KB |
Output is correct |
55 |
Correct |
30 ms |
8444 KB |
Output is correct |
56 |
Correct |
23 ms |
8440 KB |
Output is correct |
57 |
Correct |
21 ms |
8448 KB |
Output is correct |
58 |
Correct |
22 ms |
8420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8164 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
10 ms |
8276 KB |
Output is correct |
4 |
Correct |
8 ms |
8192 KB |
Output is correct |
5 |
Correct |
9 ms |
8192 KB |
Output is correct |
6 |
Correct |
9 ms |
8192 KB |
Output is correct |
7 |
Execution timed out |
1049 ms |
18724 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8192 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
8 ms |
8192 KB |
Output is correct |
4 |
Correct |
10 ms |
8192 KB |
Output is correct |
5 |
Correct |
9 ms |
8164 KB |
Output is correct |
6 |
Correct |
9 ms |
8192 KB |
Output is correct |
7 |
Correct |
8 ms |
8192 KB |
Output is correct |
8 |
Correct |
9 ms |
8192 KB |
Output is correct |
9 |
Correct |
9 ms |
8192 KB |
Output is correct |
10 |
Correct |
10 ms |
8184 KB |
Output is correct |
11 |
Correct |
9 ms |
8192 KB |
Output is correct |
12 |
Correct |
8 ms |
8192 KB |
Output is correct |
13 |
Correct |
8 ms |
8192 KB |
Output is correct |
14 |
Correct |
9 ms |
8164 KB |
Output is correct |
15 |
Correct |
10 ms |
8192 KB |
Output is correct |
16 |
Correct |
11 ms |
8192 KB |
Output is correct |
17 |
Correct |
8 ms |
8192 KB |
Output is correct |
18 |
Correct |
9 ms |
8192 KB |
Output is correct |
19 |
Correct |
8 ms |
8192 KB |
Output is correct |
20 |
Correct |
11 ms |
8192 KB |
Output is correct |
21 |
Correct |
9 ms |
8320 KB |
Output is correct |
22 |
Correct |
8 ms |
8192 KB |
Output is correct |
23 |
Correct |
9 ms |
8164 KB |
Output is correct |
24 |
Correct |
9 ms |
8192 KB |
Output is correct |
25 |
Correct |
9 ms |
8192 KB |
Output is correct |
26 |
Correct |
8 ms |
8192 KB |
Output is correct |
27 |
Correct |
9 ms |
8192 KB |
Output is correct |
28 |
Correct |
9 ms |
8192 KB |
Output is correct |
29 |
Correct |
8 ms |
8192 KB |
Output is correct |
30 |
Correct |
10 ms |
8280 KB |
Output is correct |
31 |
Correct |
9 ms |
8192 KB |
Output is correct |
32 |
Correct |
9 ms |
8192 KB |
Output is correct |
33 |
Correct |
8 ms |
8192 KB |
Output is correct |
34 |
Correct |
8 ms |
8192 KB |
Output is correct |
35 |
Correct |
27 ms |
8420 KB |
Output is correct |
36 |
Correct |
21 ms |
8420 KB |
Output is correct |
37 |
Correct |
22 ms |
8448 KB |
Output is correct |
38 |
Correct |
26 ms |
8440 KB |
Output is correct |
39 |
Correct |
19 ms |
8448 KB |
Output is correct |
40 |
Correct |
27 ms |
8420 KB |
Output is correct |
41 |
Correct |
20 ms |
8440 KB |
Output is correct |
42 |
Correct |
30 ms |
8448 KB |
Output is correct |
43 |
Correct |
22 ms |
8440 KB |
Output is correct |
44 |
Correct |
28 ms |
8444 KB |
Output is correct |
45 |
Correct |
21 ms |
8448 KB |
Output is correct |
46 |
Correct |
21 ms |
8444 KB |
Output is correct |
47 |
Correct |
22 ms |
8472 KB |
Output is correct |
48 |
Correct |
21 ms |
8448 KB |
Output is correct |
49 |
Correct |
25 ms |
8448 KB |
Output is correct |
50 |
Correct |
22 ms |
8480 KB |
Output is correct |
51 |
Correct |
20 ms |
8448 KB |
Output is correct |
52 |
Correct |
21 ms |
8448 KB |
Output is correct |
53 |
Correct |
26 ms |
8440 KB |
Output is correct |
54 |
Correct |
26 ms |
8336 KB |
Output is correct |
55 |
Correct |
30 ms |
8444 KB |
Output is correct |
56 |
Correct |
23 ms |
8440 KB |
Output is correct |
57 |
Correct |
21 ms |
8448 KB |
Output is correct |
58 |
Correct |
22 ms |
8420 KB |
Output is correct |
59 |
Correct |
9 ms |
8164 KB |
Output is correct |
60 |
Correct |
9 ms |
8192 KB |
Output is correct |
61 |
Correct |
10 ms |
8276 KB |
Output is correct |
62 |
Correct |
8 ms |
8192 KB |
Output is correct |
63 |
Correct |
9 ms |
8192 KB |
Output is correct |
64 |
Correct |
9 ms |
8192 KB |
Output is correct |
65 |
Execution timed out |
1049 ms |
18724 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |