Submission #425131

#TimeUsernameProblemLanguageResultExecution timeMemory
425131alishahali1382Split the Attractions (IOI19_split)C++14
18 / 100
2067 ms13808 KiB
#include "split.h" #include<bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define debug(x) {cerr<<#x<<"="<<x<<"\n";} #define debug2(x, y) {cerr<<"{"<<#x<<", "<<#y<<"}={"<<x<<", "<<y<<"}\n";} #define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";} #define debugv(abcd) {cerr<<#abcd<<": ";for (auto dcba:abcd) cerr<<dcba<<", ";cerr<<"\n";} #define pb push_back #define SZ(x) ((int)x.size()) #define all(x) x.begin(), x.end() const int inf=1000001000; // 1e9 const ll INF=10000000010000000; // 1e16 const int mod=1000000007; const int MAXN=100010; vector<pair<int, char>> perm; int n, m, k, a, b, c, u, v, t, x, y, solved; int mark[MAXN], sz[MAXN], par[MAXN]; int dist[3][MAXN]; int Q[MAXN], QL, QR; vector<int> G[MAXN]; vector<int> out; vector<int> topol; void BFS(int src, int *dist){ fill(dist, dist+MAXN, inf); QL=QR=0; dist[Q[QR++]=src]=0; while (QL<QR){ int v=Q[QL++]; for (int u:G[v]) if (dist[v]+1<dist[u]){ dist[u]=dist[v]+1; Q[QR++]=u; } } } void dfs(int node){ mark[node]=1; topol.pb(node); for (int v:G[node]) if (!mark[v]) dfs(v); } vector<int> find_split(int _n, int _a, int _b, int _c, vector<int> _p, vector<int> _q){ n=_n; out.resize(n, 0); a=_a; b=_b; c=_c; for (int i=0; i<SZ(_p); i++){ int u=_p[i], v=_q[i]; G[u].pb(v); G[v].pb(u); } perm.pb({a, 'a'}); perm.pb({b, 'b'}); perm.pb({c, 'c'}); sort(all(perm)); a=perm[0].first; b=perm[1].first; c=perm[2].first; // -------------------------- for (int x=0; x<n; x++){ BFS(x, dist[0]); int y=x; for (int i=0; i<n; i++) if (dist[0][i]>dist[0][y]) y=i; BFS(y, dist[1]); // debug2(x, y) vector<int> X, Y, P(n, 0); iota(all(P), 0); sort(all(P), [](int i, int j){ return dist[0][i]<dist[0][j]; }); memset(mark, 0, sizeof(mark)); topol.clear(); for (int i=0; i<a; i++){ X.pb(P[i]); mark[P[i]]=1; } dfs(y); Y=topol; if (SZ(X)>=a && SZ(Y)>=b){ for (int i=0; i<a; i++) out[X[i]]=1; for (int i=0; i<b; i++) out[Y[i]]=2; solved=1; break ; } } // -------------------------- if (!solved) return out; // debugv(out) for (int i=0; i<n; i++){ if (!out[i]) out[i]=3; if (out[i]==1){ if (perm[0].second=='a') out[i]=1; if (perm[0].second=='b') out[i]=2; if (perm[0].second=='c') out[i]=3; } else if (out[i]==2){ if (perm[1].second=='a') out[i]=1; if (perm[1].second=='b') out[i]=2; if (perm[1].second=='c') out[i]=3; } else if (out[i]==3){ if (perm[2].second=='a') out[i]=1; if (perm[2].second=='b') out[i]=2; if (perm[2].second=='c') out[i]=3; } } for (int i=0; i<n; i++){ if (out[i]==1) _a--; if (out[i]==2) _b--; if (out[i]==3) _c--; } assert(!_a && !_b && !_c); return out; }
#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...