Submission #207850

# Submission time Handle Problem Language Result Execution time Memory
207850 2020-03-09T09:26:50 Z quocnguyen1012 Library (JOI18_library) C++14
100 / 100
502 ms 380 KB
//#define LOCAL 1
#ifndef LOCAL
#include "library.h"
#endif // LOCAL
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
using namespace std;
void Solve(int N);

namespace {
struct Judge
{
	int N;
	int A[1002];
	int pos[1002];
	bool f[1002];
	int query_c;
	bool answered;
	void init()
	{
		query_c=0;
		int ret=scanf("%d",&N); ret++;
		answered=false;
		for(int i=0;i<N;i++)ret=scanf("%d",&A[i]),pos[A[i]]=i;
	}
	int query(const vector<int>& M)
	{
		if(query_c==20000)
		{
			puts("Wrong Answer [3]");
			exit(0);
		}
		if(int(M.size())!=N)
		{
			puts("Wrong Answer [1]");
			exit(0);
		}
		bool all_zero=true;
		for(int i=0;i<N;i++)
		{
			if(M[i]!=0&&M[i]!=1)
			{
				puts("Wrong Answer [2]");
				exit(0);
			}
			if(M[i]==1)all_zero=false;
		}
		if(all_zero)
		{
			puts("Wrong Answer [2]");
			exit(0);
		}
		memset(f,0,sizeof(f));
		for(int i=0;i<N;i++)if(M[i])f[pos[i+1]]=true;
		bool las=false;
		int r=0;
		for(int i=0;i<N;i++)
		{
			if(las==false&&f[i]==true)r++;
			las=f[i];
		}
		query_c++;
		return r;
	}
	void answer(const vector<int>& res)
	{
		bool f1=true,f2=true;
		if(int(res.size())!=N)
		{
			puts("Wrong Answer [4]");
			exit(0);
		}
		if(answered)
		{
			puts("Wrong Answer [7]");
			exit(0);
		}
		answered=true;
		memset(f,0,sizeof(f));
		for(int i=0;i<N;i++)
		{
			if(res[i]<=0||res[i]>N)
			{
				puts("Wrong Answer [5]");
				exit(0);
			}
			if(f[res[i]])
			{
				puts("Wrong Answer [6]");
				exit(0);
			}
			f[res[i]]=true;
		}
		for(int i=0;i<N;i++)
		{
			f1&=A[i]==res[i];
			f2&=A[i]==res[N-i-1];
		}
		if(!f1&&!f2)
		{
			puts("Wrong Answer [8]");
			exit(0);
		}
	}
	void end()
	{
		if(!answered)puts("Wrong Answer [7]");
		else printf("Accepted : %d\n",query_c);
	}
}judge;
}

int Query(const vector<int>& M)
{
	return judge.query(M);
}
void Answer(const vector<int>& res)
{
	judge.answer(res);
}

int main()
{
	if(fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
  }
	judge.init();
	Solve(judge.N);
	judge.end();
}
#endif // LOCAL

#include<bits/stdc++.h>

#define pb push_back

using namespace std;

vector<int> vec, vis;

int ask(vector<int> vi)
{
	if(vi.size() == 0) return 0;
	if(vi.size() == 1) return 1;
  for(int & x : vec) x = 0;
  for(int x : vi) vec[x - 1] = 1;
  return Query(vec);
}

int con(int u, vector<int> v)
{
	int a = ask(v); v.pb(u);
	int b = ask(v); return a - b + 1;
}

void Solve(int N)
{
	if (N == 1) {   Answer({1});    return; }
	if (N == 2) {   Answer({1,2});  return; }
	vec.assign(N, 0);
	vis.assign(N, 0);
	vector<int> res;
	for(int i = 1; i <= N; ++i){
		vector<int> v;
		for(int j = 1; j <= N; ++j){
			if(i != j) v.pb(j);
		}
		if(ask(v) == 1){
			res.pb(i);
			break;
		}
	}
	for(int i = 0; i < N - 1; ++i){
		int u = res[i];
		vis[u - 1] = 1;
		vector<int> v;
		for(int j = 0; j < N; ++j){
			if(vis[j] == 0) v.pb(j + 1);
		}
		int l = 1, r = v.size(), mid;
		while(l <= r){
			mid = (l + r) / 2;
			if(con(u, vector<int> (v.begin(), v.begin() + mid)))
				r = mid - 1;
			else l = mid + 1;
		}
    res.pb(v[l - 1]);
	}
	Answer(res);
}
# Verdict Execution time Memory Grader output
1 Correct 42 ms 380 KB # of queries: 2384
2 Correct 41 ms 248 KB # of queries: 2422
3 Correct 49 ms 376 KB # of queries: 2649
4 Correct 42 ms 376 KB # of queries: 2584
5 Correct 47 ms 376 KB # of queries: 2512
6 Correct 46 ms 376 KB # of queries: 2551
7 Correct 48 ms 376 KB # of queries: 2542
8 Correct 42 ms 248 KB # of queries: 2412
9 Correct 46 ms 248 KB # of queries: 2540
10 Correct 31 ms 248 KB # of queries: 1479
11 Correct 4 ms 248 KB # of queries: 0
12 Correct 5 ms 376 KB # of queries: 0
13 Correct 5 ms 248 KB # of queries: 4
14 Correct 5 ms 280 KB # of queries: 6
15 Correct 6 ms 376 KB # of queries: 74
16 Correct 7 ms 376 KB # of queries: 186
# Verdict Execution time Memory Grader output
1 Correct 42 ms 380 KB # of queries: 2384
2 Correct 41 ms 248 KB # of queries: 2422
3 Correct 49 ms 376 KB # of queries: 2649
4 Correct 42 ms 376 KB # of queries: 2584
5 Correct 47 ms 376 KB # of queries: 2512
6 Correct 46 ms 376 KB # of queries: 2551
7 Correct 48 ms 376 KB # of queries: 2542
8 Correct 42 ms 248 KB # of queries: 2412
9 Correct 46 ms 248 KB # of queries: 2540
10 Correct 31 ms 248 KB # of queries: 1479
11 Correct 4 ms 248 KB # of queries: 0
12 Correct 5 ms 376 KB # of queries: 0
13 Correct 5 ms 248 KB # of queries: 4
14 Correct 5 ms 280 KB # of queries: 6
15 Correct 6 ms 376 KB # of queries: 74
16 Correct 7 ms 376 KB # of queries: 186
17 Correct 502 ms 376 KB # of queries: 18015
18 Correct 455 ms 248 KB # of queries: 17262
19 Correct 479 ms 248 KB # of queries: 17468
20 Correct 434 ms 248 KB # of queries: 16285
21 Correct 408 ms 376 KB # of queries: 15335
22 Correct 480 ms 248 KB # of queries: 17643
23 Correct 476 ms 248 KB # of queries: 17239
24 Correct 166 ms 376 KB # of queries: 7908
25 Correct 486 ms 248 KB # of queries: 17140
26 Correct 432 ms 376 KB # of queries: 15986
27 Correct 167 ms 248 KB # of queries: 8027
28 Correct 383 ms 248 KB # of queries: 14976
29 Correct 391 ms 376 KB # of queries: 14959
30 Correct 396 ms 248 KB # of queries: 14976