Submission #140066

# Submission time Handle Problem Language Result Execution time Memory
140066 2019-08-02T01:35:29 Z mahmoudbadawy Library (JOI18_library) C++17
0 / 100
2000 ms 209928 KB
#include <cstdio>
#include <iostream>
#include <vector>
#include "library.h"
using namespace std;

// Query()
// Answer()
int n;

int query(vector<int> v)
{
	vector<int> m(n,0);
	for(int i:v) m[i]=1;
	return Query(m);
}

int get(int x,vector<int> v)
{
	if(v.size()==1)
	{
		v.push_back(x);
		if(query(v)==2)
			return -1;
		return v[0];
	}
	vector<int> mm;
	for(int i=0;i<v.size()/2;i++)
		mm.push_back(v[i]);
	int cur=query(mm);
	mm.push_back(x);
	if(query(mm)<=cur)
	{
		mm.pop_back();
		return get(x,mm);
	}
	mm.clear();
	for(int i=v.size()/2;i<v.size();i++)
		mm.push_back(v[i]);
	return get(x,mm);
}

vector<int> adj[1005];
vector<int> ans;
int vis[1005];

void build(int x,int pa)
{
	vis[x]=1;
	ans.push_back(x+1);
	for(int i:adj[x])
		if(!vis[x]) build(i,x);
}

void Solve(int N)
{
	n=N;
	vector<int> hv1;
	for(int i=0;i<N;i++)
	{
		vector<int> m(N,1);
		m[i]=0;
		if(Query(m)==1)
			hv1.push_back(i);
	}
	for(int i=0;i<N;i++)
	{
		while(true){
			if(adj[i].size()==2 || (adj[i].size()==1 && (hv1[0]==i||hv1[1]==i))) break;
			vector<int> ss;
			for(int j=0;j<N;j++)
			{
				bool ok=1;
				for(int k:adj[i])
					ok&=(k!=j);
				ok&=(i!=j);
				if(ok) ss.push_back(j);
			}
			int x=get(i,ss);
			if(x!=-1) {adj[i].push_back(x); adj[x].push_back(i);}
		}
		//cout << i+1 << " Found " << x+1 << endl;
	}
	/*for(int i=0;i<n;i++)
	{
		cout << i+1 << ": ";
		for(int j:adj[i]) cout << j+1 << " ";
		cout << endl;
	}*/
	for(int i=0;i<n;i++)
	{
		if(adj[i].size()==1)
		{
			build(i,-1); break;
		}
	}
	Answer(ans);
}

Compilation message

library.cpp: In function 'int get(int, std::vector<int>)':
library.cpp:28:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size()/2;i++)
              ~^~~~~~~~~~~
library.cpp:38:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=v.size()/2;i<v.size();i++)
                       ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 348 KB Wrong Answer [4]
2 Incorrect 61 ms 352 KB Wrong Answer [4]
3 Incorrect 70 ms 476 KB Wrong Answer [4]
4 Incorrect 55 ms 376 KB Wrong Answer [4]
5 Incorrect 71 ms 376 KB Wrong Answer [4]
6 Incorrect 64 ms 376 KB Wrong Answer [4]
7 Incorrect 46 ms 428 KB Wrong Answer [4]
8 Incorrect 56 ms 348 KB Wrong Answer [4]
9 Incorrect 65 ms 376 KB Wrong Answer [4]
10 Incorrect 33 ms 376 KB Wrong Answer [4]
11 Execution timed out 3065 ms 209928 KB Time limit exceeded
12 Incorrect 2 ms 248 KB Wrong Answer [4]
13 Incorrect 2 ms 376 KB Wrong Answer [4]
14 Incorrect 2 ms 248 KB Wrong Answer [4]
15 Incorrect 5 ms 376 KB Wrong Answer [4]
16 Incorrect 6 ms 248 KB Wrong Answer [4]
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 348 KB Wrong Answer [4]
2 Incorrect 61 ms 352 KB Wrong Answer [4]
3 Incorrect 70 ms 476 KB Wrong Answer [4]
4 Incorrect 55 ms 376 KB Wrong Answer [4]
5 Incorrect 71 ms 376 KB Wrong Answer [4]
6 Incorrect 64 ms 376 KB Wrong Answer [4]
7 Incorrect 46 ms 428 KB Wrong Answer [4]
8 Incorrect 56 ms 348 KB Wrong Answer [4]
9 Incorrect 65 ms 376 KB Wrong Answer [4]
10 Incorrect 33 ms 376 KB Wrong Answer [4]
11 Execution timed out 3065 ms 209928 KB Time limit exceeded
12 Incorrect 2 ms 248 KB Wrong Answer [4]
13 Incorrect 2 ms 376 KB Wrong Answer [4]
14 Incorrect 2 ms 248 KB Wrong Answer [4]
15 Incorrect 5 ms 376 KB Wrong Answer [4]
16 Incorrect 6 ms 248 KB Wrong Answer [4]
17 Incorrect 622 ms 384 KB Wrong Answer [3]
18 Execution timed out 3033 ms 14060 KB Time limit exceeded
19 Incorrect 624 ms 516 KB Wrong Answer [3]
20 Execution timed out 3076 ms 16052 KB Time limit exceeded
21 Incorrect 539 ms 504 KB Wrong Answer [4]
22 Incorrect 648 ms 636 KB Wrong Answer [3]
23 Incorrect 617 ms 516 KB Wrong Answer [3]
24 Incorrect 214 ms 376 KB Wrong Answer [4]
25 Execution timed out 3078 ms 15148 KB Time limit exceeded
26 Execution timed out 3069 ms 16900 KB Time limit exceeded
27 Incorrect 226 ms 448 KB Wrong Answer [4]
28 Incorrect 571 ms 504 KB Wrong Answer [3]
29 Incorrect 574 ms 392 KB Wrong Answer [3]
30 Incorrect 621 ms 400 KB Wrong Answer [3]