Submission #1035455

# Submission time Handle Problem Language Result Execution time Memory
1035455 2024-07-26T11:19:53 Z vjudge1 Comparing Plants (IOI20_plants) C++14
0 / 100
39 ms 33192 KB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 10'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);
	}
	if(at < n)
		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, cnt=0;cnt+1<k;j=(j+1)%n, cnt++) {
//		cout << idx << " " << j << endl;
		g[idx].push_back(j);
		g[idx].push_back(dummy);
		tim[dummy]=cnt+1;
		nums.push_back(dummy++);
	}
	int timer=-1;
	for(int j = (idx-1+n)%n;j!=idx;j=(j-1+n)%n) {
		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()) {
//			cout << (*prev(it)) << " " << j << endl;
			g[(*prev(it))].push_back(j);
		}
		if(it!=(--nums.end())) {
//			cout << j << " " << (*next(it)) << endl;
			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;
	}
	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;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12888 KB Output is correct
2 Correct 5 ms 12888 KB Output is correct
3 Correct 5 ms 12984 KB Output is correct
4 Correct 5 ms 12980 KB Output is correct
5 Correct 5 ms 12892 KB Output is correct
6 Correct 35 ms 16692 KB Output is correct
7 Runtime error 39 ms 33192 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12888 KB Output is correct
2 Correct 5 ms 12888 KB Output is correct
3 Correct 5 ms 12892 KB Output is correct
4 Incorrect 5 ms 12892 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12888 KB Output is correct
2 Correct 5 ms 12888 KB Output is correct
3 Correct 5 ms 12892 KB Output is correct
4 Incorrect 5 ms 12892 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12888 KB Output is correct
2 Incorrect 5 ms 12888 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12892 KB Output is correct
2 Correct 5 ms 12892 KB Output is correct
3 Correct 5 ms 12892 KB Output is correct
4 Correct 5 ms 12892 KB Output is correct
5 Incorrect 5 ms 12892 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12808 KB Output is correct
2 Correct 5 ms 12772 KB Output is correct
3 Correct 5 ms 12892 KB Output is correct
4 Correct 5 ms 12868 KB Output is correct
5 Incorrect 6 ms 12892 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12888 KB Output is correct
2 Correct 5 ms 12888 KB Output is correct
3 Correct 5 ms 12984 KB Output is correct
4 Correct 5 ms 12980 KB Output is correct
5 Correct 5 ms 12892 KB Output is correct
6 Correct 35 ms 16692 KB Output is correct
7 Runtime error 39 ms 33192 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -