답안 #446018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446018 2021-07-20T13:36:45 Z flappybird 도서관 (JOI18_library) C++14
19 / 100
692 ms 440 KB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
typedef int ll;

vector<ll> asdf;
vector<ll> chk;
vector<ll> p, e;
ll n;

void randp(ll N) {
	p.resize(N);
	ll i;
	for (i = 0; i < N; i++) p[i] = i + 1;
	for (i = 1; i <= N; i++) {
		ll a, b;
		a = rand() % N;
		b = rand() % N;
		swap(p[a], p[b]);
	}
}

ll query(vector<ll> &v) {
	vector<ll> a;
	a.resize(n);
	for (auto x : v) a[x - 1] = 1;
	return Query(a);
}

void Solve(int N) {
	n = N;
	srand(time(NULL));
	chk.resize(N + 1);
	ll i, a;
	ll sz = N;
	for (a = 1; a <= N; a++) {
		asdf.clear();
		for (ll i = 1; i <= N; i++) if (!chk[i]) asdf.push_back(i);
		sz = asdf.size();
		if (asdf.size() <= 2) {
			e.push_back(asdf[0]);
			chk[asdf[0]] = 1;
			continue;
		}
		start:
		vector<ll> q1, q2;
		do {
			randp(sz);
			q1.clear();
			q2.clear();
			for (i = 0; i < sz; i++) {
				if (p[i] <= sz / 2) q1.push_back(asdf[i]);
				else q2.push_back(asdf[i]);
			}
		} while ((query(q1) + query(q2)) % 2);
		ll l, r;
		l = 0, r = q1.size() - 1;
		vector<ll> v1, v2;
		while (l < r) {
			v1 = q1;
			v2 = q2;
			ll mid = (l + r) / 2;
			for (ll k = mid + 1; k < q1.size(); k++) v2.push_back(v1[k]);
			for (ll k = mid + 1; k < q1.size(); k++) v1.pop_back();
			if ((query(v1) + query(v2)) % 2) l = mid + 1;
			else r = mid;
		}
		e.push_back(q1[r]);
		chk[q1[r]] = 1;
	}
	deque<ll> d;
	for (i = N - 1; i >= 0; i--) {
		if (d.empty()) {
			d.push_back(e[i]);
			continue;
		}
		ll b = d.back();
		vector<ll> v;
		v.push_back(b);
		v.push_back(e[i]);
		if (query(v) == 1) d.push_back(e[i]);
		else d.push_front(e[i]);
	}
	vector<ll> ans;
	while (!d.empty()) {
		ans.push_back(d.back());
		d.pop_back();
	}
	Answer(ans);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:63:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |    for (ll k = mid + 1; k < q1.size(); k++) v2.push_back(v1[k]);
      |                         ~~^~~~~~~~~~~
library.cpp:64:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |    for (ll k = mid + 1; k < q1.size(); k++) v1.pop_back();
      |                         ~~^~~~~~~~~~~
library.cpp:45:3: warning: label 'start' defined but not used [-Wunused-label]
   45 |   start:
      |   ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 292 KB # of queries: 2919
2 Correct 63 ms 304 KB # of queries: 2980
3 Correct 50 ms 296 KB # of queries: 3049
4 Correct 59 ms 308 KB # of queries: 3109
5 Correct 43 ms 288 KB # of queries: 3041
6 Correct 61 ms 300 KB # of queries: 3011
7 Correct 52 ms 304 KB # of queries: 3009
8 Correct 51 ms 300 KB # of queries: 2970
9 Correct 67 ms 300 KB # of queries: 3156
10 Correct 33 ms 200 KB # of queries: 1808
11 Correct 0 ms 200 KB # of queries: 0
12 Correct 1 ms 200 KB # of queries: 1
13 Correct 1 ms 200 KB # of queries: 4
14 Correct 1 ms 200 KB # of queries: 9
15 Correct 2 ms 200 KB # of queries: 116
16 Correct 5 ms 272 KB # of queries: 232
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 292 KB # of queries: 2919
2 Correct 63 ms 304 KB # of queries: 2980
3 Correct 50 ms 296 KB # of queries: 3049
4 Correct 59 ms 308 KB # of queries: 3109
5 Correct 43 ms 288 KB # of queries: 3041
6 Correct 61 ms 300 KB # of queries: 3011
7 Correct 52 ms 304 KB # of queries: 3009
8 Correct 51 ms 300 KB # of queries: 2970
9 Correct 67 ms 300 KB # of queries: 3156
10 Correct 33 ms 200 KB # of queries: 1808
11 Correct 0 ms 200 KB # of queries: 0
12 Correct 1 ms 200 KB # of queries: 1
13 Correct 1 ms 200 KB # of queries: 4
14 Correct 1 ms 200 KB # of queries: 9
15 Correct 2 ms 200 KB # of queries: 116
16 Correct 5 ms 272 KB # of queries: 232
17 Correct 692 ms 364 KB # of queries: 19981
18 Correct 655 ms 320 KB # of queries: 19794
19 Runtime error 669 ms 440 KB Execution killed with signal 13
20 Halted 0 ms 0 KB -