답안 #314640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
314640 2020-10-20T14:01:14 Z kostia244 식물 비교 (IOI20_plants) C++17
19 / 100
4000 ms 5880 KB
#include "plants.h"
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const int maxn = 1<<18;
int n, k, ord[maxn], ord2[maxn], oh[maxn];
int in(int l, int r, int x) {
	if(l >= n) l%=n;
	if(r >= n) r%=n;
	if(l > r) {
		return in(l, n-1, x) || in(0, r, x);
	}
	return l <= x && x <= r;
}
void ah(int i, int x) {
	for(int j = 1; j < k; j++) oh[(i+j)%n]+=x;
}
void init(int K, std::vector<int> r) {
	k = K;
	n = r.size();
	if(k == 2) {
		int cur = 0;
		for(int j = 0, i = 0; i < n; i++) {
			while(r[j]) j = (j+1)%n;
			ord[i] = j;
			if(i == j) j++;
		}
		for(int j = 0, i = 0; i < n; i++) {
			while(!r[j]) j = (j+1)%n;
			ord2[i] = j;
			if(i == j) j++;
		}
		return;
	}
	for(int i = 0; i < n; i++) if(r[i] == 0) ah(i, 1);
	for(int L = n; L; L--) {
		int f = 1;
		for(int i = 0; f && i < n; i++) if(!oh[i] && r[i] == 0 && !ord[i]) {
			ord[i] = L;
			ah(i, -1);
			for(int j = 1; j < k; j++) {
				int pos = (n-j+i)%n;
				if(--r[pos] == 0) ah(pos, 1);
			}
			f = 0;
		}
	}
	return;
}

int compare_plants(int x, int y) {
	if(k == 2) {
		if(in(x, ord[x], y) || in(y, ord2[y], x)) return -1;
		if(in(y, ord[y], x) || in(x, ord2[x], y)) return 1;
		return 0;
	}
	return (ord[x] > ord[y]) - (ord[x] < ord[y]);
}

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:22:7: warning: unused variable 'cur' [-Wunused-variable]
   22 |   int cur = 0;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 64 ms 3192 KB Output is correct
7 Correct 85 ms 3448 KB Output is correct
8 Correct 108 ms 5880 KB Output is correct
9 Correct 108 ms 5880 KB Output is correct
10 Correct 106 ms 5796 KB Output is correct
11 Correct 109 ms 5880 KB Output is correct
12 Correct 105 ms 5880 KB Output is correct
13 Correct 104 ms 5880 KB Output is correct
14 Correct 104 ms 5752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 18 ms 384 KB Output is correct
7 Correct 464 ms 3268 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 18 ms 384 KB Output is correct
10 Correct 464 ms 3268 KB Output is correct
11 Correct 326 ms 3480 KB Output is correct
12 Correct 315 ms 3320 KB Output is correct
13 Correct 550 ms 3336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 18 ms 384 KB Output is correct
7 Correct 464 ms 3268 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 18 ms 384 KB Output is correct
10 Correct 464 ms 3268 KB Output is correct
11 Correct 326 ms 3480 KB Output is correct
12 Correct 315 ms 3320 KB Output is correct
13 Correct 550 ms 3336 KB Output is correct
14 Execution timed out 4051 ms 2944 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 71 ms 3320 KB Output is correct
4 Execution timed out 4090 ms 5284 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 64 ms 3192 KB Output is correct
7 Correct 85 ms 3448 KB Output is correct
8 Correct 108 ms 5880 KB Output is correct
9 Correct 108 ms 5880 KB Output is correct
10 Correct 106 ms 5796 KB Output is correct
11 Correct 109 ms 5880 KB Output is correct
12 Correct 105 ms 5880 KB Output is correct
13 Correct 104 ms 5880 KB Output is correct
14 Correct 104 ms 5752 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 18 ms 384 KB Output is correct
21 Correct 464 ms 3268 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 18 ms 384 KB Output is correct
24 Correct 464 ms 3268 KB Output is correct
25 Correct 326 ms 3480 KB Output is correct
26 Correct 315 ms 3320 KB Output is correct
27 Correct 550 ms 3336 KB Output is correct
28 Execution timed out 4051 ms 2944 KB Time limit exceeded
29 Halted 0 ms 0 KB -