# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
444469 |
2021-07-14T07:06:20 Z |
blue |
Lamps (JOI19_lamps) |
C++17 |
|
725 ms |
6292 KB |
#include <iostream>
#include <vector>
using namespace std;
/*
States:
0 nothing
1 on
2 off
3 toggle
4 on + off
5 on + toggle
6 off + on
7 off + toggle
8 toggle + on
9 toggle + off
*/
const int off = 0;
const int on = 1;
const int toggle = 2;
string s[3] = {"OFF", "ON", "TOGGLE"};
int op_res(int a, int b)
{
if(b == off) return 0;
else if(b == on) return 1;
else return !a;
}
vector<int> ops[10];
int ops_res(int a, int b)
{
for(int x: ops[b]) a = op_res(a, x);
return a;
}
int cost(int ops1, int ops2)
{
int ans = ops[ops2].size();
int reducevalue = 0;
if(ops[ops1] == ops[ops2]) reducevalue = ops[ops2].size();
else
{
for(int x: ops[ops1])
for(int y: ops[ops2])
if(x == y)
reducevalue = 1;
}
return ans - reducevalue;
}
const long long INF = 1'000'000'000LL;
long long* dp1;
long long* dp2;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ops[0] = vector<int>{};
ops[1] = vector<int>{off};
ops[2] = vector<int>{on};
ops[3] = vector<int>{toggle};
ops[4] = vector<int>{off, on};
ops[5] = vector<int>{off, toggle};
ops[6] = vector<int>{on, off};
ops[7] = vector<int>{on, toggle};
ops[8] = vector<int>{toggle, off};
ops[9] = vector<int>{toggle, on};
// for(int i = 0; i <= 9; i++)
// for(int j = 0; j <= 9; j++)
// {
// for(int x: ops[i]) cerr << s[x] << ' ';
// cerr << "-> ";
// for(int y: ops[j]) cerr << s[y] << ' ';
// cerr << ": ";
// cerr << cost(i, j) << '\n';
// }
int N;
cin >> N;
string A;
cin >> A;
A = " " + A;
string B;
cin >> B;
B = " " + B;
dp1 = new long long[10];
dp2 = new long long[10];
dp2[0] = 0;
for(int o = 1; o < 10; o++) dp2[o] = INF;
for(int i = 1; i <= N; i++)
{
swap(dp1, dp2);
for(int o2 = 0; o2 < 10; o2++)
{
if(ops_res(A[i] - '0', o2) != (B[i] - '0'))
{
dp2[o2] = INF;
}
else
{
dp2[o2] = INF;
for(int o1 = 0; o1 < 10; o1++)
{
dp2[o2] = min(dp2[o2], dp1[o1] + cost(o1, o2));
}
}
}
}
long long ans = INF;
for(int o = 0; o < 10; o++)
ans = min(ans, dp2[o]);
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
312 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
0 ms |
312 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
312 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
0 ms |
312 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
2 ms |
204 KB |
Output is correct |
36 |
Correct |
2 ms |
204 KB |
Output is correct |
37 |
Correct |
2 ms |
312 KB |
Output is correct |
38 |
Correct |
2 ms |
204 KB |
Output is correct |
39 |
Correct |
2 ms |
204 KB |
Output is correct |
40 |
Correct |
2 ms |
204 KB |
Output is correct |
41 |
Correct |
2 ms |
204 KB |
Output is correct |
42 |
Correct |
2 ms |
204 KB |
Output is correct |
43 |
Correct |
2 ms |
204 KB |
Output is correct |
44 |
Correct |
2 ms |
204 KB |
Output is correct |
45 |
Correct |
2 ms |
204 KB |
Output is correct |
46 |
Correct |
2 ms |
204 KB |
Output is correct |
47 |
Correct |
2 ms |
204 KB |
Output is correct |
48 |
Correct |
2 ms |
204 KB |
Output is correct |
49 |
Correct |
3 ms |
204 KB |
Output is correct |
50 |
Correct |
2 ms |
204 KB |
Output is correct |
51 |
Correct |
2 ms |
312 KB |
Output is correct |
52 |
Correct |
2 ms |
204 KB |
Output is correct |
53 |
Correct |
2 ms |
204 KB |
Output is correct |
54 |
Correct |
2 ms |
204 KB |
Output is correct |
55 |
Correct |
2 ms |
316 KB |
Output is correct |
56 |
Correct |
2 ms |
204 KB |
Output is correct |
57 |
Correct |
2 ms |
204 KB |
Output is correct |
58 |
Correct |
2 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
308 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 |
204 KB |
Output is correct |
7 |
Correct |
632 ms |
6180 KB |
Output is correct |
8 |
Correct |
640 ms |
6168 KB |
Output is correct |
9 |
Correct |
722 ms |
6176 KB |
Output is correct |
10 |
Correct |
638 ms |
6280 KB |
Output is correct |
11 |
Correct |
685 ms |
6180 KB |
Output is correct |
12 |
Correct |
634 ms |
6168 KB |
Output is correct |
13 |
Correct |
612 ms |
6176 KB |
Output is correct |
14 |
Correct |
611 ms |
6176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
312 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
0 ms |
312 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
2 ms |
204 KB |
Output is correct |
36 |
Correct |
2 ms |
204 KB |
Output is correct |
37 |
Correct |
2 ms |
312 KB |
Output is correct |
38 |
Correct |
2 ms |
204 KB |
Output is correct |
39 |
Correct |
2 ms |
204 KB |
Output is correct |
40 |
Correct |
2 ms |
204 KB |
Output is correct |
41 |
Correct |
2 ms |
204 KB |
Output is correct |
42 |
Correct |
2 ms |
204 KB |
Output is correct |
43 |
Correct |
2 ms |
204 KB |
Output is correct |
44 |
Correct |
2 ms |
204 KB |
Output is correct |
45 |
Correct |
2 ms |
204 KB |
Output is correct |
46 |
Correct |
2 ms |
204 KB |
Output is correct |
47 |
Correct |
2 ms |
204 KB |
Output is correct |
48 |
Correct |
2 ms |
204 KB |
Output is correct |
49 |
Correct |
3 ms |
204 KB |
Output is correct |
50 |
Correct |
2 ms |
204 KB |
Output is correct |
51 |
Correct |
2 ms |
312 KB |
Output is correct |
52 |
Correct |
2 ms |
204 KB |
Output is correct |
53 |
Correct |
2 ms |
204 KB |
Output is correct |
54 |
Correct |
2 ms |
204 KB |
Output is correct |
55 |
Correct |
2 ms |
316 KB |
Output is correct |
56 |
Correct |
2 ms |
204 KB |
Output is correct |
57 |
Correct |
2 ms |
204 KB |
Output is correct |
58 |
Correct |
2 ms |
312 KB |
Output is correct |
59 |
Correct |
0 ms |
204 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
1 ms |
308 KB |
Output is correct |
62 |
Correct |
1 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
204 KB |
Output is correct |
64 |
Correct |
1 ms |
204 KB |
Output is correct |
65 |
Correct |
632 ms |
6180 KB |
Output is correct |
66 |
Correct |
640 ms |
6168 KB |
Output is correct |
67 |
Correct |
722 ms |
6176 KB |
Output is correct |
68 |
Correct |
638 ms |
6280 KB |
Output is correct |
69 |
Correct |
685 ms |
6180 KB |
Output is correct |
70 |
Correct |
634 ms |
6168 KB |
Output is correct |
71 |
Correct |
612 ms |
6176 KB |
Output is correct |
72 |
Correct |
611 ms |
6176 KB |
Output is correct |
73 |
Correct |
631 ms |
6172 KB |
Output is correct |
74 |
Correct |
669 ms |
6176 KB |
Output is correct |
75 |
Correct |
672 ms |
6280 KB |
Output is correct |
76 |
Correct |
675 ms |
6180 KB |
Output is correct |
77 |
Correct |
661 ms |
6172 KB |
Output is correct |
78 |
Correct |
641 ms |
6280 KB |
Output is correct |
79 |
Correct |
725 ms |
6172 KB |
Output is correct |
80 |
Correct |
653 ms |
6188 KB |
Output is correct |
81 |
Correct |
665 ms |
6172 KB |
Output is correct |
82 |
Correct |
644 ms |
6284 KB |
Output is correct |
83 |
Correct |
617 ms |
6176 KB |
Output is correct |
84 |
Correct |
620 ms |
6188 KB |
Output is correct |
85 |
Correct |
619 ms |
6172 KB |
Output is correct |
86 |
Correct |
688 ms |
6180 KB |
Output is correct |
87 |
Correct |
656 ms |
6280 KB |
Output is correct |
88 |
Correct |
654 ms |
6172 KB |
Output is correct |
89 |
Correct |
642 ms |
6172 KB |
Output is correct |
90 |
Correct |
643 ms |
6292 KB |
Output is correct |
91 |
Correct |
701 ms |
6176 KB |
Output is correct |
92 |
Correct |
659 ms |
6280 KB |
Output is correct |
93 |
Correct |
689 ms |
6176 KB |
Output is correct |
94 |
Correct |
717 ms |
6176 KB |
Output is correct |
95 |
Correct |
684 ms |
6172 KB |
Output is correct |
96 |
Correct |
661 ms |
6164 KB |
Output is correct |
97 |
Correct |
665 ms |
6172 KB |
Output is correct |
98 |
Correct |
680 ms |
6196 KB |
Output is correct |
99 |
Correct |
659 ms |
6172 KB |
Output is correct |
100 |
Correct |
668 ms |
6172 KB |
Output is correct |
101 |
Correct |
700 ms |
6172 KB |
Output is correct |
102 |
Correct |
651 ms |
6168 KB |
Output is correct |