답안 #783571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
783571 2023-07-15T04:20:02 Z mindiyak 슈퍼트리 잇기 (IOI20_supertrees) C++14
0 / 100
1000 ms 16016 KB
#include "supertrees.h"
#include <vector>
#include <iostream>

#define pb push_back

using namespace std;

int find_head(vector<int> a,int val){
	if(a[val] == val)
	    return val;
	return find_head(a,a[val]);
}

int find_leaf(vector<int> a,int val){
	if(a[val] == val)
	    return val;
	return find_leaf(a,a[val]);
}

int construct(vector<vector<int>> p) {
    // cout << "started" << endl;
	int n = p.size();

	vector<vector<int>> ans;
	vector<int> temp(n,0);
	vector<int> head;
	vector<int> leaf;
	for (int i = 0; i < n; i++) {
		ans.pb(temp);
		head.pb(i);
		leaf.pb(i);
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p[i][j] >= 1){
				int c = min(i,j),d = max(i,j);

				int h_c = find_head(head,c);
				int h_d = find_head(head,d);
				int l_c = find_leaf(leaf,c);
				int l_d = find_leaf(leaf,d);

				if(h_c != h_d){
				    ans[h_c][h_d] = 1;
				    ans[h_d][h_c] = 1;
				}
				head[h_d] = h_c;
				leaf[l_c] = l_d;
			} 
		}
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int c = min(i,j),d = max(i,j);
			int h_c = find_head(head,c);
			int h_d = find_head(head,d);
			int l_c = find_leaf(leaf,c);
			int l_d = find_leaf(leaf,d);

			if(p[i][j] == 2){
				ans[h_c][l_d] = 1;
				ans[l_d][h_c] = 1;
			}
			
			if(p[i][j] == 0 and h_c == h_d){
				return 0;
			}
			if(p[i][j] == 1 and h_c != h_d){
				return 0;
			}
			if(p[i][j] == 2 and (h_c != h_d or l_c != l_d)){
				return 0;
			}
		}
	}


	build(ans);
// 	cout << "finish" << endl;
	return 1;
}
# 결과 실행 시간 메모리 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 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 803 ms 1156 KB Output is correct
7 Execution timed out 1079 ms 16016 KB Time limit exceeded
8 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 803 ms 1156 KB Output is correct
7 Execution timed out 1079 ms 16016 KB Time limit exceeded
8 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 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Too few ways to get from 0 to 1, should be 2 found 1
3 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 803 ms 1156 KB Output is correct
7 Execution timed out 1079 ms 16016 KB Time limit exceeded
8 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 803 ms 1156 KB Output is correct
7 Execution timed out 1079 ms 16016 KB Time limit exceeded
8 Halted 0 ms 0 KB -