Submission #1221493

#TimeUsernameProblemLanguageResultExecution timeMemory
1221493nibertHieroglyphs (IOI24_hieroglyphs)C++20
3 / 100
171 ms12272 KiB
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <iostream>
using namespace std;

const int max_value = 200001 ;
bool is_sequence(const vector<int>&a , const vector<int>&b) {
    int j = 0;
    int m = b.size();
    for(int x : a) {
        if(j < m && b[j] == x) {
            j++;
        }
        
    }
    return j == m;
}
vector <int> coordinate_compression(vector <int> &arr){
    set<int> unique_values(arr.begin(), arr.end());
    map<int, int> mapping;
    int idx = 0;
    for(int val : unique_values) {
        mapping[val] = idx++;
    } 
    vector <int> compressed;
    for(int val : arr) {
        compressed.push_back(mapping[val]);
    }
    return compressed;
}
vector <int> get_subsequences (vector<int> A, vector<int> B) {
    int N = A.size(), M = B.size();
    vector<int> occurances_a(max_value, 0) , occurances_b(max_value,0);
    for(int x : A) {
        occurances_a[x]++;
    } 
    for(int y : B) {
        occurances_b[y]++;
    }
    vector<int> UCS;
    for(int x : A) {
        if(occurances_b[x]) {
            UCS.push_back(x);
        }
    }
    return UCS;
}
   
vector<int> ucs(vector<int> A, vector<int>B) {
    A = coordinate_compression(A);
    B = coordinate_compression(B);
    vector<int> sequences = get_subsequences(A,B);
    return is_sequence(A, sequences) && is_sequence(B,sequences) ? sequences : vector<int> {-1};
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...