답안 #1051479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051479 2024-08-10T07:18:36 Z Gromp15 식물 비교 (IOI20_plants) C++17
0 / 100
1 ms 504 KB
#include <bits/stdc++.h>
#include "plants.h"
#define sz(x) (int)x.size()
using namespace std;

int n;
vector<vector<int>> adj;

void init(int k, std::vector<int> r) {
	n = sz(r);
	adj.resize(n);
	vector<bool> vis(n);
	for (int i = 0; i < n; i++) {
		vector<int> idx;
		for (int j = 0; j < n; j++) if (!vis[j]) {
			if (!r[j]) idx.emplace_back(j), vis[j] = 1;
		}
		if (idx.empty()) return;
		for (int v : idx) {
			for (int j = 1; j < k; j++) {
				int u = (v + j) % n;
				if (!vis[u]) { 
					adj[v].emplace_back(u);
				}
			}
			int u = (v - 1 + n) % n;
			if (!vis[u]) adj[v].emplace_back(u);
		}
		for (int v : idx) {
			vis[v] = 1;
			for (int j = 1; j < k; j++) {
				int u = (v - j + n) % n;
				r[u]--;
			}
		}
	}
	for (int i = 0; i < n; i++) assert(vis[i]);
}

bool reachable(int x, int y) {
	vector<bool> vis(n);
	auto dfs = [&](auto&& s, int v) -> void {
		vis[v] = 1;
		for (int u : adj[v]) if (!vis[u]) s(s, u);
	};
	dfs(dfs, x);
	return vis[y];
}

int compare_plants(int x, int y) {
	assert(!reachable(x, y) || !reachable(y, x));
	return reachable(x, y) ? 1 : reachable(y, x) ? -1 : 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 376 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 376 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 504 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
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 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -