Submission #72894

# Submission time Handle Problem Language Result Execution time Memory
72894 2018-08-27T07:45:15 Z ainta Key of Impassable Doors (FXCUP3_key) C++17
100 / 100
39 ms 7172 KB
#include "key.h"
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>G[1010];
vector<int>U[1010], B[1010], V[1010];
 
int S[1010][1010], Nxt[1010], vis[1010], isU[1010];
 
int Num[1010], D[1010];
vector<int>T[1010];
 
void Go(int i, int x) {
	if (U[i].empty()) {
		U[i].push_back(x);
		return;
	}
	int b = 1, e = U[i].size(), mid, r = 0, j;
	while (b <= e) {
		mid = (b + e) >> 1;
		for (j = 0; j < mid; j++) {
			TakeKey(U[i][j]);
		}
		TakeKey(x);
		if (Explore() == i * (mid + 1)) {
			r = mid;
			b = mid + 1;
		}
		else e = mid - 1;
	}
	if (r == U[i].size()) {
		U[i].push_back(x);
	}
	else {
		Num[x] = U[i][r];
	}
}
 
void TakeAll(int b, int e) {
	int i;
	for (i = b; i <= e; i++) {
		for (auto &x : V[i])TakeKey(x);
	}
}
 
void EnsureKeyInfo(int N) {
	int i, j, k;
	for (i = 1; i <= N; i++) {
		TakeKey(i);
		int t = Explore();
		G[t].push_back(i);
	}
	int Mn = -1;
	for (i = 1; i <= N; i++) {
		if (G[i].empty()) {
			D[i] = D[i - 1];
			continue;
		}
		if (Mn == -1) {
			Mn = i;
			for (auto &x : G[i]) {
				Go(i, x);
			}
		}
		else {
			for (auto &x : G[i]) {
				TakeAll(1, i - 1);
				TakeKey(x);
				if (Explore() == D[i - 1] + i) {
					Go(i, x);
					continue;
				}
 
				int b = 1, e = V[i - 1].size() - 1, r = V[i - 1].size(), mid;
				while (b <= e) {
					mid = (b + e) >> 1;
					TakeAll(1, i - 2);
					for (j = 0; j < mid; j++) {
						TakeKey(V[i - 1][j]);
					}
					TakeKey(x);
					int t = Explore();
					if (S[i - 1][mid] + 1 == t) {
						r = mid;
						e = mid - 1;
					}
					else b = mid + 1;
				}
 
				Nxt[x] = V[i - 1][r - 1];
				B[i].push_back(x);
			}
		}
		for (auto &x : U[i]) {
			V[i].push_back(x);
			isU[x] = 1;
		}
		for (auto &x : B[i])V[i].push_back(x);
		for (j = 0; j <= V[i].size(); j++) {
			if (j == 0) {
				if (Mn == i)S[i][j] = 0;
				else S[i][j] = D[i - 1];
				continue;
			}
			else {
				int x = V[i][j - 1];
				if (isU[x]) S[i][j] = S[i][j - 1] + i;
				else S[i][j] = S[i][j - 1] + 1;
			}
		}
		D[i] = S[i][V[i].size()];
	}
 
	for (i = 1; i <= N; i++)for (auto &x : U[i])Num[x] = x;
 
 
	for (i = 1; i <= N; i++) {
		if (Num[i]) {
			for (j = 1; j <= N; j++) {
				if (Num[j] == Num[i])Report(i, j);
			}
			continue;
		}
		else {
			for (j = 1; j <= N; j++)vis[j] = 0;
			int x = i;
			while (x) {
				vis[x] = 1;
				x = Nxt[x];
			}
			for (j = 1; j <= N; j++) {
				if (vis[j] || vis[Num[j]])Report(i, j);
			}
		}
 
	}
 
}

Compilation message

