#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 20'010;
vector<int> g[N];
int n;
bool vis[N];
vector<int> topo;
vector<bitset<N>> b(N);
void dfs(int at) {
vis[at]=1;
for(int to:g[at]) {
if(vis[to])continue;
dfs(to);
}
topo.push_back(at);
}
void init(int k, std::vector<int> r) {
n=r.size();
int dummy=n;
int idx=-1;
for(int i = 0;i<n;i++) {
if(r[i] == 0) {
idx=i;
break;
}
}
vector<int> nums;
nums.push_back(idx);
vector<int> tim(n+k+1, -1e9);
tim[idx]=0;
for(int j = (idx+1)%n, cnt=0;cnt+1<k;j=(j+1)%n, cnt++) {
g[idx].push_back(j);
tim[dummy]=cnt+1;
nums.push_back(dummy++);
}
for(int j = 0;j+1<(int)nums.size();j++) {
g[nums[j]].push_back(nums[j+1]);
}
int timer=-1;
for(int j = (idx-1+n)%n, cnt=0;cnt<=2*n;j=(j-1+n)%n, cnt++) {
int need_to_erase=0;
for(int i = 0;i<n+k;i++){
if(tim[i] == timer+k) {
need_to_erase=i;
break;
}
}
for(auto it=nums.begin();it!=nums.end();it++) {
if((*it) == need_to_erase) {
nums.erase(it);
break;
}
}
auto it = nums.insert(nums.begin()+r[j], j);
if(it!=nums.begin()) {
g[(*prev(it))].push_back(j);
}
if(it!=(--nums.end())) {
g[j].push_back((*next(it)));
}
tim[j]=timer;
timer--;
}
for(int i = 0;i<n;i++) {
if(!vis[i])
dfs(i);
b[i][i]=1;
}
// reverse(topo.begin(), topo.end());
for(int i:topo) {
for(int j:g[i]) {
b[i]|=b[j];
}
}
return;
}
int compare_plants(int x, int y) {
if(b[x][y])return 1;
if(b[y][x])return -1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
49752 KB |
Output is correct |
2 |
Correct |
24 ms |
49860 KB |
Output is correct |
3 |
Correct |
22 ms |
49752 KB |
Output is correct |
4 |
Correct |
21 ms |
49748 KB |
Output is correct |
5 |
Correct |
22 ms |
49740 KB |
Output is correct |
6 |
Correct |
54 ms |
53512 KB |
Output is correct |
7 |
Correct |
212 ms |
55892 KB |
Output is correct |
8 |
Runtime error |
101 ms |
113248 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
49752 KB |
Output is correct |
2 |
Correct |
21 ms |
49756 KB |
Output is correct |
3 |
Correct |
21 ms |
49748 KB |
Output is correct |
4 |
Correct |
22 ms |
49756 KB |
Output is correct |
5 |
Incorrect |
22 ms |
49752 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
49752 KB |
Output is correct |
2 |
Correct |
21 ms |
49756 KB |
Output is correct |
3 |
Correct |
21 ms |
49748 KB |
Output is correct |
4 |
Correct |
22 ms |
49756 KB |
Output is correct |
5 |
Incorrect |
22 ms |
49752 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
49752 KB |
Output is correct |
2 |
Correct |
23 ms |
49888 KB |
Output is correct |
3 |
Incorrect |
60 ms |
54612 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
49756 KB |
Output is correct |
2 |
Correct |
21 ms |
49756 KB |
Output is correct |
3 |
Correct |
20 ms |
49800 KB |
Output is correct |
4 |
Correct |
20 ms |
49756 KB |
Output is correct |
5 |
Correct |
21 ms |
49920 KB |
Output is correct |
6 |
Correct |
23 ms |
50012 KB |
Output is correct |
7 |
Correct |
28 ms |
50788 KB |
Output is correct |
8 |
Incorrect |
30 ms |
50772 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
49756 KB |
Output is correct |
2 |
Correct |
22 ms |
49752 KB |
Output is correct |
3 |
Correct |
21 ms |
50012 KB |
Output is correct |
4 |
Correct |
22 ms |
49756 KB |
Output is correct |
5 |
Incorrect |
24 ms |
50012 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
49752 KB |
Output is correct |
2 |
Correct |
24 ms |
49860 KB |
Output is correct |
3 |
Correct |
22 ms |
49752 KB |
Output is correct |
4 |
Correct |
21 ms |
49748 KB |
Output is correct |
5 |
Correct |
22 ms |
49740 KB |
Output is correct |
6 |
Correct |
54 ms |
53512 KB |
Output is correct |
7 |
Correct |
212 ms |
55892 KB |
Output is correct |
8 |
Runtime error |
101 ms |
113248 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |