# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
250934 |
2020-07-19T13:30:03 Z |
imeimi2000 |
Park (JOI17_park) |
C++17 |
|
545 ms |
788 KB |
#include "park.h"
#include <vector>
#include <cstdlib>
using namespace std;
static int n;
static int place[1400];
static int check[1400];
static vector<int> edge[1400];
static int alive[1400];
static int ord[1400];
static int rev[1400];
void init() {
for (int i = 0; i < n; ++i) place[i] = 0;
}
int imeAsk(int a, int b) {
if (a == b) exit(1);
if (a > b) swap(a, b);
return Ask(a, b, place);
}
int isConnected(int x) {
init();
for (int i = 0; i < n; ++i) if (check[i] == 1) place[i] = 1;
place[x] = 1;
return imeAsk(0, x);
}
int findNearNode(int x) {
int s = 1, e = n - 1;
while (s < e) {
int m = (s + e) / 2;
init();
for (int i = 0; i < n; ++i) if (check[i] == 1) place[i] = 1;
for (int i = 0; i <= m; ++i) if (check[i] != -1) place[i] = 1;
place[x] = 1;
if (imeAsk(0, x)) e = m;
else s = m + 1;
}
return s;
}
int tp;
void dfs(int x) {
ord[x] = tp++;
rev[ord[x]] = x;
for (int i : edge[x]) {
if (ord[i] != -1) continue;
if (alive[i]) dfs(i);
}
}
void del(int x) {
alive[x] = 0;
for (int i : edge[x]) {
if (alive[i]) del(i);
}
}
void findEdges(int x) {
for (int i = 0; i < n; ++i) alive[i] = (check[i] == 1);
for (int i = 0; i < n; ++i) {
while (alive[i]) {
for (int i = 0; i < n; ++i) ord[i] = -1, rev[i] = -1;
tp = 0;
dfs(i);
for (int i = 0; i < n; ++i) place[i] = (ord[i] != -1);
place[x] = 1;
if (!imeAsk(i, x)) {
del(i);
break;
}
int s = 0, e = tp - 1;
while (s < e) {
int m = (s + e) / 2;
init();
for (int i = 0; i <= m; ++i) place[rev[i]] = 1;
place[x] = 1;
if (imeAsk(i, x)) e = m;
else s = m + 1;
}
edge[rev[s]].push_back(x);
edge[x].push_back(rev[s]);
alive[rev[s]] = 0;
}
}
}
void solve(int x) {
if (check[x]) return;
check[x] = -1;
while (!isConnected(x)) {
int nxt = findNearNode(x);
solve(nxt);
}
findEdges(x);
check[x] = 1;
}
void Detect(int T, int N) {
n = N;
check[0] = 1;
for (int i = 1; i < n; ++i) solve(i);
for (int i = 0; i < n; ++i) {
for (int j : edge[i]) {
if (i < j) Answer(i, j);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
384 KB |
Output is correct |
3 |
Correct |
9 ms |
384 KB |
Output is correct |
4 |
Correct |
18 ms |
384 KB |
Output is correct |
5 |
Correct |
39 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
543 ms |
588 KB |
Output is correct |
2 |
Correct |
151 ms |
512 KB |
Output is correct |
3 |
Correct |
211 ms |
512 KB |
Output is correct |
4 |
Correct |
545 ms |
716 KB |
Output is correct |
5 |
Correct |
540 ms |
688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
284 ms |
788 KB |
Output is correct |
2 |
Correct |
295 ms |
632 KB |
Output is correct |
3 |
Correct |
286 ms |
512 KB |
Output is correct |
4 |
Correct |
272 ms |
632 KB |
Output is correct |
5 |
Correct |
319 ms |
512 KB |
Output is correct |
6 |
Correct |
303 ms |
672 KB |
Output is correct |
7 |
Correct |
277 ms |
632 KB |
Output is correct |
8 |
Correct |
298 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
504 KB |
Output is correct |
2 |
Correct |
344 ms |
512 KB |
Output is correct |
3 |
Correct |
347 ms |
764 KB |
Output is correct |
4 |
Correct |
392 ms |
512 KB |
Output is correct |
5 |
Correct |
406 ms |
768 KB |
Output is correct |
6 |
Correct |
398 ms |
632 KB |
Output is correct |
7 |
Correct |
405 ms |
768 KB |
Output is correct |
8 |
Correct |
356 ms |
512 KB |
Output is correct |
9 |
Correct |
367 ms |
652 KB |
Output is correct |
10 |
Correct |
401 ms |
632 KB |
Output is correct |
11 |
Correct |
405 ms |
760 KB |
Output is correct |
12 |
Correct |
333 ms |
512 KB |
Output is correct |
13 |
Correct |
455 ms |
788 KB |
Output is correct |
14 |
Correct |
362 ms |
512 KB |
Output is correct |
15 |
Correct |
451 ms |
512 KB |
Output is correct |
16 |
Correct |
288 ms |
512 KB |
Output is correct |
17 |
Correct |
534 ms |
768 KB |
Output is correct |
18 |
Correct |
378 ms |
512 KB |
Output is correct |
19 |
Correct |
486 ms |
636 KB |
Output is correct |
20 |
Correct |
371 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
388 ms |
632 KB |
Output is correct |
2 |
Correct |
382 ms |
676 KB |
Output is correct |
3 |
Correct |
321 ms |
512 KB |
Output is correct |
4 |
Correct |
402 ms |
764 KB |
Output is correct |
5 |
Correct |
369 ms |
632 KB |
Output is correct |
6 |
Correct |
518 ms |
632 KB |
Output is correct |
7 |
Correct |
418 ms |
760 KB |
Output is correct |
8 |
Correct |
435 ms |
760 KB |
Output is correct |
9 |
Correct |
419 ms |
704 KB |
Output is correct |
10 |
Correct |
347 ms |
632 KB |
Output is correct |
11 |
Correct |
370 ms |
512 KB |
Output is correct |
12 |
Correct |
406 ms |
776 KB |
Output is correct |
13 |
Correct |
365 ms |
632 KB |
Output is correct |
14 |
Correct |
389 ms |
632 KB |
Output is correct |
15 |
Correct |
370 ms |
632 KB |
Output is correct |
16 |
Correct |
291 ms |
760 KB |
Output is correct |
17 |
Correct |
530 ms |
656 KB |
Output is correct |
18 |
Correct |
362 ms |
632 KB |
Output is correct |