#include "key.h"
#include <stdio.h>
int dir[1005];
int count[1005][1005]; // [i][j]: i개 들어갈수있는 j번째 방
int countIdx[1005]; // i개 들어갈수있는 방의 갯수
int maxCount; // 가장 많이 들어갈수있는 방의 수
int report[1005][1005];
void EnsureKeyInfo(int N) {
for(int i = 0; i<= N; i++) {
dir[i] = -1;
countIdx[i] = 0;
for(int j =0; j<= N; j++) {
report[i][j] = 0;
}
}
maxCount = 0;
for(int i = 1; i <= N; i++) {
TakeKey(i);
int cnt = Explore();
count[cnt][countIdx[cnt]] = i;
countIdx[cnt]++;
if(cnt > maxCount) maxCount = cnt;
}
// printf("%d\n", maxCount);
for(int i = 2; i <= maxCount; i++) {
int with[1005] = {0,};
int withCnt = 0;
for(int j = 0; j < countIdx[i]; j++) {
int now = count[i][j];
if(dir[now] != -1) continue;
int low = 0;
int high = countIdx[i-1];
int mid = (low + high) / 2;
int flag = 0;
{
int visit[1005] = {0,};
int cnt = 0;
TakeKey(now);
for(int j = low; j < high; j++) {
int room = count[i-1][j];
TakeKey(room);
while(room != -1) {
if(visit[room] == 0) {
visit[room] = 1;
cnt++;
} else {
break;
}
room = dir[room];
}
}
int r = Explore();
if( r == cnt+1) {
flag = 1;
}
}
if(flag) {
while(low != mid) {
int visit[1005] = {0,};
int cnt = 0;
TakeKey(now);
for(int j = low; j < mid; j++) {
int room = count[i-1][j];
TakeKey(room);
while(room != -1) {
if(visit[room] == 0) {
visit[room] = 1;
cnt++;
} else {
break;
}
room = dir[room];
}
}
int r = Explore();
if( r == cnt+1) {
high = mid;
mid = (low + high) / 2;
} else {
low = mid;
mid = (low + high) / 2;
}
}
dir[now] = count[i-1][low];
continue;
} else {
with[withCnt++] = now;
}
}
// for(int j= 0; j< withCnt; j++) printf("%d ", with[j]);
int head[1005];
int headCnt = 0;
for(int j = 0; j < withCnt; j++) {
// printf("%d ", headCnt);
int now = with[j];
if(headCnt == 0) head[headCnt++] = now;
else {
int low = 0;
int high = headCnt;
int mid = (low + high) / 2;
int cnt = 0;
{
TakeKey(now);
for(int k = low; k < high; k++) {
TakeKey(head[k]);
cnt += i;
}
int r = Explore();
if(r != cnt) {
head[headCnt++] = now;
continue;
}
}
// printf("this");
while(low != mid) {
cnt = 0;
TakeKey(now);
for(int k = low; k < mid; k++) {
TakeKey(head[k]);
cnt += i;
}
int r = Explore();
// printf("%d %d %d %d %d\n", now, cnt, r, low, high);
if(r == cnt) {
high = mid;
mid = (low + high) / 2;
} else {
low = mid;
mid = (low + high) / 2;
}
}
// printf("this");
dir[now] = dir[head[low]];
if(dir[now] == -1) dir[now] = head[low];
dir[head[low]] = now;
// printf("%d %d %d %d\n", now, dir[now], head[low], dir[head[low]]);
}
}
// for(int j =0; j < headCnt; j++) printf("%d ", head[j]);
// printf("\n");
}
for(int i = 1; i <= N; i++) {
int room = i;
while(room != -1 && report[i][room] == 0) {
// printf("%d %d\n", i, room);
Report(i, room);
report[i][room] = 1;
room = dir[room];
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
1004 KB |
Output is correct |
3 |
Correct |
1 ms |
876 KB |
Output is correct |
4 |
Correct |
1 ms |
896 KB |
Output is correct |
5 |
Correct |
1 ms |
876 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
7 |
Correct |
1 ms |
1260 KB |
Output is correct |
8 |
Correct |
1 ms |
1260 KB |
Output is correct |
9 |
Correct |
1 ms |
1132 KB |
Output is correct |
10 |
Correct |
1 ms |
1132 KB |
Output is correct |
11 |
Correct |
1 ms |
1132 KB |
Output is correct |
12 |
Correct |
1 ms |
1132 KB |
Output is correct |
13 |
Correct |
1 ms |
1132 KB |
Output is correct |
14 |
Correct |
1 ms |
1260 KB |
Output is correct |
15 |
Correct |
1 ms |
1260 KB |
Output is correct |
16 |
Correct |
1 ms |
1132 KB |
Output is correct |
17 |
Correct |
2 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
1004 KB |
Output is correct |
3 |
Correct |
1 ms |
876 KB |
Output is correct |
4 |
Correct |
1 ms |
896 KB |
Output is correct |
5 |
Correct |
1 ms |
876 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
7 |
Correct |
1 ms |
1260 KB |
Output is correct |
8 |
Correct |
1 ms |
1260 KB |
Output is correct |
9 |
Correct |
1 ms |
1132 KB |
Output is correct |
10 |
Correct |
1 ms |
1132 KB |
Output is correct |
11 |
Correct |
1 ms |
1132 KB |
Output is correct |
12 |
Correct |
1 ms |
1132 KB |
Output is correct |
13 |
Correct |
1 ms |
1132 KB |
Output is correct |
14 |
Correct |
1 ms |
1260 KB |
Output is correct |
15 |
Correct |
1 ms |
1260 KB |
Output is correct |
16 |
Correct |
1 ms |
1132 KB |
Output is correct |
17 |
Correct |
2 ms |
1408 KB |
Output is correct |
18 |
Correct |
3 ms |
3052 KB |
Output is correct |
19 |
Correct |
4 ms |
2924 KB |
Output is correct |
20 |
Correct |
4 ms |
2924 KB |
Output is correct |
21 |
Correct |
4 ms |
3052 KB |
Output is correct |
22 |
Correct |
3 ms |
3564 KB |
Output is correct |
23 |
Correct |
6 ms |
4460 KB |
Output is correct |
24 |
Correct |
6 ms |
4460 KB |
Output is correct |
25 |
Correct |
7 ms |
4332 KB |
Output is correct |
26 |
Correct |
6 ms |
4332 KB |
Output is correct |
27 |
Correct |
6 ms |
4460 KB |
Output is correct |
28 |
Correct |
5 ms |
4332 KB |
Output is correct |
29 |
Correct |
5 ms |
4352 KB |
Output is correct |
30 |
Correct |
6 ms |
4332 KB |
Output is correct |
31 |
Correct |
6 ms |
4352 KB |
Output is correct |
32 |
Correct |
7 ms |
4460 KB |
Output is correct |
33 |
Correct |
6 ms |
5228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
1004 KB |
Output is correct |
3 |
Correct |
1 ms |
876 KB |
Output is correct |
4 |
Correct |
1 ms |
896 KB |
Output is correct |
5 |
Correct |
1 ms |
876 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
7 |
Correct |
1 ms |
1260 KB |
Output is correct |
8 |
Correct |
1 ms |
1260 KB |
Output is correct |
9 |
Correct |
1 ms |
1132 KB |
Output is correct |
10 |
Correct |
1 ms |
1132 KB |
Output is correct |
11 |
Correct |
1 ms |
1132 KB |
Output is correct |
12 |
Correct |
1 ms |
1132 KB |
Output is correct |
13 |
Correct |
1 ms |
1132 KB |
Output is correct |
14 |
Correct |
1 ms |
1260 KB |
Output is correct |
15 |
Correct |
1 ms |
1260 KB |
Output is correct |
16 |
Correct |
1 ms |
1132 KB |
Output is correct |
17 |
Correct |
2 ms |
1408 KB |
Output is correct |
18 |
Correct |
3 ms |
3052 KB |
Output is correct |
19 |
Correct |
4 ms |
2924 KB |
Output is correct |
20 |
Correct |
4 ms |
2924 KB |
Output is correct |
21 |
Correct |
4 ms |
3052 KB |
Output is correct |
22 |
Correct |
3 ms |
3564 KB |
Output is correct |
23 |
Correct |
6 ms |
4460 KB |
Output is correct |
24 |
Correct |
6 ms |
4460 KB |
Output is correct |
25 |
Correct |
7 ms |
4332 KB |
Output is correct |
26 |
Correct |
6 ms |
4332 KB |
Output is correct |
27 |
Correct |
6 ms |
4460 KB |
Output is correct |
28 |
Correct |
5 ms |
4332 KB |
Output is correct |
29 |
Correct |
5 ms |
4352 KB |
Output is correct |
30 |
Correct |
6 ms |
4332 KB |
Output is correct |
31 |
Correct |
6 ms |
4352 KB |
Output is correct |
32 |
Correct |
7 ms |
4460 KB |
Output is correct |
33 |
Correct |
6 ms |
5228 KB |
Output is correct |
34 |
Correct |
14 ms |
7404 KB |
Output is correct |
35 |
Correct |
18 ms |
7148 KB |
Output is correct |
36 |
Correct |
13 ms |
7148 KB |
Output is correct |
37 |
Correct |
12 ms |
7148 KB |
Output is correct |
38 |
Correct |
14 ms |
8812 KB |
Output is correct |
39 |
Correct |
18 ms |
8428 KB |
Output is correct |
40 |
Correct |
19 ms |
8428 KB |
Output is correct |
41 |
Correct |
23 ms |
8300 KB |
Output is correct |
42 |
Correct |
20 ms |
8300 KB |
Output is correct |
43 |
Correct |
22 ms |
8300 KB |
Output is correct |
44 |
Correct |
17 ms |
8300 KB |
Output is correct |
45 |
Correct |
16 ms |
8300 KB |
Output is correct |
46 |
Correct |
19 ms |
8300 KB |
Output is correct |
47 |
Correct |
19 ms |
8428 KB |
Output is correct |
48 |
Correct |
17 ms |
8428 KB |
Output is correct |
49 |
Correct |
18 ms |
10220 KB |
Output is correct |