Submission #1130045

#TimeUsernameProblemLanguageResultExecution timeMemory
1130045math_rabbit_1028Sphinx's Riddle (IOI24_sphinx)C++20
3 / 100
6 ms416 KiB
#include "sphinx.h" #include <bits/stdc++.h> using namespace std; vector<int> adj[303]; vector<int> ch; void dfs(int v) { ch[v] = 1; for (int u : adj[v]) { if (ch[u]) continue; dfs(u); } } int other(int N, int v, int u) { int ret = 0; ch = vector<int>(N, 0); ch[v] = ch[u] = 1; for (int i = 0; i < N; i++) { if (ch[i]) continue; dfs(i); ret++; } return ret; } int trivial(vector<int> E) { int ret = 1; for (int i = 1; i < E.size(); i++) if (E[i] != E[i-1]) ret++; return ret; } vector<int> vec; void solve(int s, int e, int x, int N, int r, int c) { if (s == e) { vec.push_back(3*s+r); return; } int m = (s+e)/2; vector<int> E(N, N); for (int i = s; i <= m; i++) { if (i % 3 == r) { E[3*i+r] = -1; E[3*i+r+1] = c; } } int y = perform_experiment(E) - trivial(E); if (y > 0) solve(s, m, y, N, r, c); if (x-y > 0) solve(m+1, e, x-y, N, r, c); } vector<int> find_colours(int N, vector<int> X, vector<int> Y) { for (int i = 0; i < X.size(); i++) { adj[X[i]].push_back(Y[i]); adj[Y[i]].push_back(X[i]); } vector<int> C(N, 0); vector<int> color(N, 0); for (int i = 0; i < N; i++) color[i] = i; if (N <= 2) { for (int i = 0; i < N; i++) { vector<int> E(N, N); E[i] = -1; random_shuffle(color.begin(), color.end()); for (int j = 0; j < N; j++) { E[adj[i][0]] = color[j]; int x = perform_experiment(E); if (x - other(N, i, adj[i][0]) == 1) { C[i] = color[j]; break; } } } } else { for (int r = 0; r < 3; r++) { for (int j = 0; j < N; j++) { vector<int> E(N, N); int cnt = 0; for (int i = 0; i < N-1; i++) { if (i % 3 == r) { E[i] = -1; cnt++; } } for (int i = 1; i < N; i++) { if ((i - 1) % 3 == r) E[i] = color[j]; } int x = trivial(E) - perform_experiment(E);\ if (x > 0) solve(0, cnt-1, x, N, r, color[j]); for (auto i : vec) C[i] = color[j]; vec.clear(); } } vector<int> E(N, N); E[N-1] = -1; random_shuffle(color.begin(), color.end()); for (int j = 0; j < N; j++) { E[N-2] = color[j]; int x = perform_experiment(E); if (x == 2) { C[N-1] = color[j]; break; } } } return C; }
#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...