Submission #58172

# Submission time Handle Problem Language Result Execution time Memory
58172 2018-07-17T05:30:09 Z khsoo01 Library (JOI18_library) C++11
100 / 100
700 ms 956 KB
#include "library.h"
#include<bits/stdc++.h>
using namespace std;

const int N = 1005;

int n;
bool chk[N];

vector<int> cp[N], qry;

void Solve(int _N)
{
	n = _N;
	for(int i=0;i<n;i++) {
		cp[i].push_back(i);
		qry.push_back(0);
	}
	for(int k=0;k<n-1;k++) {
		int S = 2, E = n-k, P, Q;
		while(S<E) {
			int M = (S+E)/2;
			for(int i=0;i<n;i++) {
				qry[i] = 0;
			}
			for(int i=0,j=0;j<M;i++) {
				if(chk[i]) continue;
				j++;
				for(auto &T : cp[i]) {
					qry[T] = true;
				}
			}
			Query(qry) != M ? E = M : S = M+1;
		}
		for(int i=0,j=0;j<S;i++) {
			if(chk[i]) continue;
			j++;
			Q = i;
		}
		E = S;
		S = 2;
		while(S<E) {
			int M = (S+E)/2;
			for(int i=0;i<n;i++) {
				qry[i] = 0;
			}
			for(int i=Q,j=0;j<M;i--) {
				if(chk[i]) continue;
				j++;
				for(auto T : cp[i]) {
					qry[T] = true;
				}
			}
			Query(qry) != M ? E = M : S = M+1;
		}
		for(int i=Q,j=0;j<S;i--) {
			if(chk[i]) continue;
			j++;
			P = i;
		}
		for(int i=0;i<n;i++) {
			qry[i] = 0;
		}
		for(auto &T : cp[P]) {
			qry[T] = 1;
		}
		qry[cp[Q][0]] = 1;
		if(Query(qry) != 1) reverse(cp[Q].begin(), cp[Q].end());
		for(int i=0;i<n;i++) {
			qry[i] = 0;
		}
		for(auto &T : cp[Q]) {
			qry[T] = 1;
		}
		qry[cp[P].back()] = 1;
		if(Query(qry) != 1) reverse(cp[P].begin(), cp[P].end());
		for(auto &T : cp[Q]) {
			cp[P].push_back(T);
		}
		cp[Q].clear();
		chk[Q] = true;
	}
	for(auto &T : cp[0]) {
		T++;
	}
	Answer(cp[0]);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:20:26: warning: 'Q' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int S = 2, E = n-k, P, Q;
                          ^
# Verdict Execution time Memory Grader output
1 Correct 60 ms 376 KB Output is correct
2 Correct 53 ms 464 KB Output is correct
3 Correct 45 ms 464 KB Output is correct
4 Correct 32 ms 536 KB Output is correct
5 Correct 30 ms 564 KB Output is correct
6 Correct 52 ms 588 KB Output is correct
7 Correct 51 ms 588 KB Output is correct
8 Correct 57 ms 596 KB Output is correct
9 Correct 68 ms 596 KB Output is correct
10 Correct 27 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 6 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 376 KB Output is correct
2 Correct 53 ms 464 KB Output is correct
3 Correct 45 ms 464 KB Output is correct
4 Correct 32 ms 536 KB Output is correct
5 Correct 30 ms 564 KB Output is correct
6 Correct 52 ms 588 KB Output is correct
7 Correct 51 ms 588 KB Output is correct
8 Correct 57 ms 596 KB Output is correct
9 Correct 68 ms 596 KB Output is correct
10 Correct 27 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 6 ms 596 KB Output is correct
17 Correct 625 ms 880 KB Output is correct
18 Correct 700 ms 880 KB Output is correct
19 Correct 519 ms 880 KB Output is correct
20 Correct 673 ms 880 KB Output is correct
21 Correct 550 ms 880 KB Output is correct
22 Correct 690 ms 880 KB Output is correct
23 Correct 681 ms 880 KB Output is correct
24 Correct 193 ms 880 KB Output is correct
25 Correct 532 ms 956 KB Output is correct
26 Correct 462 ms 956 KB Output is correct
27 Correct 206 ms 956 KB Output is correct
28 Correct 400 ms 956 KB Output is correct
29 Correct 395 ms 956 KB Output is correct
30 Correct 364 ms 956 KB Output is correct