key.cpp: In function 'void Go(int, int)':
key.cpp:32:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (r == U[i].size()) {
      ~~^~~~~~~~~~~~~~
key.cpp: In function 'void EnsureKeyInfo(int)':
key.cpp:100:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (j = 0; j <= V[i].size(); j++) {
               ~~^~~~~~~~~~~~~~
key.cpp:48:12: warning: unused variable 'k' [-Wunused-variable]
  int i, j, k;
            ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 976 KB Output is correct
3 Correct 3 ms 976 KB Output is correct
4 Correct 3 ms 976 KB Output is correct
5 Correct 4 ms 976 KB Output is correct
6 Correct 3 ms 1044 KB Output is correct
7 Correct 4 ms 1100 KB Output is correct
8 Correct 3 ms 1232 KB Output is correct
9 Correct 3 ms 1232 KB Output is correct
10 Correct 3 ms 1264 KB Output is correct
11 Correct 3 ms 1372 KB Output is correct
12 Correct 3 ms 1372 KB Output is correct
13 Correct 3 ms 1372 KB Output is correct
14 Correct 4 ms 1388 KB Output is correct
15 Correct 4 ms 1412 KB Output is correct
16 Correct 3 ms 1416 KB Output is correct
17 Correct 4 ms 1436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 976 KB Output is correct
3 Correct 3 ms 976 KB Output is correct
4 Correct 3 ms 976 KB Output is correct
5 Correct 4 ms 976 KB Output is correct
6 Correct 3 ms 1044 KB Output is correct
7 Correct 4 ms 1100 KB Output is correct
8 Correct 3 ms 1232 KB Output is correct
9 Correct 3 ms 1232 KB Output is correct
10 Correct 3 ms 1264 KB Output is correct
11 Correct 3 ms 1372 KB Output is correct
12 Correct 3 ms 1372 KB Output is correct
13 Correct 3 ms 1372 KB Output is correct
14 Correct 4 ms 1388 KB Output is correct
15 Correct 4 ms 1412 KB Output is correct
16 Correct 3 ms 1416 KB Output is correct
17 Correct 4 ms 1436 KB Output is correct
18 Correct 8 ms 2336 KB Output is correct
19 Correct 5 ms 2336 KB Output is correct
20 Correct 8 ms 2336 KB Output is correct
21 Correct 8 ms 2336 KB Output is correct
22 Correct 7 ms 2868 KB Output is correct
23 Correct 11 ms 2996 KB Output is correct
24 Correct 12 ms 3128 KB Output is correct
25 Correct 8 ms 3128 KB Output is correct
26 Correct 9 ms 3128 KB Output is correct
27 Correct 10 ms 3128 KB Output is correct
28 Correct 12 ms 3128 KB Output is correct
29 Correct 13 ms 3128 KB Output is correct
30 Correct 12 ms 3128 KB Output is correct
31 Correct 11 ms 3128 KB Output is correct
32 Correct 16 ms 3128 KB Output is correct
33 Correct 9 ms 3936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 976 KB Output is correct
3 Correct 3 ms 976 KB Output is correct
4 Correct 3 ms 976 KB Output is correct
5 Correct 4 ms 976 KB Output is correct
6 Correct 3 ms 1044 KB Output is correct
7 Correct 4 ms 1100 KB Output is correct
8 Correct 3 ms 1232 KB Output is correct
9 Correct 3 ms 1232 KB Output is correct
10 Correct 3 ms 1264 KB Output is correct
11 Correct 3 ms 1372 KB Output is correct
12 Correct 3 ms 1372 KB Output is correct
13 Correct 3 ms 1372 KB Output is correct
14 Correct 4 ms 1388 KB Output is correct
15 Correct 4 ms 1412 KB Output is correct
16 Correct 3 ms 1416 KB Output is correct
17 Correct 4 ms 1436 KB Output is correct
18 Correct 8 ms 2336 KB Output is correct
19 Correct 5 ms 2336 KB Output is correct
20 Correct 8 ms 2336 KB Output is correct
21 Correct 8 ms 2336 KB Output is correct
22 Correct 7 ms 2868 KB Output is correct
23 Correct 11 ms 2996 KB Output is correct
24 Correct 12 ms 3128 KB Output is correct
25 Correct 8 ms 3128 KB Output is correct
26 Correct 9 ms 3128 KB Output is correct
27 Correct 10 ms 3128 KB Output is correct
28 Correct 12 ms 3128 KB Output is correct
29 Correct 13 ms 3128 KB Output is correct
30 Correct 12 ms 3128 KB Output is correct
31 Correct 11 ms 3128 KB Output is correct
32 Correct 16 ms 3128 KB Output is correct
33 Correct 9 ms 3936 KB Output is correct
34 Correct 24 ms 4576 KB Output is correct
35 Correct 15 ms 4576 KB Output is correct
36 Correct 28 ms 4576 KB Output is correct
37 Correct 25 ms 4576 KB Output is correct
38 Correct 21 ms 6196 KB Output is correct
39 Correct 35 ms 6196 KB Output is correct
40 Correct 36 ms 6196 KB Output is correct
41 Correct 21 ms 6196 KB Output is correct
42 Correct 24 ms 6196 KB Output is correct
43 Correct 30 ms 6196 KB Output is correct
44 Correct 39 ms 6196 KB Output is correct
45 Correct 36 ms 6196 KB Output is correct
46 Correct 39 ms 6196 KB Output is correct
47 Correct 36 ms 6196 KB Output is correct
48 Correct 35 ms 6196 KB Output is correct
49 Correct 30 ms 7172 KB Output is correct