// incorrect/felix-hasucs.cpp
#include "hieroglyphs.h"
#include<bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
//erases non-common elements
void clean(vi& a, vi& b) {
vi ap;
vi bp;
set<int> as;
set<int> bs;
for (int x : a) as.insert(x);
for (int x : b) bs.insert(x);
for (int x : a) if (bs.count(x)) ap.push_back(x);
for (int x : b) if (as.count(x)) bp.push_back(x);
swap(a, ap);
swap(b, bp);
}
map<int, int> coordinate_compress(vi& a, vi& b) {
int cc = 0;
map<int, int> mp;
map<int, int> rmp;
for (int& x : a) {
if (!mp.count(x)) {
mp[x] = cc++;
rmp[mp[x]] = x;
}
x = mp[x];
}
for (int& x : b) {
if (!mp.count(x)) {
mp[x] = cc++;
rmp[mp[x]] = x;
}
x = mp[x];
}
return rmp;
}
bool is_subsequence(const vi& a, const vi& b) {
int j = 0;
for (int x : a) {
if (j < (int)b.size() && b[j] == x) {
j++;
}
}
return j == (int)b.size();
}
vector<int> get_candidate(vector<int> a, vector<int> b) {
int n = a.size();
int m = b.size();
vi occ_a(max(n, m)+1, 0);
vi occ_b(max(n, m)+1, 0);
for (int i=0; i < n; ++i) {
occ_a[a[i]]++;
}
for (int i=0; i < m; ++i) {
occ_b[b[i]]++;
}
vi c;
queue<int> qa;
queue<int> qb;
for (int i=0; i < n; ++i) {
if (occ_a[a[i]] <= occ_b[a[i]]) {
qa.push(i);
}
}
for (int i=0; i < m; ++i) {
if (occ_a[b[i]] > occ_b[b[i]]) {
qb.push(i);
}
}
int i_a_curr = 0;
int i_b_curr = 0;
int i_a_next = 0;
int i_b_next = 0;
vi occ_a_curr = vi(occ_a);
vi occ_a_next = vi(occ_a);
vi occ_b_curr = vi(occ_b);
vi occ_b_next = vi(occ_b);
while(!qa.empty() && !qb.empty()) {
while(i_a_next < qa.front()) {
occ_a_next[a[i_a_next]]--;
i_a_next++;
}
while(i_b_next < qb.front()) {
occ_b_next[b[i_b_next]]--;
i_b_next++;
}
int x = a[i_a_next];
int y = b[i_b_next];
int occ_x = occ_a_next[x];
int occ_y = occ_b_next[y];
bool a_good = (occ_a_next[y] >= occ_y && occ_b_curr[x] > occ_b_next[x]);
bool b_good = (occ_b_next[x] >= occ_x && occ_a_curr[y] > occ_a_next[y]);
if (a_good && b_good) return vi();
if (!a_good && !b_good) return vi();
if(a_good) {
c.push_back(x);
qa.pop();
while(i_a_curr <= i_a_next) {
occ_a_curr[a[i_a_curr]]--;
i_a_curr++;
}
while(b[i_b_curr] != x) {
occ_b_curr[b[i_b_curr]]--;
i_b_curr++;
}
occ_b_curr[b[i_b_curr]]--;
i_b_curr++;
}
else {
c.push_back(y);
qb.pop();
while(i_b_curr <= i_b_next) {
occ_b_curr[b[i_b_curr]]--;
i_b_curr++;
}
while(a[i_a_curr] != y) {
occ_a_curr[a[i_a_curr]]--;
i_a_curr++;
}
occ_a_curr[a[i_a_curr]]--;
i_a_curr++;
}
}
while(!qa.empty()) {
c.push_back(a[qa.front()]);
qa.pop();
}
while(!qb.empty()) {
c.push_back(b[qb.front()]);
qb.pop();
}
return ((is_subsequence(a, c) && is_subsequence(b, c)) ? c : vi());
}
vector<int> ucs(vector<int> a, vector<int> b) {
clean(a, b);
if (a.empty() || b.empty()) {
return vector<int>();
}
map<int, int> mp = coordinate_compress(a, b);
vi c;
c = get_candidate(a, b);
if (c.empty() || c[0] == -1) return {-1};
for (int& x : c) x = mp[x];
return c;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
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 |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
223 ms |
15796 KB |
Output is correct |
6 |
Correct |
213 ms |
15676 KB |
Output is correct |
7 |
Correct |
216 ms |
15672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
223 ms |
15796 KB |
Output is correct |
6 |
Correct |
213 ms |
15676 KB |
Output is correct |
7 |
Correct |
216 ms |
15672 KB |
Output is correct |
8 |
Correct |
169 ms |
10920 KB |
Output is correct |
9 |
Correct |
151 ms |
10900 KB |
Output is correct |
10 |
Correct |
166 ms |
10940 KB |
Output is correct |
11 |
Correct |
154 ms |
10904 KB |
Output is correct |
12 |
Correct |
171 ms |
10900 KB |
Output is correct |
13 |
Correct |
148 ms |
10860 KB |
Output is correct |
14 |
Correct |
148 ms |
10904 KB |
Output is correct |
15 |
Correct |
151 ms |
10796 KB |
Output is correct |
16 |
Correct |
145 ms |
10904 KB |
Output is correct |
17 |
Correct |
150 ms |
11000 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
66 ms |
6132 KB |
Output is correct |
23 |
Correct |
121 ms |
10408 KB |
Output is correct |
24 |
Correct |
123 ms |
10304 KB |
Output is correct |
25 |
Correct |
130 ms |
10308 KB |
Output is correct |
26 |
Correct |
75 ms |
6480 KB |
Output is correct |
27 |
Correct |
145 ms |
10992 KB |
Output is correct |
28 |
Correct |
146 ms |
10884 KB |
Output is correct |
29 |
Incorrect |
148 ms |
10904 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
6200 KB |
Output is correct |
2 |
Correct |
28 ms |
6468 KB |
Output is correct |
3 |
Correct |
21 ms |
5696 KB |
Output is correct |
4 |
Correct |
20 ms |
5484 KB |
Output is correct |
5 |
Correct |
25 ms |
6252 KB |
Output is correct |
6 |
Correct |
13 ms |
4240 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
10920 KB |
Output is correct |
2 |
Correct |
151 ms |
10900 KB |
Output is correct |
3 |
Correct |
166 ms |
10940 KB |
Output is correct |
4 |
Correct |
154 ms |
10904 KB |
Output is correct |
5 |
Correct |
171 ms |
10900 KB |
Output is correct |
6 |
Correct |
148 ms |
10860 KB |
Output is correct |
7 |
Correct |
148 ms |
10904 KB |
Output is correct |
8 |
Correct |
151 ms |
10796 KB |
Output is correct |
9 |
Correct |
145 ms |
10904 KB |
Output is correct |
10 |
Correct |
150 ms |
11000 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
66 ms |
6132 KB |
Output is correct |
16 |
Correct |
121 ms |
10408 KB |
Output is correct |
17 |
Correct |
123 ms |
10304 KB |
Output is correct |
18 |
Correct |
130 ms |
10308 KB |
Output is correct |
19 |
Correct |
75 ms |
6480 KB |
Output is correct |
20 |
Correct |
27 ms |
6200 KB |
Output is correct |
21 |
Correct |
28 ms |
6468 KB |
Output is correct |
22 |
Correct |
21 ms |
5696 KB |
Output is correct |
23 |
Correct |
20 ms |
5484 KB |
Output is correct |
24 |
Correct |
25 ms |
6252 KB |
Output is correct |
25 |
Correct |
13 ms |
4240 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
544 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
6 ms |
1912 KB |
Output is correct |
35 |
Correct |
26 ms |
6000 KB |
Output is correct |
36 |
Correct |
42 ms |
6864 KB |
Output is correct |
37 |
Correct |
30 ms |
6468 KB |
Output is correct |
38 |
Correct |
31 ms |
6216 KB |
Output is correct |
39 |
Correct |
30 ms |
6208 KB |
Output is correct |
40 |
Correct |
131 ms |
9624 KB |
Output is correct |
41 |
Correct |
87 ms |
7376 KB |
Output is correct |
42 |
Correct |
20 ms |
4928 KB |
Output is correct |
43 |
Correct |
21 ms |
4924 KB |
Output is correct |
44 |
Correct |
22 ms |
5048 KB |
Output is correct |
45 |
Correct |
20 ms |
4652 KB |
Output is correct |
46 |
Correct |
112 ms |
8404 KB |
Output is correct |
47 |
Correct |
106 ms |
8508 KB |
Output is correct |
48 |
Correct |
111 ms |
8376 KB |
Output is correct |
49 |
Correct |
123 ms |
8120 KB |
Output is correct |
50 |
Correct |
112 ms |
8228 KB |
Output is correct |
51 |
Correct |
100 ms |
8288 KB |
Output is correct |
52 |
Correct |
111 ms |
7740 KB |
Output is correct |
53 |
Correct |
100 ms |
7600 KB |
Output is correct |
54 |
Correct |
93 ms |
7608 KB |
Output is correct |
55 |
Correct |
15 ms |
2384 KB |
Output is correct |
56 |
Correct |
41 ms |
6216 KB |
Output is correct |
57 |
Correct |
36 ms |
5772 KB |
Output is correct |
58 |
Correct |
58 ms |
6504 KB |
Output is correct |
59 |
Correct |
73 ms |
6716 KB |
Output is correct |
60 |
Correct |
101 ms |
7284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
223 ms |
15796 KB |
Output is correct |
9 |
Correct |
213 ms |
15676 KB |
Output is correct |
10 |
Correct |
216 ms |
15672 KB |
Output is correct |
11 |
Correct |
169 ms |
10920 KB |
Output is correct |
12 |
Correct |
151 ms |
10900 KB |
Output is correct |
13 |
Correct |
166 ms |
10940 KB |
Output is correct |
14 |
Correct |
154 ms |
10904 KB |
Output is correct |
15 |
Correct |
171 ms |
10900 KB |
Output is correct |
16 |
Correct |
148 ms |
10860 KB |
Output is correct |
17 |
Correct |
148 ms |
10904 KB |
Output is correct |
18 |
Correct |
151 ms |
10796 KB |
Output is correct |
19 |
Correct |
145 ms |
10904 KB |
Output is correct |
20 |
Correct |
150 ms |
11000 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
66 ms |
6132 KB |
Output is correct |
26 |
Correct |
121 ms |
10408 KB |
Output is correct |
27 |
Correct |
123 ms |
10304 KB |
Output is correct |
28 |
Correct |
130 ms |
10308 KB |
Output is correct |
29 |
Correct |
75 ms |
6480 KB |
Output is correct |
30 |
Correct |
145 ms |
10992 KB |
Output is correct |
31 |
Correct |
146 ms |
10884 KB |
Output is correct |
32 |
Incorrect |
148 ms |
10904 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |