# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
471858 |
2021-09-11T09:11:48 Z |
prvocislo |
Lamps (JOI19_lamps) |
C++17 |
|
883 ms |
113964 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
typedef long long ll;
using namespace std;
const int inf = 1e9 + 5, di = 3, cnt = 1 << (2 * di);
void upd(int& a, const int& b) { a = min(a, b); }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
string sa, sb;
cin >> n >> sa >> sb;
vector<int> a, b;
for (int i = 0; i < n; i++) a.push_back(sa[i] == '1');
for (int i = 0; i < n; i++) b.push_back(sb[i] == '1');
vector<int> c(cnt), v, num(cnt, -1);
for (int i = 0; i < cnt; i++)
{
int k = 0;
vector<int> f(4);
for (int j = 0; j < di; j++)
{
int val = (i >> (2 * j)) & 3;
if (val) c[i] |= val << (k * 2), k++, f[val]++;
}
if (*max_element(f.begin(), f.end()) <= 1 && c[i] == i)
num[i] = v.size(), v.push_back(i);
}
vector<vector<int> > dp(n + 1, vector<int>(v.size(), inf));
dp[0][0] = 0;
for (int i = 0; i < n; i++)
{
// ideme ukoncit par zmien - naraz vzdy len jednu
for (int j = v.size() - 1; j >= 0; j--) for (int k = 0; k < di; k++)
{
int mask = (cnt - 1) ^ (3 << (2 * k)), nw = num[c[mask & v[j]]];
if (nw != -1) upd(dp[i][nw], dp[i][j]);
}
// ideme vytvorit par zmien
for (int j = 0; j < v.size(); j++) for (int k = 0; k < di; k++)
{
int mask = (cnt - 1) ^ (3 << (2 * k)), nw = num[c[mask & v[j]]];
if (nw != -1) upd(dp[i][j], dp[i][nw] + 1);
}
// ideme na dalsi prvok
for (int j = 0; j < v.size(); j++)
{
int val = a[i];
for (int k = 0; k < di; k++)
{
int d = (v[j] >> (2 * k)) & 3;
if (d == 1) val = !val;
if (d == 2) val = 0;
if (d == 3) val = 1;
}
if (val == b[i]) upd(dp[i + 1][j], dp[i][j]);
}
}
int ans = inf;
for (int i = 0; i < v.size(); i++) upd(ans, dp[n][i]);
cout << ans << "\n";
return 0;
}
Compilation message
lamp.cpp: In function 'int main()':
lamp.cpp:46:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int j = 0; j < v.size(); j++) for (int k = 0; k < di; k++)
| ~~^~~~~~~~~~
lamp.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int j = 0; j < v.size(); j++)
| ~~^~~~~~~~~~
lamp.cpp:66:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i = 0; i < v.size(); i++) upd(ans, dp[n][i]);
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
204 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 |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
312 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
312 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 |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
308 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
204 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 |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
312 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
312 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 |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
308 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
3 ms |
460 KB |
Output is correct |
36 |
Correct |
3 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
460 KB |
Output is correct |
38 |
Correct |
2 ms |
460 KB |
Output is correct |
39 |
Correct |
2 ms |
536 KB |
Output is correct |
40 |
Correct |
2 ms |
460 KB |
Output is correct |
41 |
Correct |
2 ms |
460 KB |
Output is correct |
42 |
Correct |
2 ms |
460 KB |
Output is correct |
43 |
Correct |
2 ms |
460 KB |
Output is correct |
44 |
Correct |
2 ms |
440 KB |
Output is correct |
45 |
Correct |
2 ms |
460 KB |
Output is correct |
46 |
Correct |
2 ms |
460 KB |
Output is correct |
47 |
Correct |
2 ms |
460 KB |
Output is correct |
48 |
Correct |
2 ms |
460 KB |
Output is correct |
49 |
Correct |
2 ms |
460 KB |
Output is correct |
50 |
Correct |
2 ms |
460 KB |
Output is correct |
51 |
Correct |
2 ms |
460 KB |
Output is correct |
52 |
Correct |
2 ms |
460 KB |
Output is correct |
53 |
Correct |
2 ms |
460 KB |
Output is correct |
54 |
Correct |
3 ms |
460 KB |
Output is correct |
55 |
Correct |
2 ms |
460 KB |
Output is correct |
56 |
Correct |
2 ms |
444 KB |
Output is correct |
57 |
Correct |
2 ms |
460 KB |
Output is correct |
58 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
803 ms |
112764 KB |
Output is correct |
8 |
Correct |
883 ms |
113964 KB |
Output is correct |
9 |
Correct |
869 ms |
113836 KB |
Output is correct |
10 |
Correct |
860 ms |
113832 KB |
Output is correct |
11 |
Correct |
855 ms |
113836 KB |
Output is correct |
12 |
Correct |
813 ms |
113824 KB |
Output is correct |
13 |
Correct |
811 ms |
113832 KB |
Output is correct |
14 |
Correct |
814 ms |
113828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
204 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 |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
312 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
312 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 |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
308 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
3 ms |
460 KB |
Output is correct |
36 |
Correct |
3 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
460 KB |
Output is correct |
38 |
Correct |
2 ms |
460 KB |
Output is correct |
39 |
Correct |
2 ms |
536 KB |
Output is correct |
40 |
Correct |
2 ms |
460 KB |
Output is correct |
41 |
Correct |
2 ms |
460 KB |
Output is correct |
42 |
Correct |
2 ms |
460 KB |
Output is correct |
43 |
Correct |
2 ms |
460 KB |
Output is correct |
44 |
Correct |
2 ms |
440 KB |
Output is correct |
45 |
Correct |
2 ms |
460 KB |
Output is correct |
46 |
Correct |
2 ms |
460 KB |
Output is correct |
47 |
Correct |
2 ms |
460 KB |
Output is correct |
48 |
Correct |
2 ms |
460 KB |
Output is correct |
49 |
Correct |
2 ms |
460 KB |
Output is correct |
50 |
Correct |
2 ms |
460 KB |
Output is correct |
51 |
Correct |
2 ms |
460 KB |
Output is correct |
52 |
Correct |
2 ms |
460 KB |
Output is correct |
53 |
Correct |
2 ms |
460 KB |
Output is correct |
54 |
Correct |
3 ms |
460 KB |
Output is correct |
55 |
Correct |
2 ms |
460 KB |
Output is correct |
56 |
Correct |
2 ms |
444 KB |
Output is correct |
57 |
Correct |
2 ms |
460 KB |
Output is correct |
58 |
Correct |
2 ms |
464 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
0 ms |
204 KB |
Output is correct |
61 |
Correct |
1 ms |
204 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 |
803 ms |
112764 KB |
Output is correct |
66 |
Correct |
883 ms |
113964 KB |
Output is correct |
67 |
Correct |
869 ms |
113836 KB |
Output is correct |
68 |
Correct |
860 ms |
113832 KB |
Output is correct |
69 |
Correct |
855 ms |
113836 KB |
Output is correct |
70 |
Correct |
813 ms |
113824 KB |
Output is correct |
71 |
Correct |
811 ms |
113832 KB |
Output is correct |
72 |
Correct |
814 ms |
113828 KB |
Output is correct |
73 |
Correct |
824 ms |
113908 KB |
Output is correct |
74 |
Correct |
825 ms |
113836 KB |
Output is correct |
75 |
Correct |
845 ms |
113832 KB |
Output is correct |
76 |
Correct |
835 ms |
113868 KB |
Output is correct |
77 |
Correct |
856 ms |
113836 KB |
Output is correct |
78 |
Correct |
839 ms |
113832 KB |
Output is correct |
79 |
Correct |
838 ms |
113832 KB |
Output is correct |
80 |
Correct |
838 ms |
113836 KB |
Output is correct |
81 |
Correct |
862 ms |
113892 KB |
Output is correct |
82 |
Correct |
842 ms |
113832 KB |
Output is correct |
83 |
Correct |
836 ms |
113852 KB |
Output is correct |
84 |
Correct |
825 ms |
113732 KB |
Output is correct |
85 |
Correct |
823 ms |
113828 KB |
Output is correct |
86 |
Correct |
825 ms |
113832 KB |
Output is correct |
87 |
Correct |
842 ms |
113880 KB |
Output is correct |
88 |
Correct |
828 ms |
113828 KB |
Output is correct |
89 |
Correct |
849 ms |
113932 KB |
Output is correct |
90 |
Correct |
832 ms |
113828 KB |
Output is correct |
91 |
Correct |
863 ms |
113828 KB |
Output is correct |
92 |
Correct |
835 ms |
113828 KB |
Output is correct |
93 |
Correct |
862 ms |
113828 KB |
Output is correct |
94 |
Correct |
832 ms |
113832 KB |
Output is correct |
95 |
Correct |
822 ms |
113724 KB |
Output is correct |
96 |
Correct |
837 ms |
113792 KB |
Output is correct |
97 |
Correct |
830 ms |
113908 KB |
Output is correct |
98 |
Correct |
866 ms |
113832 KB |
Output is correct |
99 |
Correct |
825 ms |
113828 KB |
Output is correct |
100 |
Correct |
823 ms |
113832 KB |
Output is correct |
101 |
Correct |
864 ms |
113828 KB |
Output is correct |
102 |
Correct |
853 ms |
113920 KB |
Output is correct |