Submission #837106

# Submission time Handle Problem Language Result Execution time Memory
837106 2023-08-25T00:07:19 Z JustAmethyst Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1000 ms 1567584 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) {
		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);
// }
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 28 ms 33748 KB Output is correct
7 Execution timed out 1142 ms 1567584 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 28 ms 33748 KB Output is correct
7 Execution timed out 1142 ms 1567584 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 216 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 336 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 10 ms 1140 KB Output is correct
9 Execution timed out 1095 ms 21612 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 Incorrect 31 ms 20712 KB Answer gives possible 0 while actual possible 1
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 28 ms 33748 KB Output is correct
7 Execution timed out 1142 ms 1567584 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 28 ms 33748 KB Output is correct
7 Execution timed out 1142 ms 1567584 KB Time limit exceeded
8 Halted 0 ms 0 KB -