#include "hieroglyphs.h"
using namespace std;
vector<int> solve(vector<int> A, vector<int> B) {
int N = (int)A.size();
int M = (int)B.size();
vector<int> cntA(202020, 0), cntB(202020, 0), ret;
int p = 0;
for (int i = 0; i < N; i++) {
cntA[A[i]]++;
}
for (int i = 0; i < M; i++) {
cntB[B[i]]++;
}
for (int i = 0; i < N; i++) {
if (cntB[A[i]] == 0) continue;
while (true) {
if (B[p] == A[i]) {
p++;
ret.push_back(A[i]);
cntA[A[i]]--;
cntB[A[i]]--;
break;
}
p++;
if (p == M) return vector<int>(1, -1);
}
}
return ret;
}
vector<int> check(vector<int> V, vector<int> U) {
if (V.size() > U.size()) swap(V, U);
// V.size() <= U.size()
int p = 0;
for (int i = 0; i < V.size(); i++) {
while (true) {
if (p == U.size()) return vector<int>(1, -1);
if (V[i] == U[p]) {
p++;
break;
}
p++;
}
}
return U;
}
vector<int> ucs(vector<int> A, vector<int> B) {
vector<int> V = solve(A, B);
vector<int> U = solve(B, A);
if (V.size() == 1 && V[0] == -1) return vector<int>(1, -1);
if (U.size() == 1 && U[0] == -1) return vector<int>(1, -1);
return check(V, U);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |