Submission #320645

# Submission time Handle Problem Language Result Execution time Memory
320645 2020-11-09T11:34:06 Z arnold518 Park (JOI17_park) C++14
27 / 100
379 ms 1188 KB
#include "park.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 = 1500;

int T, N;
int P[MAXN+10];

int query(int A, int B)
{
	if(A>B) swap(A, B);
	//printf("QUERY %d %d\n", A, B);
	//for(int i=0; i<N; i++) printf("%d ", P[i]); printf("\n");
	return Ask(A, B, P);	
}

void answer(int A, int B)
{
	if(A>B) swap(A, B);
	//printf("ANSWER %d %d\n", A, B);
	Answer(A, B);
}

bool vis[MAXN+10];
int D[MAXN+10];

void solve(int u, int v)
{
	assert(vis[u]);
	if(vis[u] && vis[v]) return;

	P[u]=1; P[v]=1;
	if(query(u, v))
	{
		vis[v]=1;
		D[v]=D[u]+1;
		answer(u, v);
		P[u]=0; P[v]=0;
		return;
	}

	vector<int> V;
	for(int i=0; i<N; i++)
	{
		if(i==u) continue;
		if(i==v) continue;
		V.push_back(i);
	}

	for(int i=0; i<N; i++) P[i]=1;

	int lo=-1, hi=V.size()-1;
	while(lo+1<hi)
	{
		int mid=lo+hi>>1;
		for(int j=0; j<=mid; j++) P[V[j]]=0;
		if(query(u, v)) lo=mid;
		else hi=mid;
		for(int j=0; j<=mid; j++) P[V[j]]=1;
	}

	for(int i=0; i<N; i++) P[i]=0;
	int w=V[hi];

	solve(u, w);
	solve(w, v);
}

void Detect(int _T, int _N)
{
	T=_T; N=_N;

	int cnt=1;
	vis[0]=1;

	for(int i=1; i<N; i++)
	{
		if(vis[i]) continue;

		P[0]=1;
		P[i]=1;
		if(query(0, i))
		{
			P[0]=0;
			vector<int> V;
			for(int i=0; i<N; i++) if(vis[i]) V.push_back(i);
			sort(V.begin(), V.end(), [&](const int &p, const int &q) { return D[p]<D[q]; });

			int lo=-1, hi=V.size()-1;
			while(lo+1<hi)
			{
				int mid=lo+hi>>1;
				for(int j=0; j<=mid; j++) P[V[j]]=1;
				if(query(0, i)) hi=mid;
				else lo=mid;
				for(int j=0; j<=mid; j++) P[V[j]]=0;
			}
			answer(V[hi], i);
			D[i]=D[V[hi]]+1;
			vis[i]=true;
			P[i]=0;
		}
		else
		{
			P[0]=0;
			P[i]=0;
			solve(0, i);
		}
	}
}

Compilation message

park.cpp: In function 'void solve(int, int)':
park.cpp:60:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |   int mid=lo+hi>>1;
      |           ~~^~~
park.cpp: In function 'void Detect(int, int)':
park.cpp:97:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   97 |     int mid=lo+hi>>1;
      |             ~~^~~
park.cpp:78:6: warning: unused variable 'cnt' [-Wunused-variable]
   78 |  int cnt=1;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Wrong Answer[6]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 90 ms 784 KB Output is correct
2 Incorrect 231 ms 1188 KB Wrong Answer[5]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 199 ms 612 KB Output is correct
2 Correct 222 ms 612 KB Output is correct
3 Correct 222 ms 492 KB Output is correct
4 Correct 272 ms 640 KB Output is correct
5 Correct 193 ms 492 KB Output is correct
6 Correct 205 ms 528 KB Output is correct
7 Correct 235 ms 492 KB Output is correct
8 Correct 236 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 484 KB Output is correct
2 Correct 264 ms 492 KB Output is correct
3 Correct 226 ms 616 KB Output is correct
4 Correct 195 ms 492 KB Output is correct
5 Correct 193 ms 620 KB Output is correct
6 Correct 180 ms 620 KB Output is correct
7 Correct 129 ms 620 KB Output is correct
8 Correct 236 ms 612 KB Output is correct
9 Correct 158 ms 612 KB Output is correct
10 Incorrect 244 ms 620 KB Wrong Answer[5]
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 379 ms 744 KB Wrong Answer[6]
2 Halted 0 ms 0 KB -