// incorrect/felix-tomek-hieroglyphs-greedy-bothsides.cpp
#include "hieroglyphs.h"
#include <vector>
#include <algorithm>
using std::vector;
constexpr int alphabet = 200'001;
vector<int> _ucs(
const vector<int> text_a,
const vector<int> text_b)
{
const int na = text_a.size();
const int nb = text_b.size();
vector<vector<int>> positions_a(alphabet);
vector<vector<int>> positions_b(alphabet);
for (int i=0; i<na; ++i) {
positions_a[text_a[i]].push_back(i);
}
for (int i=0; i<nb; ++i) {
positions_b[text_b[i]].push_back(i);
}
vector<int> next_a(alphabet, 0);
vector<int> next_b(alphabet, 0);
int pos_a = 0;
int pos_b = 0;
vector<int> result;
while (pos_a < na && pos_b < nb) {
int ta = text_a[pos_a];
int tb = text_b[pos_b];
if (ta == tb) {
result.push_back(ta);
++pos_a;
++pos_b;
continue;
}
for (int t : {ta, tb}) {
while (next_a[t] < int(positions_a[t].size()) && positions_a[t][next_a[t]] < pos_a) {
++next_a[t];
}
while (next_b[t] < int(positions_b[t].size()) && positions_b[t][next_b[t]] < pos_b) {
++next_b[t];
}
}
int left_ta_self = int(positions_a[ta].size()) - next_a[ta];
int left_ta_opp = int(positions_b[ta].size()) - next_b[ta];
int left_tb_self = int(positions_b[tb].size()) - next_b[tb];
int left_tb_opp = int(positions_a[tb].size()) - next_a[tb];
if (left_ta_opp == 0) {
++pos_a;
continue;
}
if (left_tb_opp == 0) {
++pos_b;
continue;
}
if (left_ta_self <= left_ta_opp) {
if (left_tb_self <= left_tb_opp) {
return {-1};
} else {
++pos_b;
continue;
}
} else {
if (left_tb_self <= left_tb_opp) {
++pos_a;
continue;
} else {
int pos_ta_opp = positions_b[ta][next_b[ta]];
int pos_tb_opp = positions_a[tb][next_a[tb]];
int last_ta = positions_a[ta][next_a[ta] + left_ta_self - left_ta_opp];
int last_tb = positions_b[tb][next_b[tb] + left_tb_self - left_tb_opp];
if (last_ta < pos_tb_opp) {
if (last_tb < pos_ta_opp) {
return {-1};
} else {
++pos_b;
continue;
}
} else {
if (last_tb < pos_ta_opp) {
++pos_a;
continue;
} else {
return {-1};
}
}
}
}
}
return result;
}
vector<int> ucs(vector<int> a, vector<int> b) {
vector<int> r1 = _ucs(a, b);
std::reverse(a.begin(), a.end());
std::reverse(b.begin(), b.end());
vector<int> r2 = _ucs(a, b);
std::reverse(r2.begin(), r2.end());
return (r1 == r2) ? r1 : vector<int>({-1});
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11356 KB |
Output is correct |
2 |
Correct |
5 ms |
11356 KB |
Output is correct |
3 |
Correct |
5 ms |
11356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11356 KB |
Output is correct |
2 |
Correct |
5 ms |
11356 KB |
Output is correct |
3 |
Correct |
5 ms |
11420 KB |
Output is correct |
4 |
Correct |
6 ms |
11416 KB |
Output is correct |
5 |
Correct |
61 ms |
21220 KB |
Output is correct |
6 |
Correct |
52 ms |
19840 KB |
Output is correct |
7 |
Correct |
57 ms |
20608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11356 KB |
Output is correct |
2 |
Correct |
5 ms |
11356 KB |
Output is correct |
3 |
Correct |
5 ms |
11420 KB |
Output is correct |
4 |
Correct |
6 ms |
11416 KB |
Output is correct |
5 |
Correct |
61 ms |
21220 KB |
Output is correct |
6 |
Correct |
52 ms |
19840 KB |
Output is correct |
7 |
Correct |
57 ms |
20608 KB |
Output is correct |
8 |
Correct |
51 ms |
17724 KB |
Output is correct |
9 |
Correct |
58 ms |
17740 KB |
Output is correct |
10 |
Correct |
59 ms |
17728 KB |
Output is correct |
11 |
Correct |
64 ms |
17764 KB |
Output is correct |
12 |
Correct |
58 ms |
17736 KB |
Output is correct |
13 |
Correct |
53 ms |
17736 KB |
Output is correct |
14 |
Correct |
72 ms |
17744 KB |
Output is correct |
15 |
Correct |
50 ms |
17744 KB |
Output is correct |
16 |
Correct |
51 ms |
17856 KB |
Output is correct |
17 |
Correct |
56 ms |
17908 KB |
Output is correct |
18 |
Correct |
5 ms |
11356 KB |
Output is correct |
19 |
Correct |
6 ms |
11356 KB |
Output is correct |
20 |
Correct |
6 ms |
11420 KB |
Output is correct |
21 |
Correct |
7 ms |
11584 KB |
Output is correct |
22 |
Correct |
32 ms |
15572 KB |
Output is correct |
23 |
Correct |
61 ms |
18692 KB |
Output is correct |
24 |
Correct |
53 ms |
18692 KB |
Output is correct |
25 |
Correct |
54 ms |
18696 KB |
Output is correct |
26 |
Correct |
45 ms |
16476 KB |
Output is correct |
27 |
Correct |
51 ms |
17736 KB |
Output is correct |
28 |
Correct |
54 ms |
17744 KB |
Output is correct |
29 |
Incorrect |
54 ms |
17748 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
15880 KB |
Output is correct |
2 |
Correct |
27 ms |
15792 KB |
Output is correct |
3 |
Correct |
25 ms |
15300 KB |
Output is correct |
4 |
Correct |
25 ms |
14944 KB |
Output is correct |
5 |
Correct |
27 ms |
15596 KB |
Output is correct |
6 |
Correct |
15 ms |
13416 KB |
Output is correct |
7 |
Correct |
5 ms |
11328 KB |
Output is correct |
8 |
Correct |
6 ms |
11372 KB |
Output is correct |
9 |
Correct |
6 ms |
11356 KB |
Output is correct |
10 |
Correct |
5 ms |
11240 KB |
Output is correct |
11 |
Correct |
6 ms |
11356 KB |
Output is correct |
12 |
Correct |
5 ms |
11356 KB |
Output is correct |
13 |
Correct |
6 ms |
11356 KB |
Output is correct |
14 |
Correct |
5 ms |
11356 KB |
Output is correct |
15 |
Correct |
5 ms |
11352 KB |
Output is correct |
16 |
Correct |
25 ms |
15944 KB |
Output is correct |
17 |
Correct |
20 ms |
15228 KB |
Output is correct |
18 |
Correct |
20 ms |
14440 KB |
Output is correct |
19 |
Correct |
15 ms |
14180 KB |
Output is correct |
20 |
Correct |
25 ms |
14988 KB |
Output is correct |
21 |
Correct |
18 ms |
14560 KB |
Output is correct |
22 |
Correct |
18 ms |
14964 KB |
Output is correct |
23 |
Incorrect |
24 ms |
15864 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
17724 KB |
Output is correct |
2 |
Correct |
58 ms |
17740 KB |
Output is correct |
3 |
Correct |
59 ms |
17728 KB |
Output is correct |
4 |
Correct |
64 ms |
17764 KB |
Output is correct |
5 |
Correct |
58 ms |
17736 KB |
Output is correct |
6 |
Correct |
53 ms |
17736 KB |
Output is correct |
7 |
Correct |
72 ms |
17744 KB |
Output is correct |
8 |
Correct |
50 ms |
17744 KB |
Output is correct |
9 |
Correct |
51 ms |
17856 KB |
Output is correct |
10 |
Correct |
56 ms |
17908 KB |
Output is correct |
11 |
Correct |
5 ms |
11356 KB |
Output is correct |
12 |
Correct |
6 ms |
11356 KB |
Output is correct |
13 |
Correct |
6 ms |
11420 KB |
Output is correct |
14 |
Correct |
7 ms |
11584 KB |
Output is correct |
15 |
Correct |
32 ms |
15572 KB |
Output is correct |
16 |
Correct |
61 ms |
18692 KB |
Output is correct |
17 |
Correct |
53 ms |
18692 KB |
Output is correct |
18 |
Correct |
54 ms |
18696 KB |
Output is correct |
19 |
Correct |
45 ms |
16476 KB |
Output is correct |
20 |
Correct |
28 ms |
15880 KB |
Output is correct |
21 |
Correct |
27 ms |
15792 KB |
Output is correct |
22 |
Correct |
25 ms |
15300 KB |
Output is correct |
23 |
Correct |
25 ms |
14944 KB |
Output is correct |
24 |
Correct |
27 ms |
15596 KB |
Output is correct |
25 |
Correct |
15 ms |
13416 KB |
Output is correct |
26 |
Correct |
6 ms |
11420 KB |
Output is correct |
27 |
Correct |
7 ms |
11420 KB |
Output is correct |
28 |
Correct |
6 ms |
11420 KB |
Output is correct |
29 |
Correct |
11 ms |
11508 KB |
Output is correct |
30 |
Correct |
6 ms |
11408 KB |
Output is correct |
31 |
Correct |
6 ms |
11420 KB |
Output is correct |
32 |
Correct |
7 ms |
11420 KB |
Output is correct |
33 |
Correct |
7 ms |
11416 KB |
Output is correct |
34 |
Correct |
11 ms |
12444 KB |
Output is correct |
35 |
Correct |
27 ms |
15884 KB |
Output is correct |
36 |
Correct |
36 ms |
16136 KB |
Output is correct |
37 |
Correct |
32 ms |
16120 KB |
Output is correct |
38 |
Correct |
33 ms |
15896 KB |
Output is correct |
39 |
Correct |
32 ms |
15868 KB |
Output is correct |
40 |
Correct |
51 ms |
17484 KB |
Output is correct |
41 |
Correct |
43 ms |
16300 KB |
Output is correct |
42 |
Correct |
29 ms |
14972 KB |
Output is correct |
43 |
Correct |
29 ms |
14692 KB |
Output is correct |
44 |
Correct |
30 ms |
14860 KB |
Output is correct |
45 |
Correct |
30 ms |
15056 KB |
Output is correct |
46 |
Correct |
48 ms |
16284 KB |
Output is correct |
47 |
Correct |
47 ms |
16184 KB |
Output is correct |
48 |
Correct |
44 ms |
16268 KB |
Output is correct |
49 |
Correct |
50 ms |
15980 KB |
Output is correct |
50 |
Correct |
45 ms |
16032 KB |
Output is correct |
51 |
Correct |
43 ms |
16044 KB |
Output is correct |
52 |
Correct |
52 ms |
16080 KB |
Output is correct |
53 |
Correct |
45 ms |
16092 KB |
Output is correct |
54 |
Correct |
52 ms |
16076 KB |
Output is correct |
55 |
Correct |
17 ms |
13076 KB |
Output is correct |
56 |
Correct |
39 ms |
16136 KB |
Output is correct |
57 |
Correct |
31 ms |
15684 KB |
Output is correct |
58 |
Correct |
34 ms |
16132 KB |
Output is correct |
59 |
Correct |
36 ms |
16148 KB |
Output is correct |
60 |
Correct |
40 ms |
16056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
11328 KB |
Output is correct |
2 |
Correct |
6 ms |
11372 KB |
Output is correct |
3 |
Correct |
6 ms |
11356 KB |
Output is correct |
4 |
Correct |
5 ms |
11240 KB |
Output is correct |
5 |
Correct |
6 ms |
11356 KB |
Output is correct |
6 |
Correct |
5 ms |
11356 KB |
Output is correct |
7 |
Correct |
6 ms |
11356 KB |
Output is correct |
8 |
Correct |
5 ms |
11356 KB |
Output is correct |
9 |
Correct |
5 ms |
11352 KB |
Output is correct |
10 |
Correct |
6 ms |
11420 KB |
Output is correct |
11 |
Correct |
7 ms |
11420 KB |
Output is correct |
12 |
Correct |
6 ms |
11420 KB |
Output is correct |
13 |
Correct |
11 ms |
11508 KB |
Output is correct |
14 |
Correct |
6 ms |
11408 KB |
Output is correct |
15 |
Correct |
6 ms |
11420 KB |
Output is correct |
16 |
Correct |
7 ms |
11420 KB |
Output is correct |
17 |
Correct |
7 ms |
11416 KB |
Output is correct |
18 |
Correct |
7 ms |
11528 KB |
Output is correct |
19 |
Correct |
7 ms |
11420 KB |
Output is correct |
20 |
Correct |
7 ms |
11420 KB |
Output is correct |
21 |
Correct |
6 ms |
11420 KB |
Output is correct |
22 |
Correct |
10 ms |
11420 KB |
Output is correct |
23 |
Correct |
6 ms |
11420 KB |
Output is correct |
24 |
Correct |
7 ms |
11420 KB |
Output is correct |
25 |
Incorrect |
7 ms |
11392 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11356 KB |
Output is correct |
2 |
Correct |
5 ms |
11356 KB |
Output is correct |
3 |
Correct |
5 ms |
11356 KB |
Output is correct |
4 |
Correct |
6 ms |
11356 KB |
Output is correct |
5 |
Correct |
5 ms |
11356 KB |
Output is correct |
6 |
Correct |
5 ms |
11420 KB |
Output is correct |
7 |
Correct |
6 ms |
11416 KB |
Output is correct |
8 |
Correct |
61 ms |
21220 KB |
Output is correct |
9 |
Correct |
52 ms |
19840 KB |
Output is correct |
10 |
Correct |
57 ms |
20608 KB |
Output is correct |
11 |
Correct |
51 ms |
17724 KB |
Output is correct |
12 |
Correct |
58 ms |
17740 KB |
Output is correct |
13 |
Correct |
59 ms |
17728 KB |
Output is correct |
14 |
Correct |
64 ms |
17764 KB |
Output is correct |
15 |
Correct |
58 ms |
17736 KB |
Output is correct |
16 |
Correct |
53 ms |
17736 KB |
Output is correct |
17 |
Correct |
72 ms |
17744 KB |
Output is correct |
18 |
Correct |
50 ms |
17744 KB |
Output is correct |
19 |
Correct |
51 ms |
17856 KB |
Output is correct |
20 |
Correct |
56 ms |
17908 KB |
Output is correct |
21 |
Correct |
5 ms |
11356 KB |
Output is correct |
22 |
Correct |
6 ms |
11356 KB |
Output is correct |
23 |
Correct |
6 ms |
11420 KB |
Output is correct |
24 |
Correct |
7 ms |
11584 KB |
Output is correct |
25 |
Correct |
32 ms |
15572 KB |
Output is correct |
26 |
Correct |
61 ms |
18692 KB |
Output is correct |
27 |
Correct |
53 ms |
18692 KB |
Output is correct |
28 |
Correct |
54 ms |
18696 KB |
Output is correct |
29 |
Correct |
45 ms |
16476 KB |
Output is correct |
30 |
Correct |
51 ms |
17736 KB |
Output is correct |
31 |
Correct |
54 ms |
17744 KB |
Output is correct |
32 |
Incorrect |
54 ms |
17748 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |