# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
965024 |
2024-04-18T03:19:17 Z |
abczz |
Lamps (JOI19_lamps) |
C++14 |
|
431 ms |
98456 KB |
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#define ll long long
using namespace std;
ll n, f = 1e18, dp[1000000][12];
string S, T;
ll get(ll u, vector <ll> state) {
ll mn = 1e18;
for (auto v : state) mn = min(mn, dp[u][v]);
return mn;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cin >> n >> S >> T;
for (int i=0; i<n; ++i) {
for (int j=0; j<12; ++j) dp[i][j] = 1e18;
if (S[i] != T[i]) {
if (!i) dp[i][2] = 1;
else dp[i][2] = min(get(i-1, {2, 3, 4, 5, 6, 7, 8}), get(i-1, {0, 1, 9, 10, 11})+1);
}
else {
if (!i) dp[i][9] = 0;
else {
for (int j=0; j<12; ++j) {
dp[i][9] = min(dp[i][9], dp[i-1][j]);
}
}
}
if (T[i] == '0') {
if (!i) dp[i][0] = 1, dp[i][4] = dp[i][5] = dp[i][11] = 2, dp[i][8] = 3;
else {
dp[i][0] = min(get(i-1, {0, 3, 5, 7, 8, 10, 11}), get(i-1, {1, 2, 4, 6, 9})+1);
dp[i][4] = min(get(i-1, {4}), min(get(i-1, {1, 2, 3, 5, 6, 7, 8, 10, 11})+1, get(i-1, {0, 9})+2));
dp[i][5] = min(get(i-1, {5, 7, 8}), min(get(i-1, {0, 2, 3, 4, 6, 10, 11})+1, get(i-1, {1, 9})+2));
dp[i][8] = min(get(i-1, {8}), min(get(i-1, {5, 6, 7, 11})+1, min(get(i-1, {0, 1, 2, 3, 4, 10})+2, get(i-1, {9})+3)));
dp[i][11] = min(get(i-1, {8, 11}), min(get(i-1, {0, 1, 3, 4, 5, 6, 7, 10})+1, get(i-1, {2, 9})+2));
}
}
else {
if (!i) dp[i][1] = 1, dp[i][3] = dp[i][6] = dp[i][10] = 2, dp[i][7] = 3;
else {
dp[i][1] = min(get(i-1, {1, 4, 6, 7, 8, 10, 11}), get(i-1, {0, 2, 3, 5, 9})+1);
dp[i][3] = min(get(i-1, {3}), min(get(i-1, {0, 2, 4, 5, 6, 7, 8, 10, 11})+1, get(i-1, {1, 9})+2));
dp[i][6] = min(get(i-1, {6, 7, 8}), min(get(i-1, {1, 2, 3, 4, 5, 10, 11})+1, get(i-1, {0, 9}))+2);
dp[i][7] = min(get(i-1, {7}), min(get(i-1, {5, 6, 8, 10})+1, min(get(i-1, {0, 1, 2, 3, 4, 11})+2, get(i-1, {9})+3)));
dp[i][10] = min(get(i-1, {7, 10}), min(get(i-1, {0, 1, 3, 4, 5, 6, 8, 11})+1, get(i-1, {2, 9})+2));
}
}
}
for (int j=0; j<12; ++j) {
f = min(f, dp[n-1][j]);
}
cout << f << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
468 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
468 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2516 KB |
Output is correct |
37 |
Correct |
3 ms |
2648 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
4 ms |
2652 KB |
Output is correct |
40 |
Correct |
1 ms |
2652 KB |
Output is correct |
41 |
Correct |
2 ms |
2652 KB |
Output is correct |
42 |
Correct |
1 ms |
2652 KB |
Output is correct |
43 |
Correct |
2 ms |
2652 KB |
Output is correct |
44 |
Correct |
1 ms |
2652 KB |
Output is correct |
45 |
Correct |
3 ms |
2652 KB |
Output is correct |
46 |
Correct |
2 ms |
2652 KB |
Output is correct |
47 |
Correct |
1 ms |
2648 KB |
Output is correct |
48 |
Correct |
2 ms |
2648 KB |
Output is correct |
49 |
Correct |
1 ms |
2652 KB |
Output is correct |
50 |
Correct |
1 ms |
2652 KB |
Output is correct |
51 |
Correct |
1 ms |
2652 KB |
Output is correct |
52 |
Correct |
2 ms |
2652 KB |
Output is correct |
53 |
Correct |
1 ms |
2652 KB |
Output is correct |
54 |
Correct |
2 ms |
2648 KB |
Output is correct |
55 |
Correct |
3 ms |
2648 KB |
Output is correct |
56 |
Correct |
1 ms |
2652 KB |
Output is correct |
57 |
Correct |
1 ms |
2652 KB |
Output is correct |
58 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
431 ms |
98432 KB |
Output is correct |
8 |
Correct |
352 ms |
98392 KB |
Output is correct |
9 |
Correct |
347 ms |
98220 KB |
Output is correct |
10 |
Correct |
383 ms |
98268 KB |
Output is correct |
11 |
Correct |
359 ms |
98400 KB |
Output is correct |
12 |
Correct |
339 ms |
98288 KB |
Output is correct |
13 |
Correct |
330 ms |
98208 KB |
Output is correct |
14 |
Correct |
334 ms |
98404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
468 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2516 KB |
Output is correct |
37 |
Correct |
3 ms |
2648 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
4 ms |
2652 KB |
Output is correct |
40 |
Correct |
1 ms |
2652 KB |
Output is correct |
41 |
Correct |
2 ms |
2652 KB |
Output is correct |
42 |
Correct |
1 ms |
2652 KB |
Output is correct |
43 |
Correct |
2 ms |
2652 KB |
Output is correct |
44 |
Correct |
1 ms |
2652 KB |
Output is correct |
45 |
Correct |
3 ms |
2652 KB |
Output is correct |
46 |
Correct |
2 ms |
2652 KB |
Output is correct |
47 |
Correct |
1 ms |
2648 KB |
Output is correct |
48 |
Correct |
2 ms |
2648 KB |
Output is correct |
49 |
Correct |
1 ms |
2652 KB |
Output is correct |
50 |
Correct |
1 ms |
2652 KB |
Output is correct |
51 |
Correct |
1 ms |
2652 KB |
Output is correct |
52 |
Correct |
2 ms |
2652 KB |
Output is correct |
53 |
Correct |
1 ms |
2652 KB |
Output is correct |
54 |
Correct |
2 ms |
2648 KB |
Output is correct |
55 |
Correct |
3 ms |
2648 KB |
Output is correct |
56 |
Correct |
1 ms |
2652 KB |
Output is correct |
57 |
Correct |
1 ms |
2652 KB |
Output is correct |
58 |
Correct |
1 ms |
2652 KB |
Output is correct |
59 |
Correct |
1 ms |
460 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
431 ms |
98432 KB |
Output is correct |
66 |
Correct |
352 ms |
98392 KB |
Output is correct |
67 |
Correct |
347 ms |
98220 KB |
Output is correct |
68 |
Correct |
383 ms |
98268 KB |
Output is correct |
69 |
Correct |
359 ms |
98400 KB |
Output is correct |
70 |
Correct |
339 ms |
98288 KB |
Output is correct |
71 |
Correct |
330 ms |
98208 KB |
Output is correct |
72 |
Correct |
334 ms |
98404 KB |
Output is correct |
73 |
Correct |
397 ms |
98272 KB |
Output is correct |
74 |
Correct |
341 ms |
98260 KB |
Output is correct |
75 |
Correct |
424 ms |
98216 KB |
Output is correct |
76 |
Correct |
425 ms |
98292 KB |
Output is correct |
77 |
Correct |
356 ms |
98432 KB |
Output is correct |
78 |
Correct |
358 ms |
98392 KB |
Output is correct |
79 |
Correct |
340 ms |
98216 KB |
Output is correct |
80 |
Correct |
391 ms |
98256 KB |
Output is correct |
81 |
Correct |
403 ms |
98180 KB |
Output is correct |
82 |
Correct |
381 ms |
98188 KB |
Output is correct |
83 |
Correct |
350 ms |
98392 KB |
Output is correct |
84 |
Correct |
356 ms |
98208 KB |
Output is correct |
85 |
Correct |
366 ms |
98456 KB |
Output is correct |
86 |
Correct |
395 ms |
98204 KB |
Output is correct |
87 |
Correct |
349 ms |
98296 KB |
Output is correct |
88 |
Correct |
366 ms |
98256 KB |
Output is correct |
89 |
Correct |
345 ms |
98296 KB |
Output is correct |
90 |
Correct |
347 ms |
98404 KB |
Output is correct |
91 |
Correct |
383 ms |
98212 KB |
Output is correct |
92 |
Correct |
374 ms |
98380 KB |
Output is correct |
93 |
Correct |
398 ms |
98280 KB |
Output is correct |
94 |
Correct |
360 ms |
98296 KB |
Output is correct |
95 |
Correct |
372 ms |
98216 KB |
Output is correct |
96 |
Correct |
389 ms |
98392 KB |
Output is correct |
97 |
Correct |
368 ms |
98300 KB |
Output is correct |
98 |
Correct |
367 ms |
98268 KB |
Output is correct |
99 |
Correct |
361 ms |
98424 KB |
Output is correct |
100 |
Correct |
430 ms |
98288 KB |
Output is correct |
101 |
Correct |
399 ms |
98276 KB |
Output is correct |
102 |
Correct |
375 ms |
98420 KB |
Output is correct |