Submission #44087

# Submission time Handle Problem Language Result Execution time Memory
44087 2018-03-29T21:08:42 Z zadrga Library (JOI18_library) C++14
100 / 100
483 ms 588 KB
#include "library.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

vector<int> here;

int find_first(int n){
	vector<int> q(n, 1);

	for(int i = 0; i < n; i++){
		q[i] = 0;
		int num = Query(q);
		if(num == 1){
			here.erase(find(here.begin(), here.end(), i));
			return i;
		}
		q[i] = 1;
	}
}

bool ask(int n, int l, int d, int last){
	vector<int> q(n, 0);
	for(int i = l; i <= d; i++)
		q[here[i]] = 1;

	int alone = Query(q);

	q[last] = 1; 
	int together = Query(q);

	if(alone == together)		// next is in range [l, d]
		return 1;
	
	return 0;
}

int find_next(int n, int last){
	int l = 0, d = here.size() - 1, ans = -1, mid;
	while(l <= d){
		if(l == d){
			ans = l;
			break;
		}

		mid = (l + d) / 2;
		if(ask(n, l, mid, last))
			d = mid;
		else
			l = mid + 1;
	}

	int ret = here[ans];
	here.erase(find(here.begin(), here.end(), ret));
	return ret;
}

void Solve(int n){
	vector<int> ans;

	if(n == 1){
		ans.pb(1);
		Answer(ans);
		return;
	}

	for(int i = 0; i < n; i++)
		here.pb(i);

	int last = find_first(n);
	ans.pb(last);

	while(here.size() > 1){
		int nxt = find_next(n, last);
		ans.pb(nxt);
		last = nxt;
	}

	ans.pb(here[0]);
	
	for(int i = 0; i < n; i++)
		ans[i]++;

	Answer(ans);
}

Compilation message

library.cpp: In function 'int find_first(int)':
library.cpp:31:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 40 ms 248 KB Output is correct
2 Correct 34 ms 308 KB Output is correct
3 Correct 36 ms 384 KB Output is correct
4 Correct 58 ms 420 KB Output is correct
5 Correct 37 ms 468 KB Output is correct
6 Correct 37 ms 496 KB Output is correct
7 Correct 40 ms 496 KB Output is correct
8 Correct 39 ms 580 KB Output is correct
9 Correct 41 ms 580 KB Output is correct
10 Correct 21 ms 580 KB Output is correct
11 Correct 2 ms 580 KB Output is correct
12 Correct 2 ms 580 KB Output is correct
13 Correct 2 ms 580 KB Output is correct
14 Correct 2 ms 580 KB Output is correct
15 Correct 3 ms 580 KB Output is correct
16 Correct 4 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 248 KB Output is correct
2 Correct 34 ms 308 KB Output is correct
3 Correct 36 ms 384 KB Output is correct
4 Correct 58 ms 420 KB Output is correct
5 Correct 37 ms 468 KB Output is correct
6 Correct 37 ms 496 KB Output is correct
7 Correct 40 ms 496 KB Output is correct
8 Correct 39 ms 580 KB Output is correct
9 Correct 41 ms 580 KB Output is correct
10 Correct 21 ms 580 KB Output is correct
11 Correct 2 ms 580 KB Output is correct
12 Correct 2 ms 580 KB Output is correct
13 Correct 2 ms 580 KB Output is correct
14 Correct 2 ms 580 KB Output is correct
15 Correct 3 ms 580 KB Output is correct
16 Correct 4 ms 580 KB Output is correct
17 Correct 456 ms 588 KB Output is correct
18 Correct 435 ms 588 KB Output is correct
19 Correct 405 ms 588 KB Output is correct
20 Correct 401 ms 588 KB Output is correct
21 Correct 387 ms 588 KB Output is correct
22 Correct 483 ms 588 KB Output is correct
23 Correct 439 ms 588 KB Output is correct
24 Correct 153 ms 588 KB Output is correct
25 Correct 386 ms 588 KB Output is correct
26 Correct 399 ms 588 KB Output is correct
27 Correct 156 ms 588 KB Output is correct
28 Correct 482 ms 588 KB Output is correct
29 Correct 452 ms 588 KB Output is correct
30 Correct 450 ms 588 KB Output is correct