Submission #1298358

#TimeUsernameProblemLanguageResultExecution timeMemory
1298358gesp3011v2Sphinx's Riddle (IOI24_sphinx)C++20
1.50 / 100
7 ms400 KiB
#include "bits/stdc++.h"
#include "sphinx.h"
using namespace std;

vector<int> find_colours(int N, vector<int> X, vector<int> Y) {
    vector<int> ans(N, 0);
    
    if (N == 2) {
        vector<int> E1 = {-1, -1};
        int res1 = perform_experiment(E1);
        
        if (res1 == 1) {
            vector<int> E2 = {0, -1};
            int res2 = perform_experiment(E2);
            if (res2 == 1) {
                ans[0] = 0;
                ans[1] = 0;
            } else {
                ans[0] = 1;
                ans[1] = 1;
            }
        } else {
            vector<int> E2 = {0, -1};
            int res2 = perform_experiment(E2);
            if (res2 == 1) {
                ans[0] = 0;
                ans[1] = 1;
            } else {
                ans[0] = 1;
                ans[1] = 0;
            }
        }
        return ans;
    }
    
    vector<int> same(N, 0);
    for (int i = 0; i < N; i++) same[i] = i;
    for (int j = 0; j < (int)X.size(); j++) {
        int u = X[j], v = Y[j];
        
        vector<int> E(N, N); 
        E[u] = -1;
        E[v] = -1;
        
        int res = perform_experiment(E);
        if (res == 1) {
            int root_u = same[u];
            int root_v = same[v];
            for (int k = 0; k < N; k++) {
                if (same[k] == root_v) same[k] = root_u;
            }
        }
    }
    
    vector<int> color_map(N, -1);
    int next_color = 0;
    for (int i = 0; i < N; i++) {
        int root = same[i];
        if (color_map[root] == -1) {
            color_map[root] = next_color++;
        }
        ans[i] = color_map[root];
    }
    
    vector<int> E_all(N, -1);
    int orig_components = perform_experiment(E_all);
    vector<bool> used(N, false);
    int our_groups = 0;
    for (int i = 0; i < N; i++) {
        if (!used[ans[i]]) {
            used[ans[i]] = true;
            our_groups++;
        }
    }
    
    if (our_groups != orig_components) {
        int cur = 0;
        vector<int> group_color(N, -1);
        for (int i = 0; i < N; i++) {
            int root = same[i];
            if (group_color[root] == -1) {
                group_color[root] = cur;
                cur = (cur + 1) % N;
            }
            ans[i] = group_color[root];
        }
    }
    
    return ans;
}
#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...