답안 #67845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67845 2018-08-15T11:01:44 Z reality Park (JOI17_park) C++17
0 / 100
215 ms 1120 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];

int called = 0;

static int get(int a,int b,vi v) {
	if (a > b)
		swap(a,b);
	if (!v[a] || !v[b])
		return 0;
	++called;
	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;
	int Last = -1;
	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;
		Last = get(a,b,was);
		if (Last)
			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)
		while (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);
				was[node] = 1;
				int g = Go(node,i,order,was);
				if (g != -1)
					add_edge(node,g),w[g] = 0;
				else {
					break;
				}
			} 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 {
		int poss = Go(0,node,vi(all(ss)),was);
		if (poss != -1) {
			nxt.pb(poss);
			ss.erase(poss);
			was[poss] = 1;
		} else {
			break;
		}
	} while (1);
	nxt.pb(node);
	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 2 ms 504 KB Output is correct
2 Correct 72 ms 620 KB Output is correct
3 Correct 63 ms 784 KB Output is correct
4 Correct 136 ms 784 KB Output is correct
5 Incorrect 176 ms 816 KB Wrong Answer[5]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 108 ms 980 KB Wrong Answer[5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 214 ms 1120 KB Wrong Answer[5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 162 ms 1120 KB Wrong Answer[5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 215 ms 1120 KB Wrong Answer[5]
2 Halted 0 ms 0 KB -