답안 #320653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
320653 2020-11-09T12:03:16 Z arnold518 Park (JOI17_park) C++14
67 / 100
360 ms 9444 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], cnt;

int query(int A, int B)
{
	if(A>B) swap(A, B);
	cnt++;
	//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)
{
	//printf("SOLVE %d %d\n", u, v);
	if(vis[v]) 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();
	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;

	if(hi==V.size())
	{
		vis[v]=1;
		D[v]=D[u]+1;
		answer(u, v);
		return;
	}

	int w=V[hi];

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

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

	vis[0]=1;

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

		for(int j=0; j<N; j++) if(vis[j]) P[j]=1;
		P[i]=1;
		if(query(0, i))
		{
			for(int j=0; j<N; j++) if(vis[j]) P[j]=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
		{
			for(int j=0; j<N; j++) if(vis[j]) P[j]=0;
			P[i]=0;
			solve(0, i);
		}
	}
}

Compilation message

park.cpp: In function 'void solve(int, int)':
park.cpp:51:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |   int mid=lo+hi>>1;
      |           ~~^~~
park.cpp:60:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  if(hi==V.size())
      |     ~~^~~~~~~~~~
park.cpp: In function 'void Detect(int, int)':
park.cpp:96:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   96 |     int mid=lo+hi>>1;
      |             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Wrong Answer[6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 234 ms 808 KB Output is correct
2 Correct 258 ms 9444 KB Output is correct
3 Correct 275 ms 7256 KB Output is correct
4 Correct 227 ms 696 KB Output is correct
5 Correct 223 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 267 ms 612 KB Output is correct
2 Correct 287 ms 612 KB Output is correct
3 Correct 291 ms 492 KB Output is correct
4 Correct 272 ms 580 KB Output is correct
5 Correct 293 ms 644 KB Output is correct
6 Correct 284 ms 492 KB Output is correct
7 Correct 282 ms 492 KB Output is correct
8 Correct 297 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 488 KB Output is correct
2 Correct 315 ms 492 KB Output is correct
3 Correct 307 ms 488 KB Output is correct
4 Correct 294 ms 492 KB Output is correct
5 Correct 285 ms 868 KB Output is correct
6 Correct 261 ms 620 KB Output is correct
7 Correct 251 ms 620 KB Output is correct
8 Correct 297 ms 492 KB Output is correct
9 Correct 267 ms 612 KB Output is correct
10 Correct 341 ms 712 KB Output is correct
11 Correct 300 ms 804 KB Output is correct
12 Correct 302 ms 736 KB Output is correct
13 Correct 245 ms 712 KB Output is correct
14 Correct 334 ms 680 KB Output is correct
15 Correct 269 ms 748 KB Output is correct
16 Correct 288 ms 612 KB Output is correct
17 Correct 212 ms 708 KB Output is correct
18 Correct 337 ms 752 KB Output is correct
19 Correct 229 ms 664 KB Output is correct
20 Correct 276 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 360 ms 740 KB Wrong Answer[6]
2 Halted 0 ms 0 KB -