#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;
if(query(1, i-1)+1-query(1, i)==0) continue;
lo=1, 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=1, 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:54:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=lo+hi>>1, t;
~~^~~
library.cpp:68: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;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
4328 KB |
# of queries: 2380 |
2 |
Correct |
44 ms |
4344 KB |
# of queries: 2447 |
3 |
Correct |
52 ms |
4344 KB |
# of queries: 2508 |
4 |
Correct |
52 ms |
4424 KB |
# of queries: 2540 |
5 |
Correct |
35 ms |
4356 KB |
# of queries: 2533 |
6 |
Correct |
35 ms |
4416 KB |
# of queries: 2528 |
7 |
Correct |
40 ms |
4392 KB |
# of queries: 2545 |
8 |
Correct |
42 ms |
4412 KB |
# of queries: 2387 |
9 |
Correct |
35 ms |
4332 KB |
# of queries: 2500 |
10 |
Correct |
30 ms |
4344 KB |
# of queries: 1481 |
11 |
Correct |
5 ms |
4216 KB |
# of queries: 0 |
12 |
Correct |
5 ms |
4344 KB |
# of queries: 1 |
13 |
Correct |
5 ms |
4220 KB |
# of queries: 3 |
14 |
Correct |
5 ms |
4320 KB |
# of queries: 6 |
15 |
Correct |
6 ms |
4216 KB |
# of queries: 76 |
16 |
Correct |
7 ms |
4344 KB |
# of queries: 172 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
4328 KB |
# of queries: 2380 |
2 |
Correct |
44 ms |
4344 KB |
# of queries: 2447 |
3 |
Correct |
52 ms |
4344 KB |
# of queries: 2508 |
4 |
Correct |
52 ms |
4424 KB |
# of queries: 2540 |
5 |
Correct |
35 ms |
4356 KB |
# of queries: 2533 |
6 |
Correct |
35 ms |
4416 KB |
# of queries: 2528 |
7 |
Correct |
40 ms |
4392 KB |
# of queries: 2545 |
8 |
Correct |
42 ms |
4412 KB |
# of queries: 2387 |
9 |
Correct |
35 ms |
4332 KB |
# of queries: 2500 |
10 |
Correct |
30 ms |
4344 KB |
# of queries: 1481 |
11 |
Correct |
5 ms |
4216 KB |
# of queries: 0 |
12 |
Correct |
5 ms |
4344 KB |
# of queries: 1 |
13 |
Correct |
5 ms |
4220 KB |
# of queries: 3 |
14 |
Correct |
5 ms |
4320 KB |
# of queries: 6 |
15 |
Correct |
6 ms |
4216 KB |
# of queries: 76 |
16 |
Correct |
7 ms |
4344 KB |
# of queries: 172 |
17 |
Correct |
535 ms |
4484 KB |
# of queries: 17598 |
18 |
Correct |
502 ms |
4600 KB |
# of queries: 17260 |
19 |
Correct |
529 ms |
4480 KB |
# of queries: 17436 |
20 |
Correct |
417 ms |
4340 KB |
# of queries: 16139 |
21 |
Correct |
421 ms |
4520 KB |
# of queries: 15248 |
22 |
Correct |
468 ms |
4592 KB |
# of queries: 17383 |
23 |
Correct |
521 ms |
4476 KB |
# of queries: 17489 |
24 |
Correct |
177 ms |
4448 KB |
# of queries: 7910 |
25 |
Correct |
464 ms |
4592 KB |
# of queries: 17058 |
26 |
Correct |
424 ms |
4344 KB |
# of queries: 15822 |
27 |
Correct |
178 ms |
4392 KB |
# of queries: 7913 |
28 |
Correct |
450 ms |
4468 KB |
# of queries: 15454 |
29 |
Correct |
460 ms |
4472 KB |
# of queries: 15436 |
30 |
Correct |
419 ms |
4420 KB |
# of queries: 15454 |