답안 #46857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46857 2018-04-24T04:08:58 Z MatheusLealV 도서관 (JOI18_library) C++17
100 / 100
534 ms 844 KB
#include <bits/stdc++.h>
#define Nmax 1005
#include "library.h"
using namespace std;

#define f first
#define s second

typedef pair<int, int> pii;

int n, used[Nmax], conta = 0, ans[Nmax], ans2[Nmax];

int esq[Nmax], dir[Nmax];

int lower_bound(int x)
{
	int ini = 1, fim = x - 1, mid, best = -1;

	while(fim >= ini)
	{
		mid = (ini + fim)/2;
		
		vector<int> v (n);

		for(int i = 1; i <= mid; i++) v[i - 1] = 1;

		v[x - 1] = 1;

		int q = ans[mid] - Query(v);

		if(q == 0) best = mid, fim = mid - 1;

		else if(q < 0) ini = mid + 1;

		else fim = mid - 1;
	}

	return best;
}

int upper_bound(int x)
{
	int ini = 1, fim = x - 1, mid, best = -1;

	while(fim >= ini)
	{
		mid = (ini + fim)/2;
		
		vector<int> v (n);

		for(int i = 1; i <= mid; i++) v[i - 1] = 1;

		v[x - 1] = 1;

		int q = ans[mid] - Query(v);

		if(q == 1) best = mid, fim = mid - 1;

		else if(q < 1) ini = mid + 1;

		else fim = mid - 1;
	}

	return best;
}

set<int> viz[Nmax];

void Solve(int N_)
{
	n = N_;

	if(n == 1)
	{
		vector<int> A(1);

		A[0] = 1;

		Answer(A);

		return;
	}

	ans[1] = 1, esq[1] = dir[1] = -1;

	for(int i = 2; i <= n; i++)
	{
		esq[i] = lower_bound(i);

		dir[i] = upper_bound(i);

		vector<int> v (n);

		for(int j = 1; j <= i; j++) v[j - 1] = 1;

		ans[i] = Query(v);
	}

	vector<int> resp;

	for(int i = 1; i <= n; i++)
	{
		if(esq[i] != -1) viz[i].insert(esq[i]);

		if(dir[i] != -1) viz[i].insert(dir[i]);

		if(esq[i] != -1) viz[ esq[i] ].insert(i);

		if(dir[i] != -1) viz[ dir[i] ].insert(i);
	}

	for(int i = 1; i <= n; i++)
	{
		vector<int> v (n);

		for(int j = 1; j <= n; j++) v[j - 1] = 1;

		v[i - 1] = 0;

		if(Query(v) == 1)
		{
			used[i] = 1;

			resp.push_back(i);

			break;
		}
	}

	while(true)
	{
		int x = resp.back(), cnt = 0;

		for(auto v: viz[x])
		{
			if(used[v]) continue;

			used[v] = 1;

			resp.push_back(v), cnt ++;

			break;
		}

		if(!cnt) break;
	}

	Answer(resp);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 376 KB Output is correct
2 Correct 39 ms 376 KB Output is correct
3 Correct 47 ms 464 KB Output is correct
4 Correct 50 ms 464 KB Output is correct
5 Correct 54 ms 464 KB Output is correct
6 Correct 60 ms 548 KB Output is correct
7 Correct 43 ms 548 KB Output is correct
8 Correct 39 ms 548 KB Output is correct
9 Correct 37 ms 548 KB Output is correct
10 Correct 31 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 376 KB Output is correct
2 Correct 39 ms 376 KB Output is correct
3 Correct 47 ms 464 KB Output is correct
4 Correct 50 ms 464 KB Output is correct
5 Correct 54 ms 464 KB Output is correct
6 Correct 60 ms 548 KB Output is correct
7 Correct 43 ms 548 KB Output is correct
8 Correct 39 ms 548 KB Output is correct
9 Correct 37 ms 548 KB Output is correct
10 Correct 31 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 466 ms 716 KB Output is correct
18 Correct 464 ms 764 KB Output is correct
19 Correct 484 ms 844 KB Output is correct
20 Correct 424 ms 844 KB Output is correct
21 Correct 410 ms 844 KB Output is correct
22 Correct 460 ms 844 KB Output is correct
23 Correct 461 ms 844 KB Output is correct
24 Correct 143 ms 844 KB Output is correct
25 Correct 463 ms 844 KB Output is correct
26 Correct 385 ms 844 KB Output is correct
27 Correct 177 ms 844 KB Output is correct
28 Correct 534 ms 844 KB Output is correct
29 Correct 495 ms 844 KB Output is correct
30 Correct 456 ms 844 KB Output is correct