답안 #1032898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032898 2024-07-24T10:32:40 Z fv3 슈퍼트리 잇기 (IOI20_supertrees) C++14
56 / 100
154 ms 30224 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

int construct(vector<vector<int>> p) 
{
	int n = p.size();

	for (int i = 0; i < n; i++)
		p[i].push_back(i);
	sort(p.begin(), p.end());

	// 1. Find all parts which are the same
	vector<vector<int>> parts = { {p[0].back()} };
	map<vector<int>, vector<int>> cycles;

	int l = 0, r = 1;
	while (r < n)
	{
		int i = 0;
		for (; i < n; i++)
		{
			if (p[r-1][i] != p[r][i])
				break;
		}

		if (i != n)
		{
			parts.push_back({p[r].back()});

			// Count 1's in last part
			int one_cnt = 0;
			for (int j = 0; j < n; j++)
			{
				if (p[r-1][j] == 1)
					one_cnt++;
			}

			if (one_cnt != r - l)
				return 0;

			vector<int> bs(n);
			for (int j = 0; j < n; j++)
			{
				if (p[r-1][j]) 
					bs[j] = 1;
			}

			cycles[bs].push_back(p[r-1].back());
			l = r;
		}
		else
		{
			parts.back().push_back(p[r].back());
		}

		r++;
	}

	// Count 1's in last part
	int one_cnt = 0;
	for (int j = 0; j < n; j++)
	{
		if (p[r-1][j] == 1)
			one_cnt++;
	}

	if (one_cnt != r - l)
		return 0;

	vector<int> bs(n);
	for (int j = 0; j < n; j++)
	{
		if (p[r-1][j]) 
			bs[j] = 1;
	}
	cycles[bs].push_back(p[r-1].back());

	// 2. Generate parts
	vector<vector<int>> answer(n, vector<int>(n));
	for (auto path : parts)
	{
		for (int i = 1; i < path.size(); i++)
		{
			answer[path[i]][path[i-1]] = 1;
			answer[path[i-1]][path[i]] = 1;
		}
	}

	// 3. Generate cycles
	cerr << parts.size() << '\n';
	cerr << cycles.size() << '\n';

	for (auto cycle : cycles)
	{
		if (cycle.second.size() == 1)
			continue;

		if (cycle.second.size() == 2)
			return 0;

		for (auto e : cycle.second)
			cerr << e << ' ';
		cerr << '\n';

		for (int i = 1; i < cycle.second.size(); i++)
		{
			answer[cycle.second[i]][cycle.second[i-1]] = 1;
			answer[cycle.second[i-1]][cycle.second[i]] = 1;
		}
		answer[cycle.second[0]][cycle.second.back()] = 1;
		answer[cycle.second.back()][cycle.second[0]] = 1;
	}

	// 4. Profit
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:84:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |   for (int i = 1; i < path.size(); i++)
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp:107:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |   for (int i = 1; i < cycle.second.size(); i++)
      |                   ~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 5 ms 1372 KB Output is correct
7 Correct 123 ms 25944 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 5 ms 1372 KB Output is correct
7 Correct 123 ms 25944 KB Output is correct
8 Correct 1 ms 344 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 600 KB Output is correct
12 Correct 6 ms 1620 KB Output is correct
13 Correct 123 ms 30036 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 74 ms 12036 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 7008 KB Output is correct
21 Correct 135 ms 25932 KB Output is correct
22 Correct 113 ms 27728 KB Output is correct
23 Correct 112 ms 25936 KB Output is correct
24 Correct 120 ms 29904 KB Output is correct
25 Correct 60 ms 12368 KB Output is correct
26 Correct 58 ms 12884 KB Output is correct
27 Correct 132 ms 26192 KB Output is correct
28 Correct 127 ms 29780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 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 5 ms 1616 KB Output is correct
9 Correct 125 ms 30224 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 9 ms 1372 KB Output is correct
13 Correct 154 ms 26136 KB Output is correct
14 Incorrect 1 ms 344 KB Answer gives possible 1 while actual possible 0
15 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 29 ms 6840 KB Output is correct
5 Correct 124 ms 25936 KB Output is correct
6 Correct 117 ms 27672 KB Output is correct
7 Correct 125 ms 25940 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 32 ms 7004 KB Output is correct
10 Correct 124 ms 26192 KB Output is correct
11 Correct 122 ms 26964 KB Output is correct
12 Correct 126 ms 26124 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 30 ms 6892 KB Output is correct
17 Correct 120 ms 26196 KB Output is correct
18 Correct 125 ms 25940 KB Output is correct
19 Correct 116 ms 26196 KB Output is correct
20 Correct 125 ms 29980 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 5 ms 1372 KB Output is correct
7 Correct 123 ms 25944 KB Output is correct
8 Correct 1 ms 344 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 600 KB Output is correct
12 Correct 6 ms 1620 KB Output is correct
13 Correct 123 ms 30036 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 74 ms 12036 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 7008 KB Output is correct
21 Correct 135 ms 25932 KB Output is correct
22 Correct 113 ms 27728 KB Output is correct
23 Correct 112 ms 25936 KB Output is correct
24 Correct 120 ms 29904 KB Output is correct
25 Correct 60 ms 12368 KB Output is correct
26 Correct 58 ms 12884 KB Output is correct
27 Correct 132 ms 26192 KB Output is correct
28 Correct 127 ms 29780 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1616 KB Output is correct
37 Correct 125 ms 30224 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 9 ms 1372 KB Output is correct
41 Correct 154 ms 26136 KB Output is correct
42 Incorrect 1 ms 344 KB Answer gives possible 1 while actual possible 0
43 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 5 ms 1372 KB Output is correct
7 Correct 123 ms 25944 KB Output is correct
8 Correct 1 ms 344 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 600 KB Output is correct
12 Correct 6 ms 1620 KB Output is correct
13 Correct 123 ms 30036 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 74 ms 12036 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 7008 KB Output is correct
21 Correct 135 ms 25932 KB Output is correct
22 Correct 113 ms 27728 KB Output is correct
23 Correct 112 ms 25936 KB Output is correct
24 Correct 120 ms 29904 KB Output is correct
25 Correct 60 ms 12368 KB Output is correct
26 Correct 58 ms 12884 KB Output is correct
27 Correct 132 ms 26192 KB Output is correct
28 Correct 127 ms 29780 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1616 KB Output is correct
37 Correct 125 ms 30224 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 9 ms 1372 KB Output is correct
41 Correct 154 ms 26136 KB Output is correct
42 Incorrect 1 ms 344 KB Answer gives possible 1 while actual possible 0
43 Halted 0 ms 0 KB -