답안 #817538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
817538 2023-08-09T13:23:56 Z hugo_pm 식물 비교 (IOI20_plants) C++17
25 / 100
4000 ms 10956 KB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define sz(v) ((int)((v).size()))

template<typename T>
void chmax(T &x, const T &v) { if (x < v) x = v; }
template<typename T>
void chmin(T &x, const T &v) { if (x > v) x = v; }

using pii = pair<int, int>;
using vi = vector<int>;

string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
	bool first = true;
	string res = "[";
	for (const auto &x : v) {
		if (!first)
			res += ", ";
		first = false;
		res += to_string(x);
	}
	res += "]";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
	cout << ' ' << to_string(H);
	dbg_out(T...);
}

#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

int N, K;
int add(int x, int y) {
	x += y;
	if (x >= N) x -= N;
	return x;
}

int sub(int x, int y) {
	x -= y;
	if (x < 0) x += N;
	return x;
}
int dist(int x, int y) {
	return min(sub(x,y), sub(y,x));
}

vector<int> relative, height;
const int MAX_GRAPH = 300;
bool graph[MAX_GRAPH][MAX_GRAPH];
void pop(int cur, int &toPut) {
	assert(relative[cur] == 0);
	relative[cur] = -1;
	rep(delta, 1, K) {
		int nxt = sub(cur, delta);
		if (relative[nxt] == 0) pop(nxt, toPut);
	}
	height[cur] = toPut--;
	rep(delta, 1, K) {
		relative[sub(cur, delta)]--;
	}
}
void init(int _k, std::vector<int> _r) {
	K = _k;
	relative = _r;
	N = _r.size();
	//--
	height.assign(N, -1);
	int toPut = N-1;
	while (count(all(height), -1)) {
		for (int i = 0; i < N; ++i) {
			if (relative[i] == 0)
				pop(i, toPut);
		}
	}
	dbg(height);
	if (N <= MAX_GRAPH) {
		rep(i, 0, N) rep(j, 0, N) {
			graph[i][j] = (dist(i,j) < K && height[i] > height[j]);
		}
		rep(k, 0, N) rep(i, 0, N) rep(j, 0, N) {
			graph[i][j] |= (graph[i][k] && graph[k][j]);
		}
	}
}

int compare_plants(int x, int y) {
	int xy = (height[x] > height[y]);
	int yx = (height[y] > height[x]);
	if (N <= MAX_GRAPH) {
		xy = graph[x][y], yx = graph[y][x];
	}
	return xy - yx;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
6 Correct 38 ms 3800 KB Output is correct
7 Incorrect 54 ms 4140 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 416 KB Output is correct
7 Correct 87 ms 5080 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 3 ms 316 KB Output is correct
10 Correct 88 ms 5092 KB Output is correct
11 Correct 59 ms 4960 KB Output is correct
12 Correct 91 ms 5136 KB Output is correct
13 Correct 98 ms 5008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 416 KB Output is correct
7 Correct 87 ms 5080 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 3 ms 316 KB Output is correct
10 Correct 88 ms 5092 KB Output is correct
11 Correct 59 ms 4960 KB Output is correct
12 Correct 91 ms 5136 KB Output is correct
13 Correct 98 ms 5008 KB Output is correct
14 Correct 528 ms 5572 KB Output is correct
15 Execution timed out 4049 ms 9452 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 228 KB Output is correct
3 Correct 42 ms 3932 KB Output is correct
4 Execution timed out 4073 ms 10956 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 28 ms 1240 KB Output is correct
8 Correct 30 ms 1236 KB Output is correct
9 Correct 28 ms 1236 KB Output is correct
10 Correct 30 ms 1236 KB Output is correct
11 Correct 27 ms 1236 KB Output is correct
12 Correct 28 ms 1280 KB Output is correct
13 Correct 31 ms 1340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
6 Correct 38 ms 3800 KB Output is correct
7 Incorrect 54 ms 4140 KB Output isn't correct
8 Halted 0 ms 0 KB -