#include "library.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1000;
int N;
int memo[MAXN+10][MAXN+10];
vector<int> adj[MAXN+10];
bool vis[MAXN+10];
vector<int> ans;
int query(int l, int r)
{
int i, j;
if(l==r) memo[l][r]=1;
else if(memo[l][r]==-1)
{
vector<int> t;
t.resize(N);
for(i=l; i<=r; i++) t[i-1]=1;
memo[l][r]=Query(t);
}
return memo[l][r];
}
void Solve(int _N)
{
int i, j;
N=_N;
memset(memo, -1, sizeof(memo));
if(N==1)
{
Answer(vector<int>(1, 1));
return;
}
for(i=2; i<=N; i++)
{
int lo, hi;
lo=0, hi=i;
while(lo+1<hi)
{
int mid=lo+hi>>1, t;
if(mid==0) t=2;
else t=query(mid, i-1)+1-query(mid, i);
if(t<=0) hi=mid;
else lo=mid;
}
if(lo) adj[i].push_back(lo), adj[lo].push_back(i);
if(query(1, i-1)+1-query(1, i)==1) continue;
lo=0, hi=i;
while(lo+1<hi)
{
int mid=lo+hi>>1, t;
if(mid==0) t=2;
else t=query(mid, i-1)+1-query(mid, i);
if(t<=1) hi=mid;
else lo=mid;
}
if(lo) adj[i].push_back(lo), adj[lo].push_back(i);
}
int now=0;
for(i=1; i<=N; i++) if(adj[i].size()==1) break;
now=i;
while(1)
{
ans.push_back(now); vis[now]=1;
int cnt=0;
for(int nxt : adj[now])
{
if(vis[nxt]) continue;
now=nxt; cnt++;
}
if(!cnt) break;
}
Answer(ans);
}
Compilation message
library.cpp: In function 'int query(int, int)':
library.cpp:20:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
library.cpp: In function 'void Solve(int)':
library.cpp:52:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=lo+hi>>1, t;
~~^~~
library.cpp:66:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=lo+hi>>1, t;
~~^~~
library.cpp:35:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
4216 KB |
# of queries: 2708 |
2 |
Correct |
59 ms |
4216 KB |
# of queries: 2732 |
3 |
Correct |
55 ms |
4216 KB |
# of queries: 2852 |
4 |
Correct |
51 ms |
4344 KB |
# of queries: 2847 |
5 |
Correct |
43 ms |
4472 KB |
# of queries: 2874 |
6 |
Correct |
58 ms |
4344 KB |
# of queries: 2804 |
7 |
Correct |
60 ms |
4336 KB |
# of queries: 2884 |
8 |
Correct |
37 ms |
4332 KB |
# of queries: 2714 |
9 |
Correct |
59 ms |
4344 KB |
# of queries: 2794 |
10 |
Correct |
38 ms |
4420 KB |
# of queries: 1666 |
11 |
Correct |
5 ms |
4216 KB |
# of queries: 0 |
12 |
Correct |
5 ms |
4216 KB |
# of queries: 1 |
13 |
Correct |
5 ms |
4344 KB |
# of queries: 3 |
14 |
Correct |
5 ms |
4344 KB |
# of queries: 6 |
15 |
Correct |
6 ms |
4216 KB |
# of queries: 73 |
16 |
Correct |
8 ms |
4344 KB |
# of queries: 186 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
4216 KB |
# of queries: 2708 |
2 |
Correct |
59 ms |
4216 KB |
# of queries: 2732 |
3 |
Correct |
55 ms |
4216 KB |
# of queries: 2852 |
4 |
Correct |
51 ms |
4344 KB |
# of queries: 2847 |
5 |
Correct |
43 ms |
4472 KB |
# of queries: 2874 |
6 |
Correct |
58 ms |
4344 KB |
# of queries: 2804 |
7 |
Correct |
60 ms |
4336 KB |
# of queries: 2884 |
8 |
Correct |
37 ms |
4332 KB |
# of queries: 2714 |
9 |
Correct |
59 ms |
4344 KB |
# of queries: 2794 |
10 |
Correct |
38 ms |
4420 KB |
# of queries: 1666 |
11 |
Correct |
5 ms |
4216 KB |
# of queries: 0 |
12 |
Correct |
5 ms |
4216 KB |
# of queries: 1 |
13 |
Correct |
5 ms |
4344 KB |
# of queries: 3 |
14 |
Correct |
5 ms |
4344 KB |
# of queries: 6 |
15 |
Correct |
6 ms |
4216 KB |
# of queries: 73 |
16 |
Correct |
8 ms |
4344 KB |
# of queries: 186 |
17 |
Incorrect |
607 ms |
4484 KB |
Wrong Answer [3] |
18 |
Correct |
558 ms |
4472 KB |
# of queries: 19843 |
19 |
Incorrect |
573 ms |
4476 KB |
Wrong Answer [3] |
20 |
Correct |
548 ms |
4520 KB |
# of queries: 18752 |
21 |
Correct |
502 ms |
4344 KB |
# of queries: 17560 |
22 |
Incorrect |
604 ms |
4476 KB |
Wrong Answer [3] |
23 |
Incorrect |
590 ms |
4472 KB |
Wrong Answer [3] |
24 |
Correct |
206 ms |
4348 KB |
# of queries: 9025 |
25 |
Correct |
531 ms |
4472 KB |
# of queries: 19653 |
26 |
Correct |
558 ms |
4480 KB |
# of queries: 18306 |
27 |
Correct |
214 ms |
4476 KB |
# of queries: 9090 |
28 |
Correct |
424 ms |
4340 KB |
# of queries: 15470 |
29 |
Correct |
472 ms |
4472 KB |
# of queries: 15451 |
30 |
Correct |
461 ms |
4604 KB |
# of queries: 15470 |