답안 #344045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
344045 2021-01-05T05:03:16 Z tengiz05 도서관 (JOI18_library) C++17
19 / 100
339 ms 636 KB
#include <bits/stdc++.h>
#include "library.h"
//~ #include "grader.cpp"
using namespace std;
void Solve(int n){
	if(n == 1){
		vector<int> ans = {1};
		Answer(ans);
		return;
	}
	vector<int> haha(n,0);
	for(int i=0;i<n;i++)haha[i] = i;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int seed_for = uniform_int_distribution<int>(0,1000000000)(rng);
	shuffle(haha.begin(), haha.end(), default_random_engine(seed_for));
	vector<vector<int>> v(n);
	for(int i=0;i<n;i++){
		int I = haha[i];
		if(v[I].size() == 2)continue;
		vector<int> ask(n, 0);
		ask[I] = 1;
		for(int j=i+1;j<n;j++){
			int J = haha[j];
			if(v[J].size() == 2)continue;
			ask[J] = 1;
			if(Query(ask) == 1)v[I].push_back(J), v[J].push_back(I);
			ask[J] = 0;
		}
	}
	//~ for(int i=0;i<n;i++){for(auto x : v[i])cout << x << ' ';cout << '\n';}
	vector<bool> used(n);
	vector<int> ans;
	int u=-1;
	for(int i=0;i<n;i++){
		if(v[i].size() == 1){
			u = i;break;
		}
	}
	assert(u != -1);
	while(true){
		bool ch = false;
		used[u] = true;
		ans.push_back(u+1);
		for(auto to : v[u]){
			if(!used[to]){
				ch=true;
				u=to;
			}
		}if(!ch)break;
	}
	Answer(ans);
	return;
}

/*

5
4 2 5 3 1

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 173 ms 492 KB # of queries: 13643
2 Correct 178 ms 492 KB # of queries: 13216
3 Correct 193 ms 364 KB # of queries: 14142
4 Correct 193 ms 620 KB # of queries: 14550
5 Correct 227 ms 512 KB # of queries: 15151
6 Correct 212 ms 492 KB # of queries: 14792
7 Correct 216 ms 364 KB # of queries: 15059
8 Correct 182 ms 364 KB # of queries: 13420
9 Correct 200 ms 364 KB # of queries: 14483
10 Correct 88 ms 636 KB # of queries: 5939
11 Correct 1 ms 364 KB # of queries: 0
12 Correct 0 ms 364 KB # of queries: 1
13 Correct 1 ms 364 KB # of queries: 3
14 Correct 1 ms 364 KB # of queries: 5
15 Correct 2 ms 364 KB # of queries: 80
16 Correct 3 ms 376 KB # of queries: 311
# 결과 실행 시간 메모리 Grader output
1 Correct 173 ms 492 KB # of queries: 13643
2 Correct 178 ms 492 KB # of queries: 13216
3 Correct 193 ms 364 KB # of queries: 14142
4 Correct 193 ms 620 KB # of queries: 14550
5 Correct 227 ms 512 KB # of queries: 15151
6 Correct 212 ms 492 KB # of queries: 14792
7 Correct 216 ms 364 KB # of queries: 15059
8 Correct 182 ms 364 KB # of queries: 13420
9 Correct 200 ms 364 KB # of queries: 14483
10 Correct 88 ms 636 KB # of queries: 5939
11 Correct 1 ms 364 KB # of queries: 0
12 Correct 0 ms 364 KB # of queries: 1
13 Correct 1 ms 364 KB # of queries: 3
14 Correct 1 ms 364 KB # of queries: 5
15 Correct 2 ms 364 KB # of queries: 80
16 Correct 3 ms 376 KB # of queries: 311
17 Runtime error 339 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
18 Halted 0 ms 0 KB -