Submission #74338

# Submission time Handle Problem Language Result Execution time Memory
74338 2018-08-31T10:49:34 Z khsoo01 Key of Impassable Doors (FXCUP3_key) C++11
100 / 100
112 ms 5068 KB
#include "key.h"
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
 
typedef pair<int,int> pii;
 
const int N = 1005;
 
int n, par[N], cyc[N], cs[N], cc;
pii ord[N];
 
bool vis[N];
 
vector<int> ci[N];
 
int dfs (int I) {
	if(vis[I]) return 0;
	if(cyc[I]) {
		for(auto &T : ci[cyc[I]]) {
			vis[T] = true;
		}
		return cs[cyc[I]];
	}
	else {
		vis[I] = true;
		return dfs(par[I]) + 1;
	}
}
 
int Try (vector<int> &V) {
	fill(vis+1, vis+1+n, false);
	int R = 0;
	for(auto &T : V) {
		R += dfs(T);
	}
	return R;
}
 
void EnsureKeyInfo(int _N) {
	n = _N;
	for(int i=1;i<=n;i++) {
		TakeKey(i);
		int T = Explore();
		ord[i] = {T, i};
	}
	sort(ord+1, ord+1+n);
	for(int i=1;i<=n;i++) {
		if(ord[i].X == 1) {
			cyc[ord[i].Y] = ++cc;
			cs[cc] = 1;
			ci[cc].push_back(ord[i].Y);
			continue;
		}
		int S = 1, E = i;
		bool inc = false;
		while(S<E) {
			int M = (S+E)/2;
			vector<int> V;
			for(int j=1;j<=M;j++) {
				V.push_back(ord[j].Y);
				TakeKey(ord[j].Y);
			}
			TakeKey(ord[i].Y);
			int A = Try(V), B = Explore();
			if(B - A == 0) inc = true;
			if(B - A <= 1) E = M;
			else S = M+1;
		}
		if(S == i) {
			cyc[ord[i].Y] = ++cc;
			cs[cc] = ord[i].X;
			ci[cc].push_back(ord[i].Y);
			continue;
		}
		else if(inc) {
			cyc[ord[i].Y] = cyc[ord[S].Y];
			ci[cyc[ord[S].Y]].push_back(ord[i].Y);
		}
		else par[ord[i].Y] = ord[S].Y;
	}
	for(int i=1;i<=n;i++) {
		fill(vis+1, vis+1+n, false);
		dfs(i);
		for(int j=1;j<=n;j++) {
			if(vis[j]) Report(i, j);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 2 ms 816 KB Output is correct
4 Correct 3 ms 816 KB Output is correct
5 Correct 3 ms 816 KB Output is correct
6 Correct 3 ms 816 KB Output is correct
7 Correct 3 ms 1020 KB Output is correct
8 Correct 3 ms 1040 KB Output is correct
9 Correct 3 ms 1040 KB Output is correct
10 Correct 3 ms 1040 KB Output is correct
11 Correct 3 ms 1040 KB Output is correct
12 Correct 3 ms 1044 KB Output is correct
13 Correct 2 ms 1048 KB Output is correct
14 Correct 3 ms 1112 KB Output is correct
15 Correct 3 ms 1180 KB Output is correct
16 Correct 3 ms 1180 KB Output is correct
17 Correct 3 ms 1180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 2 ms 816 KB Output is correct
4 Correct 3 ms 816 KB Output is correct
5 Correct 3 ms 816 KB Output is correct
6 Correct 3 ms 816 KB Output is correct
7 Correct 3 ms 1020 KB Output is correct
8 Correct 3 ms 1040 KB Output is correct
9 Correct 3 ms 1040 KB Output is correct
10 Correct 3 ms 1040 KB Output is correct
11 Correct 3 ms 1040 KB Output is correct
12 Correct 3 ms 1044 KB Output is correct
13 Correct 2 ms 1048 KB Output is correct
14 Correct 3 ms 1112 KB Output is correct
15 Correct 3 ms 1180 KB Output is correct
16 Correct 3 ms 1180 KB Output is correct
17 Correct 3 ms 1180 KB Output is correct
18 Correct 11 ms 2108 KB Output is correct
19 Correct 8 ms 2108 KB Output is correct
20 Correct 9 ms 2108 KB Output is correct
21 Correct 7 ms 2108 KB Output is correct
22 Correct 12 ms 2108 KB Output is correct
23 Correct 22 ms 2644 KB Output is correct
24 Correct 24 ms 2776 KB Output is correct
25 Correct 17 ms 2776 KB Output is correct
26 Correct 15 ms 2776 KB Output is correct
27 Correct 16 ms 2776 KB Output is correct
28 Correct 20 ms 2776 KB Output is correct
29 Correct 14 ms 2776 KB Output is correct
30 Correct 34 ms 2776 KB Output is correct
31 Correct 22 ms 2776 KB Output is correct
32 Correct 23 ms 2840 KB Output is correct
33 Correct 24 ms 2840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 2 ms 816 KB Output is correct
4 Correct 3 ms 816 KB Output is correct
5 Correct 3 ms 816 KB Output is correct
6 Correct 3 ms 816 KB Output is correct
7 Correct 3 ms 1020 KB Output is correct
8 Correct 3 ms 1040 KB Output is correct
9 Correct 3 ms 1040 KB Output is correct
10 Correct 3 ms 1040 KB Output is correct
11 Correct 3 ms 1040 KB Output is correct
12 Correct 3 ms 1044 KB Output is correct
13 Correct 2 ms 1048 KB Output is correct
14 Correct 3 ms 1112 KB Output is correct
15 Correct 3 ms 1180 KB Output is correct
16 Correct 3 ms 1180 KB Output is correct
17 Correct 3 ms 1180 KB Output is correct
18 Correct 11 ms 2108 KB Output is correct
19 Correct 8 ms 2108 KB Output is correct
20 Correct 9 ms 2108 KB Output is correct
21 Correct 7 ms 2108 KB Output is correct
22 Correct 12 ms 2108 KB Output is correct
23 Correct 22 ms 2644 KB Output is correct
24 Correct 24 ms 2776 KB Output is correct
25 Correct 17 ms 2776 KB Output is correct
26 Correct 15 ms 2776 KB Output is correct
27 Correct 16 ms 2776 KB Output is correct
28 Correct 20 ms 2776 KB Output is correct
29 Correct 14 ms 2776 KB Output is correct
30 Correct 34 ms 2776 KB Output is correct
31 Correct 22 ms 2776 KB Output is correct
32 Correct 23 ms 2840 KB Output is correct
33 Correct 24 ms 2840 KB Output is correct
34 Correct 65 ms 4244 KB Output is correct
35 Correct 48 ms 4360 KB Output is correct
36 Correct 53 ms 4360 KB Output is correct
37 Correct 30 ms 4360 KB Output is correct
38 Correct 76 ms 4360 KB Output is correct
39 Correct 95 ms 4808 KB Output is correct
40 Correct 93 ms 4832 KB Output is correct
41 Correct 65 ms 4884 KB Output is correct
42 Correct 56 ms 4992 KB Output is correct
43 Correct 51 ms 4992 KB Output is correct
44 Correct 68 ms 4992 KB Output is correct
45 Correct 38 ms 4992 KB Output is correct
46 Correct 102 ms 5024 KB Output is correct
47 Correct 112 ms 5068 KB Output is correct
48 Correct 92 ms 5068 KB Output is correct
49 Correct 103 ms 5068 KB Output is correct