Submission #65395

# Submission time Handle Problem Language Result Execution time Memory
65395 2018-08-07T13:50:10 Z imsifile Key of Impassable Doors (FXCUP3_key) C++
100 / 100
44 ms 4700 KB
#include "key.h"
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int NN, ba[1010], self[1010], par[1010], ccn, ld[1010];
// par[i] = -x (i is in cycle x), ld[x] = leader of cycle x
vector<int> lds[1010]; // lds[i] : leaders that ba[x]=i

int chk[1010], sum;
void TakeKey2(int K){
	while(1){
		if(par[K]<0) K=par[K];
		if(K<0){
			K=ld[-K];
			if(!chk[K]) chk[K]=1, sum+=self[K];
			break;
		}
		if(chk[K]) break;
		chk[K]=1, sum++;
		K=par[K];
	}
}

int ExploreKey(vector<int> &v, int s, int e, int pl){
	if(pl){
		TakeKey(pl);
		for(int i=s; i<=e; i++){
			if(v[i]<0) TakeKey(ld[-v[i]]);
			else TakeKey(v[i]);
		}
		return Explore();
	}
	sum=0;
	for(int i=1; i<=NN; i++) chk[i]=0;
	for(int i=s; i<=e; i++) TakeKey2(v[i]);
	return sum;
}

int cmp(const int &x, const int &y){
	return self[x] < self[y];
}

int para(int ix, vector<int> &v){
	int mi=0, mx=v.size(), md;
	v.push_back(0);
	while(1){
		md = (mi+mx)/2;
		if(mi==mx) break;
		if(ExploreKey(v, mi, md, ix) <= ExploreKey(v, mi, md, 0)+1) mx=md;
		else mi=md+1;
	}
	md = v[md];
	v.pop_back();
	return md;
}

void EnsureKeyInfo(int N) {
	NN = N;
	for(int i=1; i<=N; i++){
		TakeKey(i);
		self[i]=Explore();
	}
	for(int i=0; i<N; i++) ba[i]=i+1;
	sort(ba, ba+N, cmp);
	for(int t=0; t<N; t++){
		int i=ba[t];
		par[i]=para(i, lds[self[i]-1]);
		if(par[i]<=0){
			if(par[i]==0){
				par[i]=-(++ccn), ld[ccn]=i;
				if(self[i]>1) lds[self[i]-1].push_back(-ccn);
				lds[self[i]].push_back(i);
			}
		}
		else lds[self[i]].push_back(i);
	}
	for(int i=1; i<=N; i++){
		int t=i;
		for(; par[t]>0; t=par[t]) Report(i, t);
		for(int j=1; j<=N; j++){
			if(par[t] == par[j]) Report(i, j);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 740 KB Output is correct
3 Correct 2 ms 816 KB Output is correct
4 Correct 2 ms 892 KB Output is correct
5 Correct 2 ms 892 KB Output is correct
6 Correct 2 ms 892 KB Output is correct
7 Correct 3 ms 952 KB Output is correct
8 Correct 4 ms 956 KB Output is correct
9 Correct 4 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 1040 KB Output is correct
13 Correct 3 ms 1040 KB Output is correct
14 Correct 3 ms 1040 KB Output is correct
15 Correct 3 ms 1040 KB Output is correct
16 Correct 4 ms 1040 KB Output is correct
17 Correct 3 ms 1040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 740 KB Output is correct
3 Correct 2 ms 816 KB Output is correct
4 Correct 2 ms 892 KB Output is correct
5 Correct 2 ms 892 KB Output is correct
6 Correct 2 ms 892 KB Output is correct
7 Correct 3 ms 952 KB Output is correct
8 Correct 4 ms 956 KB Output is correct
9 Correct 4 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 1040 KB Output is correct
13 Correct 3 ms 1040 KB Output is correct
14 Correct 3 ms 1040 KB Output is correct
15 Correct 3 ms 1040 KB Output is correct
16 Correct 4 ms 1040 KB Output is correct
17 Correct 3 ms 1040 KB Output is correct
18 Correct 6 ms 1904 KB Output is correct
19 Correct 5 ms 1904 KB Output is correct
20 Correct 5 ms 1904 KB Output is correct
21 Correct 5 ms 1904 KB Output is correct
22 Correct 4 ms 1984 KB Output is correct
23 Correct 10 ms 2540 KB Output is correct
24 Correct 7 ms 2540 KB Output is correct
25 Correct 9 ms 2540 KB Output is correct
26 Correct 10 ms 2540 KB Output is correct
27 Correct 10 ms 2540 KB Output is correct
28 Correct 11 ms 2540 KB Output is correct
29 Correct 8 ms 2540 KB Output is correct
30 Correct 8 ms 2540 KB Output is correct
31 Correct 7 ms 2540 KB Output is correct
32 Correct 9 ms 2540 KB Output is correct
33 Correct 8 ms 2544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 740 KB Output is correct
3 Correct 2 ms 816 KB Output is correct
4 Correct 2 ms 892 KB Output is correct
5 Correct 2 ms 892 KB Output is correct
6 Correct 2 ms 892 KB Output is correct
7 Correct 3 ms 952 KB Output is correct
8 Correct 4 ms 956 KB Output is correct
9 Correct 4 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 1040 KB Output is correct
13 Correct 3 ms 1040 KB Output is correct
14 Correct 3 ms 1040 KB Output is correct
15 Correct 3 ms 1040 KB Output is correct
16 Correct 4 ms 1040 KB Output is correct
17 Correct 3 ms 1040 KB Output is correct
18 Correct 6 ms 1904 KB Output is correct
19 Correct 5 ms 1904 KB Output is correct
20 Correct 5 ms 1904 KB Output is correct
21 Correct 5 ms 1904 KB Output is correct
22 Correct 4 ms 1984 KB Output is correct
23 Correct 10 ms 2540 KB Output is correct
24 Correct 7 ms 2540 KB Output is correct
25 Correct 9 ms 2540 KB Output is correct
26 Correct 10 ms 2540 KB Output is correct
27 Correct 10 ms 2540 KB Output is correct
28 Correct 11 ms 2540 KB Output is correct
29 Correct 8 ms 2540 KB Output is correct
30 Correct 8 ms 2540 KB Output is correct
31 Correct 7 ms 2540 KB Output is correct
32 Correct 9 ms 2540 KB Output is correct
33 Correct 8 ms 2544 KB Output is correct
34 Correct 17 ms 4076 KB Output is correct
35 Correct 18 ms 4076 KB Output is correct
36 Correct 23 ms 4076 KB Output is correct
37 Correct 18 ms 4076 KB Output is correct
38 Correct 15 ms 4196 KB Output is correct
39 Correct 23 ms 4588 KB Output is correct
40 Correct 24 ms 4588 KB Output is correct
41 Correct 23 ms 4588 KB Output is correct
42 Correct 21 ms 4588 KB Output is correct
43 Correct 30 ms 4700 KB Output is correct
44 Correct 44 ms 4700 KB Output is correct
45 Correct 30 ms 4700 KB Output is correct
46 Correct 24 ms 4700 KB Output is correct
47 Correct 26 ms 4700 KB Output is correct
48 Correct 19 ms 4700 KB Output is correct
49 Correct 19 ms 4700 KB Output is correct