# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
539299 |
2022-03-18T16:21:18 Z |
Soumya1 |
Library (JOI18_library) |
C++17 |
|
225 ms |
344 KB |
#include <cstdio>
#include <vector>
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
void Solve(int n) {
int store[n + 1];
{
vector<int> q(n);
for (int i = 1; i <= n; i++) {
q[i - 1] = 1;
store[i] = Query(q);
}
}
store[0] = 0;
vector<int> edge[n + 1];
for (int i = 1; i <= n; i++) {
int old_answer = store[i - 1];
int new_answer = store[i];
if (old_answer + 1 == new_answer) {
continue;
}
int lo = 1, hi = i - 1;
while (lo < hi) {
int mid = (lo + hi) / 2;
vector<int> q(n);
for (int j = 1; j <= mid; j++) q[j - 1] = 1;
q[i - 1] = 1;
int x = store[mid];
int y = Query(q);
if (y > x) lo = mid + 1;
else hi = mid;
}
edge[lo].push_back(i);
edge[i].push_back(lo);
if (new_answer < old_answer) {
lo = 1, hi = i - 1;
while (lo < hi) {
int mid = (lo + hi) / 2;
vector<int> q(n);
for (int j = 1; j <= mid; j++) q[j - 1] = 1;
q[i - 1] = 1;
int x = store[mid];
int y = Query(q);
if (x <= y) lo = mid + 1;
else hi = mid;
}
edge[lo].push_back(i);
edge[i].push_back(lo);
}
}
int start;
for (int i = 1; i <= n; i++) {
if ((int) edge[i].size() <= 1) start = i;
}
vector<bool> vis(n + 1);
vector<int> ans;
while ((int) ans.size() < n) {
ans.push_back(start);
vis[start] = true;
for (int next : edge[start]) {
if (!vis[next]) {
start = next;
break;
}
}
}
Answer(ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
296 KB |
# of queries: 1523 |
2 |
Correct |
13 ms |
296 KB |
# of queries: 1506 |
3 |
Correct |
26 ms |
296 KB |
# of queries: 1587 |
4 |
Correct |
29 ms |
328 KB |
# of queries: 1584 |
5 |
Correct |
15 ms |
300 KB |
# of queries: 1577 |
6 |
Correct |
20 ms |
308 KB |
# of queries: 1582 |
7 |
Correct |
35 ms |
304 KB |
# of queries: 1599 |
8 |
Correct |
25 ms |
288 KB |
# of queries: 1517 |
9 |
Correct |
23 ms |
300 KB |
# of queries: 1598 |
10 |
Correct |
22 ms |
300 KB |
# of queries: 940 |
11 |
Correct |
1 ms |
208 KB |
# of queries: 1 |
12 |
Correct |
1 ms |
208 KB |
# of queries: 2 |
13 |
Correct |
1 ms |
208 KB |
# of queries: 4 |
14 |
Correct |
1 ms |
208 KB |
# of queries: 8 |
15 |
Correct |
2 ms |
208 KB |
# of queries: 61 |
16 |
Correct |
5 ms |
208 KB |
# of queries: 131 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
296 KB |
# of queries: 1523 |
2 |
Correct |
13 ms |
296 KB |
# of queries: 1506 |
3 |
Correct |
26 ms |
296 KB |
# of queries: 1587 |
4 |
Correct |
29 ms |
328 KB |
# of queries: 1584 |
5 |
Correct |
15 ms |
300 KB |
# of queries: 1577 |
6 |
Correct |
20 ms |
308 KB |
# of queries: 1582 |
7 |
Correct |
35 ms |
304 KB |
# of queries: 1599 |
8 |
Correct |
25 ms |
288 KB |
# of queries: 1517 |
9 |
Correct |
23 ms |
300 KB |
# of queries: 1598 |
10 |
Correct |
22 ms |
300 KB |
# of queries: 940 |
11 |
Correct |
1 ms |
208 KB |
# of queries: 1 |
12 |
Correct |
1 ms |
208 KB |
# of queries: 2 |
13 |
Correct |
1 ms |
208 KB |
# of queries: 4 |
14 |
Correct |
1 ms |
208 KB |
# of queries: 8 |
15 |
Correct |
2 ms |
208 KB |
# of queries: 61 |
16 |
Correct |
5 ms |
208 KB |
# of queries: 131 |
17 |
Correct |
185 ms |
336 KB |
# of queries: 10295 |
18 |
Correct |
174 ms |
336 KB |
# of queries: 10159 |
19 |
Correct |
196 ms |
340 KB |
# of queries: 10274 |
20 |
Correct |
186 ms |
332 KB |
# of queries: 9621 |
21 |
Correct |
147 ms |
308 KB |
# of queries: 9030 |
22 |
Correct |
225 ms |
336 KB |
# of queries: 10315 |
23 |
Correct |
196 ms |
336 KB |
# of queries: 10263 |
24 |
Correct |
87 ms |
300 KB |
# of queries: 4780 |
25 |
Correct |
168 ms |
340 KB |
# of queries: 10072 |
26 |
Correct |
180 ms |
332 KB |
# of queries: 9411 |
27 |
Correct |
75 ms |
304 KB |
# of queries: 4765 |
28 |
Correct |
168 ms |
336 KB |
# of queries: 8978 |
29 |
Correct |
139 ms |
340 KB |
# of queries: 8968 |
30 |
Correct |
144 ms |
344 KB |
# of queries: 8978 |