#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=1; 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);
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:64: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 |
52 ms |
4216 KB |
# of queries: 2827 |
2 |
Correct |
71 ms |
4344 KB |
# of queries: 2917 |
3 |
Correct |
50 ms |
4344 KB |
# of queries: 2997 |
4 |
Correct |
41 ms |
4332 KB |
# of queries: 3035 |
5 |
Correct |
62 ms |
4344 KB |
# of queries: 3023 |
6 |
Correct |
52 ms |
4216 KB |
# of queries: 2996 |
7 |
Correct |
50 ms |
4348 KB |
# of queries: 3048 |
8 |
Correct |
58 ms |
4396 KB |
# of queries: 2910 |
9 |
Correct |
62 ms |
4340 KB |
# of queries: 2959 |
10 |
Correct |
37 ms |
4344 KB |
# of queries: 1710 |
11 |
Correct |
5 ms |
4216 KB |
# of queries: 0 |
12 |
Correct |
5 ms |
4472 KB |
# of queries: 1 |
13 |
Correct |
5 ms |
4216 KB |
# of queries: 3 |
14 |
Correct |
5 ms |
4216 KB |
# of queries: 6 |
15 |
Correct |
6 ms |
4216 KB |
# of queries: 73 |
16 |
Correct |
8 ms |
4344 KB |
# of queries: 191 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
4216 KB |
# of queries: 2827 |
2 |
Correct |
71 ms |
4344 KB |
# of queries: 2917 |
3 |
Correct |
50 ms |
4344 KB |
# of queries: 2997 |
4 |
Correct |
41 ms |
4332 KB |
# of queries: 3035 |
5 |
Correct |
62 ms |
4344 KB |
# of queries: 3023 |
6 |
Correct |
52 ms |
4216 KB |
# of queries: 2996 |
7 |
Correct |
50 ms |
4348 KB |
# of queries: 3048 |
8 |
Correct |
58 ms |
4396 KB |
# of queries: 2910 |
9 |
Correct |
62 ms |
4340 KB |
# of queries: 2959 |
10 |
Correct |
37 ms |
4344 KB |
# of queries: 1710 |
11 |
Correct |
5 ms |
4216 KB |
# of queries: 0 |
12 |
Correct |
5 ms |
4472 KB |
# of queries: 1 |
13 |
Correct |
5 ms |
4216 KB |
# of queries: 3 |
14 |
Correct |
5 ms |
4216 KB |
# of queries: 6 |
15 |
Correct |
6 ms |
4216 KB |
# of queries: 73 |
16 |
Correct |
8 ms |
4344 KB |
# of queries: 191 |
17 |
Incorrect |
613 ms |
4344 KB |
Wrong Answer [3] |
18 |
Incorrect |
597 ms |
4592 KB |
Wrong Answer [3] |
19 |
Incorrect |
775 ms |
4596 KB |
Wrong Answer [3] |
20 |
Incorrect |
545 ms |
4600 KB |
Wrong Answer [3] |
21 |
Correct |
540 ms |
4420 KB |
# of queries: 18847 |
22 |
Incorrect |
609 ms |
4468 KB |
Wrong Answer [3] |
23 |
Incorrect |
583 ms |
4356 KB |
Wrong Answer [3] |
24 |
Correct |
220 ms |
4468 KB |
# of queries: 9697 |
25 |
Incorrect |
606 ms |
4392 KB |
Wrong Answer [3] |
26 |
Correct |
573 ms |
4348 KB |
# of queries: 19657 |
27 |
Correct |
206 ms |
4392 KB |
# of queries: 9640 |
28 |
Incorrect |
585 ms |
4464 KB |
Wrong Answer [3] |
29 |
Incorrect |
589 ms |
4588 KB |
Wrong Answer [3] |
30 |
Incorrect |
592 ms |
4476 KB |
Wrong Answer [3] |