답안 #300830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300830 2020-09-17T14:09:09 Z gs14004 식물 비교 (IOI20_plants) C++17
0 / 100
4000 ms 9208 KB
#include "plants.h"
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define rank fuck
using namespace std;
using lint = long long;
using llf = long double;
using pi = pair<lint, lint>;
const int MAXN = 200005;

int n, rank[MAXN];
lint L[MAXN], R[MAXN], DL[MAXN], DR[MAXN];
vector<int> lev[MAXN];

int dist(int x, int y){
	int d = abs(y - x);
	return min(d, n - d);
}

void init(int k, std::vector<int> r) {
	n = sz(r);
	int layer = 0;
	int solved = 0;
	while(count(rank, rank + n, 0)){
		vector<int> vect;
		for(int j=0; j<n; j++){
			if(r[j]) continue;
			bool claim = true;
			for(int x=1; x<=k-1; x++){
				if(r[(j-x+n)%n] == 0) claim = false; 
			}
			if(claim) vect.push_back(j);
		}
		layer++;
		for(auto &j : vect) if(!rank[j]) rank[j] = layer;
		for(auto &j : vect){
			r[j] = k - 1;
			for(int x=1; x<=k-1; x++){
				r[(j-x+n)%n]--;
			}
		}
	}
	for(int i=0; i<n; i++){
		lev[rank[i]].push_back(i);
	}
	set<int> s;
	for(int i=layer; i; i--){
		for(auto &j : lev[i]){
			auto qq = s.upper_bound(j - k);
			auto rr = s.lower_bound(j + k);
			if(qq != s.end() && *qq < j) L[j] = (*qq + n) % n;
			if(rr != s.begin() && *prev(rr) > j) R[j] = *prev(rr) % n;
			DL[j] = DL[L[j]] + (j - L[j] + n) % n;
			DR[j] = DR[R[j]] + (R[j] - j + n) % n;
		}
		for(auto &j : lev[i]){
			s.insert(j-n);
			s.insert(j);
			s.insert(j+n);
		}
	}
}

int compare_plants(int x, int y) {
	if(rank[x] == rank[y]) return 0;
	if(rank[x] > rank[y]) return -compare_plants(y, x);
	lint st = x - DL[x];
	lint ed = x + DR[x];
	return st <= y && y <= ed ? 1 : 0;
}

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:24:6: warning: unused variable 'solved' [-Wunused-variable]
   24 |  int solved = 0;
      |      ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Incorrect 3 ms 4992 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 22 ms 5376 KB Output is correct
7 Correct 466 ms 9208 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 23 ms 5376 KB Output is correct
10 Correct 474 ms 8952 KB Output is correct
11 Execution timed out 4066 ms 7544 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 22 ms 5376 KB Output is correct
7 Correct 466 ms 9208 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 23 ms 5376 KB Output is correct
10 Correct 474 ms 8952 KB Output is correct
11 Execution timed out 4066 ms 7544 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5024 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 97 ms 8312 KB Output is correct
4 Execution timed out 4067 ms 9208 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Incorrect 4 ms 4992 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Incorrect 4 ms 4992 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Incorrect 3 ms 4992 KB Output isn't correct
5 Halted 0 ms 0 KB -