Submission #1205781

#TimeUsernameProblemLanguageResultExecution timeMemory
1205781Andrey스핑크스 (IOI24_sphinx)C++20
100 / 100
126 ms1672 KiB
#include "sphinx.h" #include<bits/stdc++.h> using namespace std; int n; vector<int> haha[300]; vector<int> bruh(300); vector<int> col[300]; vector<int> no[300]; vector<int> odd(0); vector<int> even(0); void dfs(int a) { bruh[a] = -1; for(int v: haha[a]) { if(bruh[v] != -1) { dfs(v); } } } int dude(vector<int> wut) { vector<int> yo(n,n); for(int i = 0; i < n; i++) { bruh[i] = 0; } for(int v: wut) { yo[v] = -1; bruh[v] = -1; } int ans = perform_experiment(yo); for(int i = 0; i < n; i++) { if(bruh[i] != -1) { dfs(i); ans--; } } return ans; } void dfs2(int a, int d) { if(d%2 == 0) { even.push_back(a); } else { odd.push_back(a); } bruh[a] = -1; for(int v: no[a]) { if(bruh[v] == 0) { dfs2(v,d+1); } } } void dfs3(int a, int c) { bruh[a] = -1; for(int v: no[a]) { if(bruh[v] == c) { dfs3(v,c); } } } bool calc(int p, int c, vector<int> wut) { if(wut.empty()) { return false; } vector<int> yo(n,-1); if(p == 0) { for(int v: odd) { yo[v] = c; } for(int v: even) { yo[v] = n; } } else { for(int v: even) { yo[v] = c; } for(int v: odd) { yo[v] = n; } } for(int v: wut) { yo[v] = -1; } for(int i = 0; i < n; i++) { bruh[i] = yo[i]; } int br = wut.size(); for(int i = 0; i < n; i++) { if(bruh[i] != -1) { dfs3(i,bruh[i]); br++; } } vector<int> ans(n,-1); for(int i = 0; i < n; i++) { for(int v: col[i]) { ans[v] = yo[i]; } } if(perform_experiment(ans) != br) { return true; } else { return false; } } int apple(int p, int c, vector<int> wut) { if(wut.size() == 1) { return wut[0]; } int mid = wut.size()/2; vector<int> wow(0); vector<int> yay(0); for(int i = 0; i < mid; i++) { wow.push_back(wut[i]); } for(int i = mid; i < wut.size(); i++) { yay.push_back(wut[i]); } if(calc(p,c,wow)) { return apple(p,c,wow); } else { return apple(p,c,yay); } } std::vector<int> find_colours(int N, std::vector<int> x, std::vector<int> y) { n = N; for(int i = 0; i < x.size(); i++) { haha[x[i]].push_back(y[i]); haha[y[i]].push_back(x[i]); } vector<int> ans(n); for(int i = 1; i < n; i++) { ans[i] = i; vector<int> wut(0); set<int> idk; for(int j = 0; j <= i; j++) { wut.push_back(j); if(j < i) { idk.insert(ans[j]); } } int c = (int)idk.size()-dude(wut)+1; for(int j = 0; j < c; j++) { int l = 0,r = i-1; while(l < r) { int mid = (l+r)/2; wut.clear(); idk.clear(); for(int k = 0; k < i; k++) { if(ans[k] >= l && ans[k] <= mid) { wut.push_back(k); idk.insert(ans[k]); } } wut.push_back(i); if(dude(wut) <= idk.size()) { r = mid; } else { l = mid+1; } } int a = l; for(int k = 0; k < i; k++) { if(ans[k] == a) { ans[k] = i; } } } } int br = 0; for(int i = 0; i < n; i++) { col[ans[i]].push_back(i); } for(int i = 0; i < n; i++) { if(col[i].size() > 0) { br++; } } if(br == 1) { vector<int> wut(n,-1); int x; for(int i = 0; i < n; i++) { wut[0] = i; if(perform_experiment(wut) == 1) { x = i; break; } } for(int i = 0; i < n; i++) { wut[i] = x; } return wut; } for(int i = 0; i < x.size(); i++) { no[ans[x[i]]].push_back(ans[y[i]]); no[ans[y[i]]].push_back(ans[x[i]]); } for(int i = 0; i < n; i++) { bruh[i] = 0; } dfs2(n-1,0); vector<int> yeah(n,-1); for(int i = 0; i < n; i++) { vector<int> wut(0); while(true) { wut.clear(); for(int v: even) { if(yeah[v] == -1) { wut.push_back(v); } } if(calc(0,i,wut)) { yeah[apple(0,i,wut)] = i; } else { break; } } while(true) { wut.clear(); for(int v: odd) { if(yeah[v] == -1) { wut.push_back(v); } } if(calc(1,i,wut)) { yeah[apple(1,i,wut)] = i; } else { break; } } } vector<int> ans2(n); for(int i = 0; i < n; i++) { for(int v: col[i]) { ans2[v] = yeah[i]; } } return ans2; }
#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...