답안 #832196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832196 2023-08-21T06:31:44 Z penguinman 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
160 ms 24008 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;

#define ln "\n"
#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define pb emplace_back
#define mp std::make_pair
#define mtp std::make_tuple
#define all(a) a.begin(),a.end()

int construct(std::vector<std::vector<int>> p) {
	int N = p.size();
	vector<vector<int>> ans(N, vector<int>(N));
	vector<bool> flag(N);
	auto tree = [&](vi v){
		rep(i,1,v.size()){
			ans[v[i-1]][v[i]] = ans[v[i]][v[i-1]] = 1;
		}
		rep(i,0,v.size()){
			rep(j,i+1,v.size()){
				if(p[v[i]][v[j]] != 1) return true;
			}
		}
		return false;
	};
	auto loop = [&](vi v){
		if(v.size() == 2) return true;
		rep(i,0,v.size()){
			ans[v[(i+1)%v.size()]][v[i]] = ans[v[i]][v[(i+1)%v.size()]] = 1;
		}
		rep(i,0,v.size()){
			rep(j,i+1,v.size()){
				if(p[v[i]][v[j]] != 2) return true;
			}
		}
		return false;
	};
	rep(i,0,N){
		if(flag[i]) continue;
		flag[i] = true;
		std::queue<ll> que;
		que.push(i);
		vi v;
		while(!que.empty()){
			ll now = que.front(); que.pop();
			v.pb(now);
			rep(next, 0, N){
				if(p[now][next]){
					if(!flag[next]){
						flag[next] = true;
						que.push(next);
					}
				}
			}
		}
		vi cnt(4);
		for(auto el: v){
			rep(j,0,N){
				cnt[p[el][j]]++;
			}
		}
		if(cnt[2] == 0){
			if(tree(v)) return 0;
			continue;
		}
		if(cnt[1] == 0){
			if(loop(v)) return 0;
			continue;
		}
	}
	build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 7 ms 1184 KB Output is correct
7 Correct 153 ms 23932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 7 ms 1184 KB Output is correct
7 Correct 153 ms 23932 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 216 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 7 ms 1204 KB Output is correct
13 Correct 153 ms 23940 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 852 KB Output is correct
17 Correct 71 ms 14096 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 296 KB Output is correct
20 Correct 39 ms 6196 KB Output is correct
21 Correct 152 ms 23932 KB Output is correct
22 Correct 151 ms 24008 KB Output is correct
23 Correct 154 ms 23972 KB Output is correct
24 Correct 156 ms 24000 KB Output is correct
25 Correct 62 ms 14076 KB Output is correct
26 Correct 59 ms 14068 KB Output is correct
27 Correct 154 ms 24000 KB Output is correct
28 Correct 160 ms 23984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 304 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 1 ms 212 KB Too few ways to get from 0 to 1, should be 2 found 0
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 7 ms 1184 KB Output is correct
7 Correct 153 ms 23932 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 216 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 7 ms 1204 KB Output is correct
13 Correct 153 ms 23940 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 852 KB Output is correct
17 Correct 71 ms 14096 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 296 KB Output is correct
20 Correct 39 ms 6196 KB Output is correct
21 Correct 152 ms 23932 KB Output is correct
22 Correct 151 ms 24008 KB Output is correct
23 Correct 154 ms 23972 KB Output is correct
24 Correct 156 ms 24000 KB Output is correct
25 Correct 62 ms 14076 KB Output is correct
26 Correct 59 ms 14068 KB Output is correct
27 Correct 154 ms 24000 KB Output is correct
28 Correct 160 ms 23984 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 300 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 1 ms 304 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 7 ms 1184 KB Output is correct
7 Correct 153 ms 23932 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 216 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 7 ms 1204 KB Output is correct
13 Correct 153 ms 23940 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 852 KB Output is correct
17 Correct 71 ms 14096 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 296 KB Output is correct
20 Correct 39 ms 6196 KB Output is correct
21 Correct 152 ms 23932 KB Output is correct
22 Correct 151 ms 24008 KB Output is correct
23 Correct 154 ms 23972 KB Output is correct
24 Correct 156 ms 24000 KB Output is correct
25 Correct 62 ms 14076 KB Output is correct
26 Correct 59 ms 14068 KB Output is correct
27 Correct 154 ms 24000 KB Output is correct
28 Correct 160 ms 23984 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 300 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 1 ms 304 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -