#include "library.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int n;
vector<int> vec;
int rec[maxn*8];
vector<int> way[maxn];
vector<int> ans;
int ask(int l, int r, int x) {
for(int i=l;i<=r;i++) vec[i-1] = 1;
if(x) vec[x-1] = 1;
int temp = Query(vec);
for(int i=l;i<=r;i++) vec[i-1] = 0;
if(x) vec[x-1] = 0;
return temp;
}
void build(int pos, int l, int r) {
if(l>r) return ;
rec[pos] = ask(l,r,0);
if(l==r) return ;
int mid = (l+r)/2;
build(pos<<1,l,mid); build(pos<<1|1,mid+1,r);
}
void addedge(int x, int pos, int l, int r) {
if(l>r || x<=l) return ;
// printf("ask [%d, %d] : %d = %d original = %d\n",l,r,x,ask(l,r,x),ask(l,r,0));
if(ask(l,r,x)>rec[pos]) return ;
if(l==r) {
// printf("%d <-> %d\n",l,x);
way[x].push_back(l);
way[l].push_back(x);
return ;
}
int mid = (l+r)/2;
addedge(x,pos<<1,l,mid); addedge(x,pos<<1|1,mid+1,r);
}
void dfs(int u, int last) {
// printf("dfs %d\n",u,last);
ans.push_back(u);
for(auto v : way[u]) {
if(v==last) continue;
dfs(v, u);
}
}
void Solve(int N) {
if(N==1) {
Answer({1});
return ;
}
n = N;
for(int i=0;i<n;i++) vec.push_back(0);
build(1,1,n);
for(int x=1;x<=n;x++) addedge(x,1,1,n);
for(int x=1;x<=n;x++) {
if(way[x].size()==1) {
dfs(x, 0);
Answer(ans);
return ;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
328 KB |
Output is correct |
2 |
Correct |
66 ms |
536 KB |
Output is correct |
3 |
Correct |
68 ms |
536 KB |
Output is correct |
4 |
Correct |
67 ms |
536 KB |
Output is correct |
5 |
Correct |
75 ms |
536 KB |
Output is correct |
6 |
Correct |
72 ms |
536 KB |
Output is correct |
7 |
Correct |
72 ms |
628 KB |
Output is correct |
8 |
Correct |
67 ms |
628 KB |
Output is correct |
9 |
Correct |
72 ms |
628 KB |
Output is correct |
10 |
Correct |
37 ms |
628 KB |
Output is correct |
11 |
Correct |
2 ms |
628 KB |
Output is correct |
12 |
Correct |
2 ms |
628 KB |
Output is correct |
13 |
Correct |
2 ms |
628 KB |
Output is correct |
14 |
Correct |
2 ms |
628 KB |
Output is correct |
15 |
Correct |
4 ms |
628 KB |
Output is correct |
16 |
Correct |
5 ms |
628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
328 KB |
Output is correct |
2 |
Correct |
66 ms |
536 KB |
Output is correct |
3 |
Correct |
68 ms |
536 KB |
Output is correct |
4 |
Correct |
67 ms |
536 KB |
Output is correct |
5 |
Correct |
75 ms |
536 KB |
Output is correct |
6 |
Correct |
72 ms |
536 KB |
Output is correct |
7 |
Correct |
72 ms |
628 KB |
Output is correct |
8 |
Correct |
67 ms |
628 KB |
Output is correct |
9 |
Correct |
72 ms |
628 KB |
Output is correct |
10 |
Correct |
37 ms |
628 KB |
Output is correct |
11 |
Correct |
2 ms |
628 KB |
Output is correct |
12 |
Correct |
2 ms |
628 KB |
Output is correct |
13 |
Correct |
2 ms |
628 KB |
Output is correct |
14 |
Correct |
2 ms |
628 KB |
Output is correct |
15 |
Correct |
4 ms |
628 KB |
Output is correct |
16 |
Correct |
5 ms |
628 KB |
Output is correct |
17 |
Runtime error |
1875 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
18 |
Halted |
0 ms |
0 KB |
- |