답안 #884521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884521 2023-12-07T15:01:30 Z 42kangaroo 참나무 (IOI23_beechtree) C++17
13 / 100
290 ms 194556 KB
//  D. Beech Tree

#include<bits/stdc++.h>
#include "beechtree.h"

using namespace std;

using g_t = vector<vector<int>>;
using dVal = pair<map<int, int>, list<set<int>>>;

struct ValR {
	int d, n, co;
};

dVal dfs(int n, g_t &g, vector<bool> &po, vector<int> &c) {
	map<int, int> r;
	map<int, vector<pair<int, int>>> ve;
	list<set<int>> se;
	se.push_back(set<int>());
	for (auto e: g[n]) {
		if (r.find(c[e]) != r.end()) po[n] = false;
		r[c[e]] = 1;
		ve[c[e]] = {};
		se.back().insert(c[e]);
	}
	for (auto e: g[n]) {
		auto [re, li] = dfs(e, g, po, c);
		if (!po[e]) {
			po[n] = false;
		}
		if (po[n]) {
			for (auto &[co, d]: re) {
				if (r.find(co) == r.end()) {
					po[n] = false;
					break;
				}
				if (co == c[e]) r[c[e]] = d + 1;
				ve[co].emplace_back(d, e);
			}
			auto itS = se.begin();
			for (auto & it : li) {
				while (itS != se.end() && itS->size() < it.size()) {
					for (auto cos: *itS) {
						if (it.erase(cos) == 0) {
							po[n] = false;
							break;
						}
					}
					itS++;
				}
				if (!it.empty()) {
					auto act = itS;
					itS = se.insert(itS, set<int>());
					for (auto cos: it) {
						if (act->erase(cos) == 0) {
							po[n] = false;
							break;
						}
						itS->insert(cos);
					}
				}
			}
		}
	}
	if (!po[n]) return {};
	map<int, int> val;
	vector<ValR> si;
	for (auto &[co, vec]: ve) {
		si.push_back({r[co] - 1, 0, co});
		si.push_back({r[co], 0, co});
		for (auto [d, e]: vec) {
			val[e] = 0;
			if (d > r[co]) {
				po[n] = false;
				return {};
			} else if (d == r[co]) {
				si.back().n++;
				si[si.size() - 2].n++;
			} else if (d == r[co] - 1) {
				si[si.size() - 2].n++;
			}
		}
	}
	std::sort(si.begin(), si.end(), [](const ValR &l, const ValR &r) { return l.n > r.n; });
	int i = 1;
	list<set<int>> siO;
	int last = g[n].size() + 1;
	for (auto v: si) {
		for (auto [d, e]: ve[v.co]) {
			if (d >= v.d) {
				if (val[e] != i - 1) {
					po[n] = false;
					return {};
				}
				val[e] = i;
			}
		}
		if (v.d == r[v.co] -1) {
			if (v.n < last) {
				siO.push_back({});
			}
			siO.back().insert(v.co);
			last = v.n;
		}
		i++;
	}
	auto itS = se.begin();
	for (auto & it : siO) {
		while (itS != se.end() && itS->size() <= it.size()) {
			for (auto cos: *itS) {
				if (it.erase(cos) == 0) {
					po[n] = false;
					break;
				}
			}
			itS++;
		}
		if (!it.empty()) {
			auto act = itS;
			itS = se.insert(itS, set<int>());
			for (auto cos: it) {
				if (act->erase(cos) == 0) {
					po[n] = false;
					break;
				}
				itS->insert(cos);
			}
		}
	}
	return {r, se};
}

vector<int> beechtree(int N, int M, vector<int> P, vector<int> C) {
	g_t g(N);
	for (int i = 1; i < N; ++i) {
		g[P[i]].push_back(i);
	}
	vector<bool> po(N, true);
	dfs(0, g, po, C);
	return {po.begin(), po.end()};
}

# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 352 KB Output is correct
21 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
22 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 225 ms 194556 KB Output is correct
8 Correct 218 ms 194504 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 436 KB Output is correct
13 Correct 3 ms 2140 KB Output is correct
14 Correct 3 ms 2136 KB Output is correct
15 Correct 2 ms 2140 KB Output is correct
16 Correct 2 ms 2140 KB Output is correct
17 Correct 290 ms 194088 KB Output is correct
18 Correct 270 ms 194544 KB Output is correct
19 Correct 233 ms 194384 KB Output is correct
20 Correct 215 ms 194368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 444 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 139 ms 7100 KB Output is correct
16 Correct 111 ms 5972 KB Output is correct
17 Runtime error 29 ms 10836 KB Execution killed with signal 11
18 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 348 KB Output is correct
5 Correct 225 ms 194556 KB Output is correct
6 Correct 218 ms 194504 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 139 ms 25172 KB Output is correct
12 Correct 230 ms 13928 KB Output is correct
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
25 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 352 KB Output is correct
17 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
18 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
25 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 352 KB Output is correct
17 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
18 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
25 Halted 0 ms 0 KB -