Submission #979421

#TimeUsernameProblemLanguageResultExecution timeMemory
979421AdamGSSplit the Attractions (IOI19_split)C++17
100 / 100
105 ms29644 KiB
#include "split.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=1e5+7; vector<int>V[LIM], G[LIM], P[LIM], ans; vector<pair<int,int>>S; int odl[LIM], pre[LIM], ile[LIM], lpre; void DFS(int x) { pre[x]=++lpre; ile[x]=1; for(auto i : V[x]) { if(!pre[i]) { G[x].pb(i); odl[i]=odl[x]+1; DFS(i); ile[x]+=ile[i]; } else if(pre[i]<pre[x]) P[x].pb(i); } } void DFS2(int x, int k) { if(!S[k].st || ans[x]) return; ans[x]=S[k].nd; --S[k].st; for(auto i : G[x]) DFS2(i, k); } void DFS3(int x, int k) { if(x==k) return; ans[x]=S[1].nd; --S[1].st; for(auto i : G[x]) DFS3(i, k); } void DFS5(int x) { if(!S[1].st) return; --S[1].st; ans[x]=S[1].nd; for(auto i : G[x]) DFS5(i); } void DFS4(int x, int k) { if(!S[1].st) return; for(auto i : P[x]) if(odl[i]<k) { DFS5(x); return; } for(auto i : G[x]) DFS4(i, k); } void DFS6(int x) { if(!S[0].st || ans[x]) return; --S[0].st; ans[x]=S[0].nd; for(auto i : G[x]) DFS6(i); } vector<int>find_split(int n, int a, int b, int c, vector<int>p, vector<int>q) { rep(i, n) ans.pb(0); S.pb({a, 1}); S.pb({b, 2}); S.pb({c, 3}); sort(all(S)); rep(i, p.size()) { V[p[i]].pb(q[i]); V[q[i]].pb(p[i]); } DFS(0); rep(j, 2) { rep(i, n) if(ile[i]>=S[0].st && n-ile[i]>=S[1].st) { DFS2(i, 0); DFS2(0, 1); rep(l, n) if(!ans[l]) ans[l]=S[2].nd; return ans; } swap(S[0], S[1]); } pair<int,int>mi={n, n}; rep(i, n) if(ile[i]>=S[0].st) mi=min(mi, {ile[i], i}); DFS3(0, mi.nd); for(auto i : G[mi.nd]) DFS4(i, odl[mi.nd]); if(S[1].st) { rep(i, n) ans[i]=0; return ans; } DFS6(mi.nd); rep(i, n) if(!ans[i]) ans[i]=S[2].nd; return ans; }

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
split.cpp:64:3: note: in expansion of macro 'rep'
   64 |   rep(i, p.size()) {
      |   ^~~
#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...