# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
47480 |
2018-05-03T17:53:16 Z |
hihi |
Library (JOI18_library) |
C++14 |
|
698 ms |
9596 KB |
#include <cstdio>
#include <vector>
#include "library.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;
vector<int> res;
set<int> rem;
int n;
int query(vector<int> &test)
{
int ex1=0;
for(int i=0;i<n;i++)
{
if(test[i]) ex1=1;
}
if(!ex1) return 0;
else return Query(test);
}
void solve(int l, int r)
{
//cerr<<"SOLVE "<<l<<' '<<r<<'\n';
if(l>r) return ;
if(l==r)
{
res[l] = (*rem.begin()); return ;
}
int xr=0;
for(int i=0;i<10;i++)
{
vector<int> test(n,0);
for(int x:rem)
{
if(x&(1<<i))
{
test[x]=1;
}
}
int res = query(test);
test.assign(n,0);
for(int x:rem)
{
if(!(x&(1<<i)))
{
test[x]=1;
}
}
int res2 = query(test);
if(res==res2)
{
xr^=(1<<i);
}
}
set<int> possibleX; vi V;
for(int x:rem)
{
if(possibleX.find(x^xr)==possibleX.end())
{
possibleX.insert(x); V.pb(x);
}
}
int lo=0; int hi=int(V.size())-1;
int ans = -1;
while(lo<=hi)
{
int mid=(lo+hi)>>1;
vector<int> test(n,0);
for(int i=0;i<V.size();i++)
{
if(i<=mid) test[V[i]]=1;
else test[V[i]]=0;
}
int ans1 = query(test);
for(int x:rem)
{
test[x]^=1;
}
int ans2=query(test);
if(ans1==ans2)
{
ans=mid;
hi=mid-1;
}
else lo=mid+1;
}
//cerr<<"XOR : "<<xr<<'\n'; //cerr<<"ANS : "<<ans<<'\n';
int x = V[ans]; int y = V[ans]^xr;
if(l>0)
{
vector<int> test(n,0);
test[res[l-1]]=1; test[x]=1;
if(query(test)!=1)
{
swap(x,y);
}
}
res[l] = x; res[r] = y;
//cerr<<l<<' '<<x<<'\n'; //cerr<<r<<' '<<y<<'\n';
rem.erase(x); rem.erase(y);
solve(l+1,r-1);
}
void Solve(int N)
{
n=N;
res.resize(N);
for(int i=0;i<N;i++) rem.insert(i);
solve(0,N-1);
for(int i=0;i<N;i++) res[i]++;
Answer(res);
}
Compilation message
library.cpp: In function 'void solve(int, int)':
library.cpp:89:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<V.size();i++)
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
760 KB |
Output is correct |
2 |
Correct |
55 ms |
760 KB |
Output is correct |
3 |
Correct |
48 ms |
880 KB |
Output is correct |
4 |
Correct |
52 ms |
916 KB |
Output is correct |
5 |
Correct |
54 ms |
916 KB |
Output is correct |
6 |
Correct |
39 ms |
916 KB |
Output is correct |
7 |
Correct |
56 ms |
916 KB |
Output is correct |
8 |
Correct |
53 ms |
916 KB |
Output is correct |
9 |
Correct |
57 ms |
916 KB |
Output is correct |
10 |
Correct |
21 ms |
916 KB |
Output is correct |
11 |
Correct |
2 ms |
916 KB |
Output is correct |
12 |
Correct |
2 ms |
916 KB |
Output is correct |
13 |
Correct |
2 ms |
916 KB |
Output is correct |
14 |
Correct |
2 ms |
916 KB |
Output is correct |
15 |
Correct |
3 ms |
916 KB |
Output is correct |
16 |
Correct |
9 ms |
916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
760 KB |
Output is correct |
2 |
Correct |
55 ms |
760 KB |
Output is correct |
3 |
Correct |
48 ms |
880 KB |
Output is correct |
4 |
Correct |
52 ms |
916 KB |
Output is correct |
5 |
Correct |
54 ms |
916 KB |
Output is correct |
6 |
Correct |
39 ms |
916 KB |
Output is correct |
7 |
Correct |
56 ms |
916 KB |
Output is correct |
8 |
Correct |
53 ms |
916 KB |
Output is correct |
9 |
Correct |
57 ms |
916 KB |
Output is correct |
10 |
Correct |
21 ms |
916 KB |
Output is correct |
11 |
Correct |
2 ms |
916 KB |
Output is correct |
12 |
Correct |
2 ms |
916 KB |
Output is correct |
13 |
Correct |
2 ms |
916 KB |
Output is correct |
14 |
Correct |
2 ms |
916 KB |
Output is correct |
15 |
Correct |
3 ms |
916 KB |
Output is correct |
16 |
Correct |
9 ms |
916 KB |
Output is correct |
17 |
Correct |
693 ms |
9504 KB |
Output is correct |
18 |
Correct |
676 ms |
9504 KB |
Output is correct |
19 |
Correct |
698 ms |
9588 KB |
Output is correct |
20 |
Correct |
583 ms |
9588 KB |
Output is correct |
21 |
Correct |
525 ms |
9588 KB |
Output is correct |
22 |
Correct |
623 ms |
9596 KB |
Output is correct |
23 |
Correct |
674 ms |
9596 KB |
Output is correct |
24 |
Correct |
232 ms |
9596 KB |
Output is correct |
25 |
Correct |
654 ms |
9596 KB |
Output is correct |
26 |
Correct |
616 ms |
9596 KB |
Output is correct |
27 |
Correct |
213 ms |
9596 KB |
Output is correct |
28 |
Correct |
544 ms |
9596 KB |
Output is correct |
29 |
Correct |
609 ms |
9596 KB |
Output is correct |
30 |
Correct |
564 ms |
9596 KB |
Output is correct |