답안 #792048

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792048 2023-07-24T14:24:56 Z mousebeaver 슈퍼트리 잇기 (IOI20_supertrees) C++14
40 / 100
181 ms 24004 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

int construct(vector<vector<int>> p) 
{
	bool sub1 = true;
	bool sub2 = true;
	int n = p.size();

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if(p[i][j] != 1)
			{
				sub1 = false;
			}
			if(p[i][j] > 1)
			{
				sub2 = false;
			}
		}
	}
	
	if(sub1)
	{
		vector<vector<int>> adjmatrix(n, vector<int> (n, 0));
		for(int i = 0; i < n-1; i++)
		{
			adjmatrix[i][i+1] = 1;
			adjmatrix[i+1][i] = 1;
		}
		build(adjmatrix);
		return 1;
	}
	if(sub2)
	{
		vector<vector<int>> adjmatrix(n, vector<int> (n, 0));
		vector<bool> used(n, false);
		for(int i = 0; i < n; i++)
		{
			if(!used[i])
			{
				vector<int> nodes(0);
				for(int j = 0; j < n; j++)
				{
					if(p[i][j] == 1)
					{
						nodes.push_back(j);
						used[j] = true;
					}
				}

				for(int i : nodes)
				{
					if(count(p[i].begin(), p[i].end(), 1) != (int) nodes.size())
					{
						return 0;
					}
					for(int j : nodes)
					{
						if(p[i][j] != 1)
						{
							return 0;
						}
					}
				}

				for(int i = 0; i < (int) nodes.size()-1; i++)
				{
					adjmatrix[nodes[i]][nodes[i+1]] = 1;
					adjmatrix[nodes[i+1]][nodes[i]] = 1;
				}
			}
		}
		build(adjmatrix);
		return 1;
	}
	
	//sub3:
	vector<vector<int>> adjmatrix(n, vector<int> (n, 0));
	vector<bool> used(n, false);
	for(int i = 0; i < n; i++)
	{
		if(!used[i])
		{
			vector<int> nodes(0);
			for(int j = 0; j < n; j++)
			{
				if(p[i][j] > 0)
				{
					nodes.push_back(j);
					used[j] = true;
				}
			}

			if(nodes.size() == 2)
			{
				return 0;
			}
			for(int i : nodes)
			{
				if(count(p[i].begin(), p[i].end(), 0) != n-nodes.size())
				{
					return 0;
				}
				for(int j : nodes)
				{
					if(p[i][j] == 0)
					{
						return 0;
					}
				}
			}

			for(int i = 0; i < (int) nodes.size()-1; i++)
			{
				adjmatrix[nodes[i]][nodes[i+1]] = 1;
				adjmatrix[nodes[i+1]][nodes[i]] = 1;
			}
			if(nodes.size() > 1)
			{
				adjmatrix[nodes[0]][nodes[nodes.size()-1]] = 1;
				adjmatrix[nodes[nodes.size()-1]][nodes[0]] = 1;
			}
		}
	}
	build(adjmatrix);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:104:43: warning: comparison of integer expressions of different signedness: 'std::__iterator_traits<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, void>::difference_type' {aka 'long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |     if(count(p[i].begin(), p[i].end(), 0) != n-nodes.size())
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 142 ms 22032 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 142 ms 22032 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1136 KB Output is correct
13 Correct 148 ms 21948 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 83 ms 12044 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 37 ms 5764 KB Output is correct
21 Correct 149 ms 21952 KB Output is correct
22 Correct 150 ms 22012 KB Output is correct
23 Correct 149 ms 22020 KB Output is correct
24 Correct 149 ms 22016 KB Output is correct
25 Correct 59 ms 12036 KB Output is correct
26 Correct 58 ms 12108 KB Output is correct
27 Correct 155 ms 22008 KB Output is correct
28 Correct 149 ms 22016 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 6 ms 1236 KB Output is correct
9 Correct 146 ms 23996 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1204 KB Output is correct
13 Correct 148 ms 23904 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 64 ms 14056 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 37 ms 6172 KB Output is correct
22 Correct 146 ms 23924 KB Output is correct
23 Correct 146 ms 24004 KB Output is correct
24 Correct 150 ms 23936 KB Output is correct
25 Correct 62 ms 14068 KB Output is correct
26 Correct 67 ms 14064 KB Output is correct
27 Correct 145 ms 23940 KB Output is correct
28 Correct 150 ms 23884 KB Output is correct
29 Correct 60 ms 14064 KB Output is correct
# 결과 실행 시간 메모리 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 45 ms 5760 KB Output is correct
5 Correct 144 ms 21964 KB Output is correct
6 Correct 145 ms 22028 KB Output is correct
7 Correct 149 ms 22028 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 39 ms 6136 KB Output is correct
10 Correct 148 ms 23960 KB Output is correct
11 Correct 158 ms 23916 KB Output is correct
12 Correct 181 ms 23924 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 1 ms 212 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
15 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 142 ms 22032 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1136 KB Output is correct
13 Correct 148 ms 21948 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 83 ms 12044 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 37 ms 5764 KB Output is correct
21 Correct 149 ms 21952 KB Output is correct
22 Correct 150 ms 22012 KB Output is correct
23 Correct 149 ms 22020 KB Output is correct
24 Correct 149 ms 22016 KB Output is correct
25 Correct 59 ms 12036 KB Output is correct
26 Correct 58 ms 12108 KB Output is correct
27 Correct 155 ms 22008 KB Output is correct
28 Correct 149 ms 22016 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 300 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 6 ms 1236 KB Output is correct
37 Correct 146 ms 23996 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 6 ms 1204 KB Output is correct
41 Correct 148 ms 23904 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 64 ms 14056 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 37 ms 6172 KB Output is correct
50 Correct 146 ms 23924 KB Output is correct
51 Correct 146 ms 24004 KB Output is correct
52 Correct 150 ms 23936 KB Output is correct
53 Correct 62 ms 14068 KB Output is correct
54 Correct 67 ms 14064 KB Output is correct
55 Correct 145 ms 23940 KB Output is correct
56 Correct 150 ms 23884 KB Output is correct
57 Correct 60 ms 14064 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 3 ms 852 KB Output is correct
61 Correct 63 ms 14080 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Incorrect 0 ms 212 KB Too many ways to get from 0 to 9, should be 1 found no less than 2
64 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 142 ms 22032 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1136 KB Output is correct
13 Correct 148 ms 21948 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 83 ms 12044 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 37 ms 5764 KB Output is correct
21 Correct 149 ms 21952 KB Output is correct
22 Correct 150 ms 22012 KB Output is correct
23 Correct 149 ms 22020 KB Output is correct
24 Correct 149 ms 22016 KB Output is correct
25 Correct 59 ms 12036 KB Output is correct
26 Correct 58 ms 12108 KB Output is correct
27 Correct 155 ms 22008 KB Output is correct
28 Correct 149 ms 22016 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 300 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 6 ms 1236 KB Output is correct
37 Correct 146 ms 23996 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 6 ms 1204 KB Output is correct
41 Correct 148 ms 23904 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 64 ms 14056 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 37 ms 6172 KB Output is correct
50 Correct 146 ms 23924 KB Output is correct
51 Correct 146 ms 24004 KB Output is correct
52 Correct 150 ms 23936 KB Output is correct
53 Correct 62 ms 14068 KB Output is correct
54 Correct 67 ms 14064 KB Output is correct
55 Correct 145 ms 23940 KB Output is correct
56 Correct 150 ms 23884 KB Output is correct
57 Correct 60 ms 14064 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 45 ms 5760 KB Output is correct
62 Correct 144 ms 21964 KB Output is correct
63 Correct 145 ms 22028 KB Output is correct
64 Correct 149 ms 22028 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 39 ms 6136 KB Output is correct
67 Correct 148 ms 23960 KB Output is correct
68 Correct 158 ms 23916 KB Output is correct
69 Correct 181 ms 23924 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Incorrect 1 ms 212 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
72 Halted 0 ms 0 KB -