답안 #112833

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
112833 2019-05-22T06:34:19 Z ckodser Amusement Park (JOI17_amusement_park) C++14
0 / 100
28 ms 4004 KB
#include<bits/stdc++.h>
#include "Joi.h"
#define pb push_back
using namespace std;
const int MXN = 12345;
vector < int > Adj[MXN];
void Joi(int N, int M, int A[], int B[], long long X, int T)
{
	for (int i = 0; i < M; i++)
		Adj[A[i]].pb(B[i]), Adj[B[i]].pb(A[i]);
	vector < int > D(N, -1);
	vector < int > P(N, -1);
	vector < int > qu(N, 0);
	int l = 0, r = 0;
	qu[r ++] = 0; D[0] = 0;
	bool OK = 0;
	while (r - l)
	{
		int v = qu[l ++];
		if (D[v] == 59)
			OK = 1;
		for (int &u : Adj[v])
			if (D[u] == -1)
				D[u] = (D[v] + 1) % 60, P[u] = v, qu[r ++] = u;
	}
	if (OK)
	{
		for (int i = 0; i < N; i++)
			MessageBoard(i, (X >> D[i]) & 1LL);
		return ;
	}
	vector < int > F(N, -1);
	vector < int > rev(N, -1);
	for (int i = 0; i < N; i++)
		rev[qu[i]] = i;
	for (int i = 0; i < 60; i++)
		MessageBoard(qu[i], (X >> i) & 1LL), F[qu[i]] = i;
	for (int i = 60; i < N; i++)
	{
		int v = qu[i];
		vector < int > Mark(60, 0);
		for (int p = P[v]; p >= 0; p = P[p])
			Mark[F[p]] = 1;
		F[v] = 59;
		while (Mark[F[v]])
			F[v] --;
		MessageBoard(v, (X >> F[v]) & 1LL);
	}
	return ;
}
#include<bits/stdc++.h>
#include "Ioi.h"
#define pb push_back
using namespace std;
const int MXN = 12345;
bool toSee[MXN], seen[MXN];
vector < int > vec, Adj[MXN];
void DFS(int v)
{
	seen[v] = 1;
	for (int &u : Adj[v])
		if (!seen[u] && toSee[u])
		{
			vec.pb(u);
			DFS(u);
			vec.pb(v);
		}
}
long long Ioi(int N, int M, int A[], int B[], int ST, int VL, int T)
{
	for (int i = 0; i < M; i++)
		Adj[A[i]].pb(B[i]), Adj[B[i]].pb(A[i]);
	vector < int > D(N, -1);
	vector < int > qu(N, 0);
	vector < int > P(N, -1);
	int l = 0, r = 0;
	qu[r ++] = 0; D[0] = 0;
	bool OK = 0;
	while (r - l)
	{
		int v = qu[l ++];
		if (D[v] % 60 == 59)
			OK = 1;
		for (int &u : Adj[v])
			if (D[u] == -1)
				D[u] = D[v] + 1, P[u] = v, qu[r ++] = u;
	}
	if (OK)
	{
		l = r = 0;
		vector < int > F(N, -1);
		for (int i = 0; i < N; i++)
			if (D[i] % 60 == 59)
				qu[r ++] = i, F[i] = i;
		while (r - l)
		{
			int v = qu[l ++];
			if (D[v] == 0)
				continue;
			for (int &u : Adj[v])
				if (D[u] == D[v] - 1 && F[u] == -1)
					qu[r ++] = u, F[u] = v;
		}
		if (D[ST] >= 59)
		{
			long long X = 0;
			for (int i = 0; i < 60; i++)
			{
				X |= (1LL * VL) << (D[ST] % 60);
				ST = P[ST]; VL = Move(ST);
			}
			return (X);
		}
		long long X = 0;
		while (ST != 0)
			ST = P[ST], VL = Move(ST);
		for (int i = 0; i < 60; i++)
		{
			X |= (1LL * VL) << (D[ST] % 60);
			ST = F[ST]; VL = Move(ST);
		}
		return (X);
	}
	vector < int > F(N, -1);
	vector < int > rev(N, -1);
	for (int i = 0; i < N; i++)
		rev[qu[i]] = i;
	for (int i = 0; i < 60; i++)
		F[qu[i]] = i;
	for (int i = 60; i < N; i++)
	{
		int v = qu[i];
		vector < int > Mark(60, 0);
		for (int p = P[v]; p >= 0; p = P[p])
			Mark[F[p]] = 1;
		F[v] = 59;
		while (Mark[F[v]])
			F[v] --;
	}
	long long X = 0;
	for (int i = 0; i < 60; i++)
		toSee[qu[i]] = 1;
	while (ST != 0)
	{
		X |= (1LL * VL) << (D[ST] % 60);
		toSee[qu[D[ST] % 60]] = 0;
		ST = P[ST]; VL = Move(ST);
	}
	X |= VL;
	DFS(0);
	for (int v : vec)
	{
		ST = v; VL = Move(ST);
		X |= (1LL * VL) << (D[ST] % 60);
	}
	return (X);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1444 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 3856 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1408 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 4004 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 3856 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -