Submission #43995

# Submission time Handle Problem Language Result Execution time Memory
43995 2018-03-29T09:34:11 Z zscoder Library (JOI18_library) C++17
100 / 100
663 ms 9508 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 81 ms 576 KB Output is correct
2 Correct 48 ms 728 KB Output is correct
3 Correct 53 ms 800 KB Output is correct
4 Correct 55 ms 816 KB Output is correct
5 Correct 50 ms 864 KB Output is correct
6 Correct 50 ms 1004 KB Output is correct
7 Correct 53 ms 1004 KB Output is correct
8 Correct 46 ms 1004 KB Output is correct
9 Correct 55 ms 1004 KB Output is correct
10 Correct 31 ms 1004 KB Output is correct
11 Correct 2 ms 1004 KB Output is correct
12 Correct 2 ms 1004 KB Output is correct
13 Correct 2 ms 1004 KB Output is correct
14 Correct 2 ms 1004 KB Output is correct
15 Correct 4 ms 1004 KB Output is correct
16 Correct 5 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 576 KB Output is correct
2 Correct 48 ms 728 KB Output is correct
3 Correct 53 ms 800 KB Output is correct
4 Correct 55 ms 816 KB Output is correct
5 Correct 50 ms 864 KB Output is correct
6 Correct 50 ms 1004 KB Output is correct
7 Correct 53 ms 1004 KB Output is correct
8 Correct 46 ms 1004 KB Output is correct
9 Correct 55 ms 1004 KB Output is correct
10 Correct 31 ms 1004 KB Output is correct
11 Correct 2 ms 1004 KB Output is correct
12 Correct 2 ms 1004 KB Output is correct
13 Correct 2 ms 1004 KB Output is correct
14 Correct 2 ms 1004 KB Output is correct
15 Correct 4 ms 1004 KB Output is correct
16 Correct 5 ms 1004 KB Output is correct
17 Correct 663 ms 9416 KB Output is correct
18 Correct 607 ms 9416 KB Output is correct
19 Correct 628 ms 9508 KB Output is correct
20 Correct 580 ms 9508 KB Output is correct
21 Correct 496 ms 9508 KB Output is correct
22 Correct 631 ms 9508 KB Output is correct
23 Correct 619 ms 9508 KB Output is correct
24 Correct 213 ms 9508 KB Output is correct
25 Correct 606 ms 9508 KB Output is correct
26 Correct 531 ms 9508 KB Output is correct
27 Correct 207 ms 9508 KB Output is correct
28 Correct 539 ms 9508 KB Output is correct
29 Correct 557 ms 9508 KB Output is correct
30 Correct 530 ms 9508 KB Output is correct