답안 #837108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
837108 2023-08-25T00:10:06 Z JustAmethyst 슈퍼트리 잇기 (IOI20_supertrees) C++17
0 / 100
1000 ms 2097152 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define sz(x) (int)(x.size())
using namespace std;

vector<int> a, b;
int as, bs;
vector<vector<int>> answer;
vector<int> done;

// void build(vector<vector<int>> ans) {
// 	for (auto x : ans) {
// 		for (auto y : x) {
// 			cout << y << " ";
// 		}
// 		cout << "\n";
// 	}
// }

bool check1(int x, int n, vector<vector<int>> p) {
	int c = 0;
	for (int i = 0; i < n; ++i) {
		if (p[x][i] == 1) {
			if (done[i] != 1) return 0;
			++c;
		}
	}
	return (c == as);
}

bool check2(int x, int n, vector<vector<int>> p) {
	int c = 1;
	for (int i = 0; i < n; ++i) {
		if (i != x) {
			if (p[x][i] == 2) {
				// if (done[i] != 2) {
				// 	cout << "here - " << x << " " << i << "\n";
				// 	return 0;
				// }
				++c;
			}
		}
	}
	// cout << "c = " << c << "\n";
	return (c == (as + bs));
}

void place(int x, int n, vector<vector<int>> p) {
	bool y = 0;
	int z = 0;
	done[x] = 3;
	for (int i = 0; i < n; ++i) {
		if (i != x && p[x][i]) {
			if (p[x][i] == 1) {
				// cout << x << " " << i << "\n";
				y = 1;
			}

			if (done[i] == 0) place(i, n, p);
		}

		if (p[x][i] == 0) ++z;
	}

	if (z == n-1) return;

	if (y) {
		a.push_back(x);
		++as;
		done[x] = 1;
	}
	else {
		b.push_back(x);
		++bs;
		done[x] = 2;
	}
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	for (int i = 0; i < n; i++) {
		done.push_back(0);
		vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}

	for (int i = 0; i < n; ++i) {
		as = 0, bs = 0;
		if (done[i] == 0) place(i, n, p);
		else continue;

		// cout << i << " - " << done[i] << "\n";

		if (done[i] == 3) continue;
		
		if (bs <= 2 && as == 0) {
			// cout << 2 << "\n";
			return 0;
		}

		for (int j = 1; j < as; ++j) {
			answer[a[0]][a[j]] = 1;
			answer[a[j]][a[0]] = 1;
		}
		if (as && bs) {
			answer[a[0]][b[0]] = 1;
			answer[b[0]][a[0]] = 1;

			answer[a[0]][b[bs-1]] = 1;
			answer[b[bs-1]][a[0]] = 1;
		}
		else if (bs) {
			answer[b[0]][b[bs-1]] = 1;
			answer[b[bs-1]][b[0]] = 1;
		}
		for (int j = 0; j < bs-1; ++j) {
			answer[b[j]][b[j+1]] = 1;
			answer[b[j+1]][b[j]] = 1;
		}

		while (!a.empty()) {
			if (!check1(a.back(), n, p)) return 0;
			a.pop_back();
		}
		while (!b.empty()) {
			if (!check2(b.back(), n, p)) return 0;
			b.pop_back();
		}

		// a.clear();
		// b.clear();

		// for (auto x : done) cout << x << " ";
		// for (auto x : a) cout << x << " ";
		// cout << "\n";
		// for (auto x : b) cout << x << " ";
		// cout << "\n";
	}

	// for (int i = 1; i < n; ++i) {
	// 	answer[0][i] = 1;
	// 	answer[i][0] = 1;
	// }
	build(answer);
	return 1;
}

// int main() {
// 	int n, a;
// 	cin >> n;
// 	vector<vector<int>> p;
// 	for (int i = 0; i < n; ++i) {
// 		p.push_back({});
// 		for (int j = 0; j < n; ++j) {
// 			cin >> a;
// 			p[i].push_back(a);
// 		}
// 	}
// 	construct(p);
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 23 ms 33748 KB Output is correct
7 Runtime error 856 ms 2097152 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 23 ms 33748 KB Output is correct
7 Runtime error 856 ms 2097152 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 10 ms 1244 KB Output is correct
9 Execution timed out 1046 ms 17860 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 338 ms 25320 KB Output is correct
5 Execution timed out 1053 ms 409428 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 23 ms 33748 KB Output is correct
7 Runtime error 856 ms 2097152 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 23 ms 33748 KB Output is correct
7 Runtime error 856 ms 2097152 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -