#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fs first
#define sc second
const int mxn = 660;
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 time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |