답안 #302938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
302938 2020-09-19T13:23:03 Z 8e7 식물 비교 (IOI20_plants) C++14
19 / 100
4000 ms 9580 KB
#include "plants.h"
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> v, one, zero, ind1, ind0, arr;
int k;
int n;
void init(int K, vector<int> r) {
	v = r;
	n = r.size();
	arr.resize(n);
	k = K;
	if (K == 2) {
		int cnt = 0, cur = 0;
		one.push_back(cnt);
		for (int i = 0;i < n;i++) {
			if (r[i] == 0) {
				ind1.push_back(cur);
				cur = i + 1;
				cnt++;
			}
			one.push_back(cnt);
		}
		if (r[n - 1] == 1) {
			for (int i = n - 1;i >= 0;i--) {
				if (one[i] == cnt) ind1[0] = i;
				one[i] %= cnt;
			}
		}
		cnt = 0, cur = 0;
		zero.push_back(cnt);
		for (int i = 0;i < n;i++) {
			if (r[i] == 1) {
				ind0.push_back(cur);
				cur = i + 1;
				cnt++;
			}
			zero.push_back(cnt);
		}
		if (r[n - 1] == 0) {
			for (int i = n - 1;i >= 0;i--) {
				if (zero[i] == cnt) ind0[0] = i;
				zero[i] %= cnt;
			}
		}
	} else {
		for (int i = n;i >= 1;i--) {
			for (int j = n - 1;j >= 0;j--) {
				if (r[j] == 0) {
					int ind = (j - 1 + n) % n, found = 1;
					for (int cnt = 0;cnt < k - 1;cnt++) {
						if (r[ind] == 0) {
							found = 0;
							break;
						}
						ind = (ind - 1 + n) % n;
					}
					if (found) {
						arr[j] = i;
						int ind = (j + n) % n;
						for (int cnt = 0;cnt < k;cnt++) {
							r[ind]--;
							ind = (ind - 1 + n) % n;
						}

						//for (int i = 0;i < n;i++) cout << r[i] << " ";
						//cout << endl;
						break;
					}
				}
			}
		}
		//for (int i = 0;i < n;i++) cout << arr[i] << " ";
		//cout << endl;
	}
	return;
}

int compare_plants(int x, int y) {
	if (k == 2) {
		if (one[x] != one[y] && zero[x] != zero[y]) {
			return 0;
		} else {
			if (one[x] == one[y]) {
				//cout <<(x - ind1[one[x]] + n) % n << " " << (y - ind1[one[y]] + n) % n << endl;
				if ((x - ind1[one[x]] + n) % n < (y - ind1[one[y]] + n) % n) return -1;
				else return 1;
			} else {
				if ((x - ind0[zero[x]] + n) % n < (y - ind0[zero[y]] + n) % n) return 1;
				else return -1;
			}
		}
	} else {
		return arr[x] > arr[y] ? 1 : -1;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 65 ms 3192 KB Output is correct
7 Correct 83 ms 3832 KB Output is correct
8 Correct 111 ms 9192 KB Output is correct
9 Correct 115 ms 9580 KB Output is correct
10 Correct 114 ms 8744 KB Output is correct
11 Correct 110 ms 8936 KB Output is correct
12 Correct 113 ms 8692 KB Output is correct
13 Correct 113 ms 8936 KB Output is correct
14 Correct 108 ms 9068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 13 ms 384 KB Output is correct
7 Correct 338 ms 3320 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 14 ms 384 KB Output is correct
10 Correct 351 ms 3324 KB Output is correct
11 Correct 285 ms 3192 KB Output is correct
12 Correct 244 ms 3448 KB Output is correct
13 Correct 403 ms 3320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 13 ms 384 KB Output is correct
7 Correct 338 ms 3320 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 14 ms 384 KB Output is correct
10 Correct 351 ms 3324 KB Output is correct
11 Correct 285 ms 3192 KB Output is correct
12 Correct 244 ms 3448 KB Output is correct
13 Correct 403 ms 3320 KB Output is correct
14 Correct 3145 ms 3652 KB Output is correct
15 Execution timed out 4083 ms 5752 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 78 ms 3192 KB Output is correct
4 Execution timed out 4021 ms 5756 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Incorrect 1 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Incorrect 0 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 65 ms 3192 KB Output is correct
7 Correct 83 ms 3832 KB Output is correct
8 Correct 111 ms 9192 KB Output is correct
9 Correct 115 ms 9580 KB Output is correct
10 Correct 114 ms 8744 KB Output is correct
11 Correct 110 ms 8936 KB Output is correct
12 Correct 113 ms 8692 KB Output is correct
13 Correct 113 ms 8936 KB Output is correct
14 Correct 108 ms 9068 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 13 ms 384 KB Output is correct
21 Correct 338 ms 3320 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 14 ms 384 KB Output is correct
24 Correct 351 ms 3324 KB Output is correct
25 Correct 285 ms 3192 KB Output is correct
26 Correct 244 ms 3448 KB Output is correct
27 Correct 403 ms 3320 KB Output is correct
28 Correct 3145 ms 3652 KB Output is correct
29 Execution timed out 4083 ms 5752 KB Time limit exceeded
30 Halted 0 ms 0 KB -