답안 #242840

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242840 2020-06-29T11:11:33 Z tonowak CEOI16_icc (CEOI16_icc) C++14
40 / 100
243 ms 640 KB
#include <bits/stdc++.h> // Tomasz Nowak
#include "icc.h"
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates

int query(vector<int> a, vector<int> b) {
	int ta[size(a)], tb[size(b)];
	REP(i, size(a))
		ta[i] = a[i] + 1;
	REP(i, size(b))
		tb[i] = b[i] + 1;
	return query(size(a), size(b), ta, tb);
}

vector<int> collapse(vector<vector<int>> v) {
	vector<int> ret;
	for(auto &vec : v)
		for(int x : vec)
			ret.emplace_back(x);
	return ret;
}

int query(vector<vector<int>> a, vector<vector<int>> b) {
	return query(collapse(a), collapse(b));
}

template<class T>
pair<T, T> split_half(T a) {
	T left, right;
	REP(i, size(a))
		if(i % 2)
			right.emplace_back(a[i]);
		else
			left.emplace_back(a[i]);
	return {left, right};
}

template<class T>
T find(T a, T b) {
	while(size(a) != 1 or size(b) != 1) {
		debug(a, b);
		if(size(a) < size(b))
			swap(a, b);
		auto [left, right] = split_half(a);
		if(query(left, b))
			a = left;
		else
			a = right;
	}
	return {a[0], b[0]};
}

template<class T>
T find(T a) {
	while(true) {
		shuffle(a.begin(), a.end(), rng);
		auto [left, right] = split_half(a);
		debug(left, right);
		if(query(left, right))
			return find(left, right);
	}
}

void run(int n) {
	vector<int> lead(n);
	iota(lead.begin(), lead.end(), 0);

	function<int (int)> find_leader = [&](int v) {
		if(v == lead[v])
			return v;
		return lead[v] = find_leader(lead[v]);
	};

	REP(edge, n - 1) {
		vector<vector<int>> in_lead(n);
		REP(v, n)
			in_lead[find_leader(v)].emplace_back(v);

		vector<vector<int>> components;
		REP(v, n)
			if(lead[v] == v)
				components.emplace_back(in_lead[v]);

		for(auto &v : components)
			shuffle(v.begin(), v.end(), rng);

		auto ret1 = find(components);
		auto ret = find(ret1[0], ret1[1]);
		int v = ret[0],
			u = ret[1];
		debug(v, u);
		setRoad(v + 1, u + 1);
		lead[find_leader(v)] = find_leader(u);
	}
}

Compilation message

icc.cpp: In function 'T find(T, T)':
icc.cpp:74:8: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
   auto [left, right] = split_half(a);
        ^
icc.cpp: In function 'T find(T)':
icc.cpp:87:8: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
   auto [left, right] = split_half(a);
        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 512 KB Ok! 112 queries used.
2 Correct 13 ms 512 KB Ok! 109 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 512 KB Ok! 670 queries used.
2 Correct 73 ms 584 KB Ok! 818 queries used.
3 Correct 78 ms 632 KB Ok! 833 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 196 ms 512 KB Ok! 1826 queries used.
2 Correct 243 ms 512 KB Ok! 2097 queries used.
3 Correct 214 ms 632 KB Ok! 2051 queries used.
4 Correct 217 ms 640 KB Ok! 2044 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 632 KB Ok! 1981 queries used.
2 Incorrect 217 ms 512 KB Too many queries! 2033 out of 2000
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 228 ms 632 KB Too many queries! 2029 out of 1775
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 232 ms 632 KB Too many queries! 2050 out of 1625
2 Halted 0 ms 0 KB -