Submission #301651

# Submission time Handle Problem Language Result Execution time Memory
301651 2020-09-18T05:43:02 Z Trickster Connecting Supertrees (IOI20_supertrees) C++14
21 / 100
316 ms 26236 KB
#include "supertrees.h"
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define N 1010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <int, int>
#define sz(a) int(a.size())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;}

int vis[N];
int arr[N][N];
int P[N], sz[N];

int ata(int x)
{
	if(x == P[x]) return x;

	return P[x] = ata(P[x]);
}

void uni(int a, int b, int tp)
{
	a = ata(a);
	b = ata(b);

	if(a == b) return;

	if(sz[a] < sz[b]) swap(a, b);

	P[b] = a, sz[a] += sz[b], sz[b] = 0;
	arr[a][b] = arr[b][a] = tp;
}

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

	for(int i = 0; i < n; i++) P[i] = i, sz[i] = 1;

	for(int i = 0; i < n; i++)
		for(int h = 0; h < n; h++) {
			if(i == h) continue;
			
			if(p[i][h] == 1) uni(i, h, 1);

			if(p[i][h] == 3) return 0;
		}
	
	for(int i = 0; i < n; i++)
		for(int h = 0; h < n; h++)
			if(p[i][h] != 1 && ata(i) == ata(h)) return 0; 

	for(int i = 0; i < n; i++)
		for(int h = 0; h < n; h++)
			if(p[i][h] == 2) uni(i, h, 0);
	
	vector <int> E[N];
	for(int i = 0; i < n; i++) E[ata(i)].pb(i);

	for(int i = 0; i < n; i++)
		for(int h = 0; h < n; h++)
			if(p[i][h] == 2) {
				if(sz[ata(i)] == 2) return 0;
				
				if(vis[ata(i)]) continue;
				vis[ata(i)] = 1;

				int last = -1;
				for(auto j: E[ata(i)]) {
					if(last != -1) arr[last][j] = arr[j][last] = 1;
					last = j;
				}
				arr[last][E[ata(i)][0]] = arr[E[ata(i)][0]][last] = 1;
			}

	vector <vector <int>> ret;
	ret.resize(n);
	for(int i = 0; i < n; i++)
		for(int h = 0; h < n; h++)
			ret[i].pb(arr[i][h]);
	
	build(ret);
	return 1;
}

Compilation message

supertrees.cpp:23: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
   23 | #pragma GCC optimization ("O3")
      | 
supertrees.cpp:24: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
   24 | #pragma GCC optimization ("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 2048 KB Output is correct
7 Correct 254 ms 26208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 2048 KB Output is correct
7 Correct 254 ms 26208 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 241 ms 22296 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1408 KB Output is correct
17 Correct 117 ms 12152 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 67 ms 7648 KB Output is correct
21 Correct 263 ms 26236 KB Output is correct
22 Correct 253 ms 25852 KB Output is correct
23 Correct 267 ms 26104 KB Output is correct
24 Correct 236 ms 22440 KB Output is correct
25 Correct 104 ms 12152 KB Output is correct
26 Correct 107 ms 11640 KB Output is correct
27 Correct 267 ms 26104 KB Output is correct
28 Correct 242 ms 22520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 392 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 13 ms 1280 KB Output is correct
9 Correct 270 ms 22264 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 12 ms 2080 KB Output is correct
13 Correct 316 ms 26104 KB Output is correct
14 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 64 ms 7672 KB Output is correct
5 Correct 254 ms 26232 KB Output is correct
6 Correct 246 ms 25728 KB Output is correct
7 Correct 271 ms 26172 KB Output is correct
8 Correct 1 ms 416 KB Output is correct
9 Correct 62 ms 7672 KB Output is correct
10 Correct 249 ms 26236 KB Output is correct
11 Correct 249 ms 26208 KB Output is correct
12 Correct 294 ms 26216 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Incorrect 1 ms 512 KB Too many ways to get from 0 to 4, should be 1 found no less than 2
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 2048 KB Output is correct
7 Correct 254 ms 26208 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 241 ms 22296 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1408 KB Output is correct
17 Correct 117 ms 12152 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 67 ms 7648 KB Output is correct
21 Correct 263 ms 26236 KB Output is correct
22 Correct 253 ms 25852 KB Output is correct
23 Correct 267 ms 26104 KB Output is correct
24 Correct 236 ms 22440 KB Output is correct
25 Correct 104 ms 12152 KB Output is correct
26 Correct 107 ms 11640 KB Output is correct
27 Correct 267 ms 26104 KB Output is correct
28 Correct 242 ms 22520 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 392 KB Output is correct
33 Correct 1 ms 416 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 13 ms 1280 KB Output is correct
37 Correct 270 ms 22264 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 12 ms 2080 KB Output is correct
41 Correct 316 ms 26104 KB Output is correct
42 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 2048 KB Output is correct
7 Correct 254 ms 26208 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 241 ms 22296 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1408 KB Output is correct
17 Correct 117 ms 12152 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 67 ms 7648 KB Output is correct
21 Correct 263 ms 26236 KB Output is correct
22 Correct 253 ms 25852 KB Output is correct
23 Correct 267 ms 26104 KB Output is correct
24 Correct 236 ms 22440 KB Output is correct
25 Correct 104 ms 12152 KB Output is correct
26 Correct 107 ms 11640 KB Output is correct
27 Correct 267 ms 26104 KB Output is correct
28 Correct 242 ms 22520 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 392 KB Output is correct
33 Correct 1 ms 416 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 13 ms 1280 KB Output is correct
37 Correct 270 ms 22264 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 12 ms 2080 KB Output is correct
41 Correct 316 ms 26104 KB Output is correct
42 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
43 Halted 0 ms 0 KB -