답안 #1051574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051574 2024-08-10T08:17:57 Z Gromp15 식물 비교 (IOI20_plants) C++17
25 / 100
4000 ms 8076 KB
#include <bits/stdc++.h>
#include "plants.h"
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;

int n, k;
vector<int> got;
vector<int> r;
vector<vector<bool>> can;

void init(int _k, std::vector<int> _r) {
	k = _k;
	r = _r;
	n = sz(r);
	if (2 * k > n) {
		got.resize(n);
		vector<bool> vis(n);
		for (int i = 0; i < n; i++) {
			vector<int> good;
			for (int j = 0; j < n; j++) if (!r[j] && !vis[j]) {
				bool ok = 1;
				for (int z = 1; z < k; z++) {
					int idx = j - z;
					if (idx < 0) idx += n;
					if (!vis[idx] && !r[idx]) {
						ok = 0; break;
					}
				}
				if (ok) {
					good.emplace_back(j);
				}
			}
			if (good.empty()) break;
			for (int v : good) vis[v] = 1;
			assert(good.size() == 1);
			for (int c : good) {
				got[c] = n - i;
				for (int j = 1; j < k; j++) {
					int idx = c - j;
					if (idx < 0) idx += n;
					r[idx]--;
				}
			}
		}
		r = _r;
		return;
	}
	if (n <= 300) {
		can.resize(n, vector<bool>(n));
		for (int t = 0; t < n; t++) {
			r = _r;
			vector<bool> vis(n);
			for (int i = 0; i < n; i++) {
				vector<int> good;
				for (int j = 0; j < n; j++) if (!r[j] && !vis[j]) {
					bool ok = 1;
					for (int z = 1; z < k; z++) {
						int idx = j - z;
						if (idx < 0) idx += n;
						if (!vis[idx] && !r[idx]) {
							ok = 0; break;
						}
					}
					if (ok) {
						good.emplace_back(j);
					}
				}
				if (find(all(good), t) != good.end()) good.erase(find(all(good), t));
				if (good.empty()) break;
				for (int v : good) vis[v] = 1;
				for (int c : good) {
					for (int j = 1; j < k; j++) {
						int idx = c - j;
						if (idx < 0) idx += n;
						r[idx]--;
					}
				}
			}
			for (int i = 0; i < n; i++) can[t][i] = vis[i];
		}
	}
}

bool win(int x, int y) { // can x be used before y
	if (2 * k > n) {
		int d = (x - y + n) % n;
		if (d < k && !r[y]) return 0;
		return got[x] > got[y];
	}
	return can[y][x];
}

int compare_plants(int x, int y) {
	int w1 = win(x, y), w2 = win(y, x);
	assert(w1 || w2);
	return w1 && w2 ? 0 : w1 ? 1 : -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 26 ms 3940 KB Output is correct
7 Runtime error 22 ms 6992 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 548 KB Output is correct
7 Correct 80 ms 4496 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 82 ms 4604 KB Output is correct
11 Correct 71 ms 4408 KB Output is correct
12 Correct 62 ms 4700 KB Output is correct
13 Correct 85 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 548 KB Output is correct
7 Correct 80 ms 4496 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 82 ms 4604 KB Output is correct
11 Correct 71 ms 4408 KB Output is correct
12 Correct 62 ms 4700 KB Output is correct
13 Correct 85 ms 4432 KB Output is correct
14 Correct 925 ms 4748 KB Output is correct
15 Execution timed out 4037 ms 8076 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 21 ms 6320 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 436 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 11 ms 1372 KB Output is correct
8 Correct 27 ms 1308 KB Output is correct
9 Correct 24 ms 1372 KB Output is correct
10 Correct 29 ms 1312 KB Output is correct
11 Correct 18 ms 1320 KB Output is correct
12 Correct 23 ms 1368 KB Output is correct
13 Correct 7 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Runtime error 1 ms 444 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 26 ms 3940 KB Output is correct
7 Runtime error 22 ms 6992 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -