제출 #497652

#제출 시각아이디문제언어결과실행 시간메모리
497652MilosMilutinovicLibrary (JOI18_library)C++14
100 / 100
855 ms4396 KiB
#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 = 0;
	for (int i = 0; i < n; i++) {
		if (graf[i].size() == 1) {
			rt = i;
		}
	}

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

	Answer(answer);
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...