Submission #497651

# Submission time Handle Problem Language Result Execution time Memory
497651 2021-12-23T13:01:28 Z MilosMilutinovic Library (JOI18_library) C++14
0 / 100
36 ms 1048 KB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;

const int maxn = 1005;

int n, adj[maxn][maxn];
vector<int> graf[maxn];

int query(int l, int r) {
	vector<int> vec(n);
	for (int i = l; i <= r; i++)
		vec[i] = 1;
	return Query(vec);
}

int Count(int l, int r) {
	int cnt = 0;
	for (int i = l; i <= r; ++i)
		for (int j = i + 1; j <= r; ++j)
			cnt += adj[i][j];
	return r - l + 1 - cnt;
}

void Solve(int N) {
	n = N;
	vector<pair<int, int>> edges;
	for (int i = 1; i < n; ++i) {
		int new_edges = Count(0, i) - query(0, i);

		for (int rep = 0; rep < new_edges; ++rep) {
			int low = 0, high = i - 1, pos = -1;
			while (low <= high) {
				int mid = low + high >> 1;
				if (query(mid, i) != Count(mid, i)) {
					pos = mid;
					low = mid + 1;
				} else {
					high = mid - 1;
				}
			}
			adj[i][pos] = adj[pos][i] = 1;
			edges.push_back({i, pos});
			assert(pos != -1);
		}
	}

	for (auto e : edges) {
		graf[e.first].push_back(e.second);
		graf[e.second].push_back(e.first);
	}

	vector<int> answer;
	function<void(int, int)> Dfs = [&](int u, int fa) {
		answer.push_back(u + 1);
		for (int v : graf[u]) {
			if (v == fa) continue;
			Dfs(v, u);
		}
	};

	int rt = -1;
	for (int i = 0; i < n; i++) {
		if (graf[i].size() == 1) {
			rt = i;
		}
	}

	assert(rt != -1);
	Dfs(rt, rt);

	Answer(answer);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:34:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |     int mid = low + high >> 1;
      |               ~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1000 KB # of queries: 1521
2 Correct 26 ms 940 KB # of queries: 1520
3 Correct 28 ms 1004 KB # of queries: 1591
4 Correct 32 ms 1048 KB # of queries: 1590
5 Correct 31 ms 1028 KB # of queries: 1596
6 Correct 34 ms 1024 KB # of queries: 1600
7 Correct 36 ms 1028 KB # of queries: 1587
8 Correct 28 ms 1036 KB # of queries: 1517
9 Correct 32 ms 992 KB # of queries: 1595
10 Correct 17 ms 808 KB # of queries: 949
11 Runtime error 1 ms 456 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1000 KB # of queries: 1521
2 Correct 26 ms 940 KB # of queries: 1520
3 Correct 28 ms 1004 KB # of queries: 1591
4 Correct 32 ms 1048 KB # of queries: 1590
5 Correct 31 ms 1028 KB # of queries: 1596
6 Correct 34 ms 1024 KB # of queries: 1600
7 Correct 36 ms 1028 KB # of queries: 1587
8 Correct 28 ms 1036 KB # of queries: 1517
9 Correct 32 ms 992 KB # of queries: 1595
10 Correct 17 ms 808 KB # of queries: 949
11 Runtime error 1 ms 456 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -