Submission #344056

# Submission time Handle Problem Language Result Execution time Memory
344056 2021-01-05T05:09:28 Z tengiz05 Library (JOI18_library) C++17
19 / 100
438 ms 660 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<vector<int>> v(n);
	int number_of_queries_asked = 0;
	for(int i=0;i<n;i++){
		if(v[i].size() == 2)continue;
		vector<int> ask(n, 0);
		ask[i] = 1;
		for(int j=i+1;j<n;j++){
			if(v[j].size() == 2 || v[i].size() == 2)continue;
			ask[j] = 1;
			if(Query(ask) == 1)v[i].push_back(j), v[j].push_back(i);
			ask[j] = 0;
			number_of_queries_asked++;
			if(number_of_queries_asked == 19998)assert(false);
		}
	}
	//~ 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

*/
# Verdict Execution time Memory Grader output
1 Correct 110 ms 364 KB # of queries: 8277
2 Correct 106 ms 364 KB # of queries: 8239
3 Correct 146 ms 364 KB # of queries: 9230
4 Correct 141 ms 384 KB # of queries: 9178
5 Correct 165 ms 384 KB # of queries: 9216
6 Correct 114 ms 384 KB # of queries: 8800
7 Correct 151 ms 496 KB # of queries: 9069
8 Correct 104 ms 384 KB # of queries: 8272
9 Correct 169 ms 384 KB # of queries: 9253
10 Correct 62 ms 380 KB # of queries: 3883
11 Correct 1 ms 364 KB # of queries: 0
12 Correct 0 ms 364 KB # of queries: 1
13 Correct 0 ms 364 KB # of queries: 3
14 Correct 1 ms 512 KB # of queries: 5
15 Correct 2 ms 364 KB # of queries: 57
16 Correct 3 ms 512 KB # of queries: 210
# Verdict Execution time Memory Grader output
1 Correct 110 ms 364 KB # of queries: 8277
2 Correct 106 ms 364 KB # of queries: 8239
3 Correct 146 ms 364 KB # of queries: 9230
4 Correct 141 ms 384 KB # of queries: 9178
5 Correct 165 ms 384 KB # of queries: 9216
6 Correct 114 ms 384 KB # of queries: 8800
7 Correct 151 ms 496 KB # of queries: 9069
8 Correct 104 ms 384 KB # of queries: 8272
9 Correct 169 ms 384 KB # of queries: 9253
10 Correct 62 ms 380 KB # of queries: 3883
11 Correct 1 ms 364 KB # of queries: 0
12 Correct 0 ms 364 KB # of queries: 1
13 Correct 0 ms 364 KB # of queries: 3
14 Correct 1 ms 512 KB # of queries: 5
15 Correct 2 ms 364 KB # of queries: 57
16 Correct 3 ms 512 KB # of queries: 210
17 Runtime error 438 ms 660 KB Execution killed with signal 6 (could be triggered by violating memory limits)
18 Halted 0 ms 0 KB -