Submission #1051589

#TimeUsernameProblemLanguageResultExecution timeMemory
1051589pccComparing Plants (IOI20_plants)C++17
14 / 100
2657 ms121236 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fs first #define sc second const int mxn = 1e4+10; int arr[mxn]; int N; int K; int perm[mxn]; int dp[mxn]; vector<int> dag[mxn]; void smaller(int a,int b){//a<b //cerr<<"SMALLER: "<<a<<','<<b<<endl; dag[a].push_back(b); } void calc(int id){ fill(dp,dp+N*2,0); int pre = -1; for(int i = 0;i<N*2;i++){ if(i)dp[i] = (arr[i-1]?dp[i-1]:0); dp[i]++; if(!arr[i]&&pre != -1&&i-pre<K)smaller(i%N,pre%N); if(!arr[i])pre = i; } int tar = 0; for(int i = 0;i<N*2;i++){ if(!arr[i]&&dp[i]>=K)tar = i%N; } arr[tar] = arr[tar+N] = mxn*2; for(int i = 0;i<K;i++){ int pre = (tar+N-i)%N; arr[pre]--;arr[pre+N]--; if(arr[pre] < N)smaller(pre,tar); } return; } queue<int> q; int deg[mxn]; bitset<mxn> vis[mxn]; void TOPO(){ for(int i = 0;i<N;i++){ sort(dag[i].begin(),dag[i].end()); dag[i].resize(unique(dag[i].begin(),dag[i].end())-dag[i].begin()); for(auto nxt:dag[i])deg[nxt]++; } for(int i = 0;i<N;i++){ vis[i][i] = 1; if(!deg[i])q.push(i); } while(!q.empty()){ auto now = q.front(); q.pop(); for(auto nxt:dag[now]){ deg[nxt]--; vis[nxt] = vis[nxt]|vis[now]; if(!deg[nxt])q.push(nxt); } } /* cerr<<"VIS: "<<endl; for(int i = 0;i<N;i++){ for(int j = 0;j<N;j++)cerr<<vis[i][j];cerr<<endl; } */ return; } void init(int k, std::vector<int> r) { K = k; N = r.size(); for(int i = 0;i<N;i++)arr[i] = arr[i+N] = r[i]; for(int i = N-1;i>=0;i--)calc(i); TOPO(); } int compare_plants(int x, int y) { return (vis[x][y]?1:vis[y][x]?-1:0); }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...