답안 #67765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67765 2018-08-15T09:40:14 Z reality Park (JOI17_park) C++17
0 / 100
197 ms 1032 KB
#include "park.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define vii vector < pii >
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}

static const int N = 2048;

static int n;

static int mark[N];

static int get(int a,int b,vi v) {
	if (a > b)
		swap(a,b);
	if (!v[a] || !v[b])
		return 0;
	return Ask(a,b,v.data());
}

static int Go(int a,int b,vi w,vi was) {
	const int sz = w.size();
	int l = 0,r = sz;
	while (l < r) {
		int m = (l + r) / 2;
		for (int i = 0;i < m;++i)
			was[w[i]] = 1;
		for (int i = m;i < sz;++i)
			was[w[i]] = 0;
		if (get(a,b,was))
			r = m;
		else
			l = m + 1;
	}
	if (!l)
		return -1;
	for (int i = 0;i < l;++i)
		was[w[i]] = 1;
	for (int i = l;i < sz;++i)
		was[w[i]] = 0;
	if (!get(a,b,was))
		return -1;
	return w[l - 1];
}

set < int > G[N];

void add_edge(int A,int B) {
	if (A > B)
		swap(A,B);
	Answer(A,B);
	G[A].insert(B);
	G[B].insert(A);
}

vi order;

int W[N];

vi w;

void dfs(int v) {
	order.pb(v);
	W[v] = 1;
	for (auto it : G[v])
		if (!W[it] && w[it])
			dfs(it);
}

void del(int v) {
	w[v] = 0;
	for (auto it : G[v])
		if (w[it])
			del(it);
}

void find_edges(int node) {
	mark[node] = 1;
	w.resize(n);
	for (int i = 0;i < n;++i)
		w[i] = mark[i];
	for (int i = 0;i < n;++i)
		if (i != node && w[i]) {
			if (get(node,i,w)) {
				order.clear();
				for (int j = 0;j < n;++j)
					W[j] = w[j];
				W[i] = 1;
				dfs(i);
				vi was(n,0);
				do {
					vi was(n,0);
					was[node] = 1;
					int g = Go(node,i,order,was);
					if (g != -1)
						add_edge(node,g);
					while (!order.empty() && order.back() != g)
						order.pop_back();
					if (!order.empty() && order.back() == g)
						order.pop_back();
				} while (!order.empty());
			} else {
				del(i);
			}
		}
}

static void Next(int node) {
	set < int > ss;
	vi was(n,0);
	for (int i = 0;i < n;++i)
		if (!mark[i] && i != node)
			ss.insert(i);
		else
			was[i] = 1;
	vi nxt;
	do {
		nxt.pb(node);
		int poss = Go(0,node,vi(all(ss)),was);
		if (poss != -1) {
			node = poss;
			ss.erase(node);
			was[node] = 1;
		} else {
			break;
		}
	} while (1);
	reverse(all(nxt));
	for (auto it : nxt)
		find_edges(it);
}

void Detect(int T, int NN) {
	n = NN;
	mark[0] = 1;
	for (int i = 1;i < n;++i)
		if (!mark[i])
			Next(i);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 75 ms 616 KB Wrong Answer[5]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 127 ms 1032 KB Wrong Answer[5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 197 ms 1032 KB Wrong Answer[5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 167 ms 1032 KB Wrong Answer[5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 191 ms 1032 KB Wrong Answer[5]
2 Halted 0 ms 0 KB -