답안 #375062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
375062 2021-03-09T02:00:12 Z Kevin_Zhang_TW Meetings (JOI19_meetings) C++17
0 / 100
396 ms 620 KB
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l) == r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif 
const int MAX_N = 300010;
// function : Query(a, b, c)
// function : Bridge(a, b)
random_device rd;
//mt19937 gen(rd());
mt19937 gen;

#define qry Query

vector<pair<int,int>> res;

void solve(vector<int> ids) {
	if (ids.size() <= 1) return;
	if (ids.size() == 2) {
		res.pb(ids[0], ids[1]);
		return;
	}
	shuffle(AI(ids), gen);
	int a = ids[0], b = ids[1];
	map<int, vector<int>> subtree;

	vector<int> sorted;

	for (int i = 2;i < ids.size();++i) {
		int x = ids[i], anc = qry(a, b, x);
		DE(a, b, x, anc);
		subtree[anc].pb(x);
		if (anc != a && anc != b)
			sorted.pb(anc);
	}
	for (auto [_, sid] : subtree)
		solve(sid);

	sort(AI(sorted));
	sorted.erase(unique(AI(sorted)), end(sorted));

	int root = a;

	set<pair<int,int>> vis;
	auto cmp = [&](int a, int b) {
		if (vis.count({a, b})) return true;
		if (vis.count({b, a})) return false;
		int mid = qry(root, a, b);
		vis.insert({mid, a + b - mid});
		return mid == a;
	};

	stable_sort(AI(sorted), cmp);

//	DE(a, b);
//	cerr << "All\n";
//
//	debug(AI(ids));
//
//
//	cerr << "sorted\n";
//	debug(AI(sorted));

	int lst = root;

	for (int u : sorted) {
		//DE(lst, u);
		res.pb(lst, u), lst = u;
	}

	res.pb(lst, b);
}
void Solve(int N) {
	vector<int> ids(N); iota(AI(ids), 0);

	solve(ids);

	for (auto &[a, b] : res) {
		if (a > b) swap(a, b);
		DE(a, b);
		Bridge(a, b);
	}
}

Compilation message

meetings.cpp: In function 'void solve(std::vector<int>)':
meetings.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i = 2;i < ids.size();++i) {
      |                 ~~^~~~~~~~~~~~
meetings.cpp:15:17: warning: statement has no effect [-Wunused-value]
   15 | #define DE(...) 0
      |                 ^
meetings.cpp:43:3: note: in expansion of macro 'DE'
   43 |   DE(a, b, x, anc);
      |   ^~
meetings.cpp: In function 'void Solve(int)':
meetings.cpp:15:17: warning: statement has no effect [-Wunused-value]
   15 | #define DE(...) 0
      |                 ^
meetings.cpp:92:3: note: in expansion of macro 'DE'
   92 |   DE(a, b);
      |   ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 396 ms 620 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -