답안 #1051589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051589 2024-08-10T08:27:17 Z pcc 식물 비교 (IOI20_plants) C++17
14 / 100
2657 ms 121236 KB
#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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Incorrect 0 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 78 ms 7604 KB Output is correct
7 Correct 2094 ms 72556 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 79 ms 7756 KB Output is correct
10 Correct 2068 ms 73144 KB Output is correct
11 Correct 987 ms 121236 KB Output is correct
12 Correct 1696 ms 65620 KB Output is correct
13 Correct 2657 ms 92968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 78 ms 7604 KB Output is correct
7 Correct 2094 ms 72556 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 79 ms 7756 KB Output is correct
10 Correct 2068 ms 73144 KB Output is correct
11 Correct 987 ms 121236 KB Output is correct
12 Correct 1696 ms 65620 KB Output is correct
13 Correct 2657 ms 92968 KB Output is correct
14 Runtime error 22 ms 9816 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2484 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Incorrect 0 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Incorrect 0 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -