Submission #954569

# Submission time Handle Problem Language Result Execution time Memory
954569 2024-03-28T07:14:07 Z Sharky Library (JOI18_library) C++17
19 / 100
2000 ms 712 KB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
 
random_device rd;
mt19937 g(rd());
int outn, qc = 0;

void TLE() {
	TLE();
}
 
int query(vector<int>& v) {
	qc++;
	if (qc > 20000) TLE();
	vector<int> vt(outn, 0);
	for (auto x : v) vt[x - 1] = 1;
	v.clear();
	return Query(vt);
}
 
vector<int> adj[1001], ans;
 
void dfs(int u, int p = -1) {
	ans.push_back(u);
	for (int v : adj[u]) if (v != p) dfs(v, u);
}
 
void Solve(int n) {
	if (n == 1) {
		ans = {1};
		Answer(ans);
		return;
	}
	outn = n;
	vector<int> ee;
	vector<int> deg(n+1, 2), cand, vt;
	for (int sk = 1; sk <= n; sk++) {
		for (int i = 1; i <= n; i++) if (i != sk) vt.push_back(i);
		if (query(vt) == 1) ee.push_back(sk), deg[sk]--;
		cand.push_back(sk);
	}
	int ender = ee[0], i = ee[0], o = ee[1];
	while (i != o) {
		int sz = cand.size();
		int rt = 20, nxt;
		shuffle(cand.begin(), cand.end(), g);
		vector<int> er;
		for (int j = 0; j < sz; j += rt) {
			for (int k = j; k < min(sz, j + rt); k++) {
				vt.push_back(cand[k]);
				if (cand[k] == i) continue;
			}
			vector<int> vt2 = vt;
			vt2.push_back(i);
			int extra = query(vt2) - query(vt);
			if (extra) continue;
			for (int k = j; k < min(sz, j + rt); k++) {
				if (cand[k] == i) continue;
				vt.push_back(i);
				vt.push_back(cand[k]);
				if (query(vt) == 1) {
					deg[cand[k]]--, deg[i]--;
					adj[cand[k]].push_back(i);
					adj[i].push_back(cand[k]);
					nxt = cand[k];
					if (!deg[cand[k]]) er.push_back(k);
					break;
				}
			}
			if (!deg[i]) break;
		}
		reverse(er.begin(), er.end());
		for (auto x : er) cand.erase(cand.begin() + x);
		for (int j = cand.size() - 1; j >= 0; j--) if (cand[j] == i) {
			cand.erase(cand.begin() + j);
			break;
		}
		i = nxt;
	}
	dfs(ender);
	Answer(ans);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:79:5: warning: 'nxt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   79 |   i = nxt;
      |   ~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 42 ms 472 KB # of queries: 4382
2 Correct 43 ms 452 KB # of queries: 4425
3 Correct 39 ms 480 KB # of queries: 4511
4 Correct 46 ms 712 KB # of queries: 4950
5 Correct 36 ms 708 KB # of queries: 4731
6 Correct 37 ms 704 KB # of queries: 4642
7 Correct 41 ms 708 KB # of queries: 4459
8 Correct 39 ms 708 KB # of queries: 4466
9 Correct 41 ms 476 KB # of queries: 4671
10 Correct 22 ms 464 KB # of queries: 2498
11 Correct 0 ms 344 KB # of queries: 0
12 Correct 0 ms 344 KB # of queries: 5
13 Correct 1 ms 344 KB # of queries: 10
14 Correct 0 ms 344 KB # of queries: 15
15 Correct 1 ms 344 KB # of queries: 103
16 Correct 2 ms 472 KB # of queries: 277
# Verdict Execution time Memory Grader output
1 Correct 42 ms 472 KB # of queries: 4382
2 Correct 43 ms 452 KB # of queries: 4425
3 Correct 39 ms 480 KB # of queries: 4511
4 Correct 46 ms 712 KB # of queries: 4950
5 Correct 36 ms 708 KB # of queries: 4731
6 Correct 37 ms 704 KB # of queries: 4642
7 Correct 41 ms 708 KB # of queries: 4459
8 Correct 39 ms 708 KB # of queries: 4466
9 Correct 41 ms 476 KB # of queries: 4671
10 Correct 22 ms 464 KB # of queries: 2498
11 Correct 0 ms 344 KB # of queries: 0
12 Correct 0 ms 344 KB # of queries: 5
13 Correct 1 ms 344 KB # of queries: 10
14 Correct 0 ms 344 KB # of queries: 15
15 Correct 1 ms 344 KB # of queries: 103
16 Correct 2 ms 472 KB # of queries: 277
17 Execution timed out 3022 ms 480 KB Time limit exceeded
18 Halted 0 ms 0 KB -