답안 #36003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
36003 2017-12-04T07:47:23 Z cheater2k Amusement Park (JOI17_amusement_park) C++14
10 / 100
39 ms 7292 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;

const int MAX = 10005;

namespace JOI {
	int n, m;
	int pos[MAX];
	int par[MAX];
	int id[MAX];
	bool vis[MAX];
	int ncomp;
	vector<int> comp[MAX];
	vector<int> G[MAX];
	long long X;
	
	void build() {
		vector< pair<int,int> > edges;
		for (int i = 0; i < n; ++i) pos[i] = 0;
		queue <int> q; q.push(0); pos[0] = 1;
	
		while(!q.empty()) {
			int u = q.front(); q.pop();
			for (int v : G[u]) {
				if (!pos[v]) q.push(v), pos[v] = 1, edges.push_back(make_pair(u,v));
			}
		}
		for (int i = 0; i < n; ++i) G[i].clear(), pos[i] = 0;
		for (auto e : edges) G[e.first].push_back(e.second), G[e.second].push_back(e.first);
	}

	void dfs(int u) {
		if (comp[ncomp].size() == 60) return;
		pos[u] = ncomp;
		comp[ncomp].push_back(u);
		for (int v : G[u]) if (!pos[v]) {
			par[v] = u;
			dfs(v);
		}
	}

	void add(int u, int c) {
		if (comp[c].size() == 60) return;
		comp[c].push_back(u);
		vis[u] = 1;
		for (int v : G[u]) {
			if (pos[v] == pos[u] && !vis[v]) add(v, c);
		}
	}

	void prepare() {
		build();
		for (int i = 0; i < n; ++i) if (!pos[i]) ++ncomp, dfs(i);

		for (int i = 1; i <= ncomp; ++i) if (comp[i].size() == 60) {
			for (int j = 0; j < comp[i].size(); ++j) id[comp[i][j]] = j;
		}
		if (comp[ncomp].empty()) --ncomp;
		
		for (int i = 1; i <= ncomp; ++i) {
			if (comp[i].size() < 60) {
				int sz = comp[i].size();
				int root = comp[i][0];
				root = par[root];
				add(root, i);

				long long mask = 0;
				vector<int> rem;
				for (int j = sz; j < 60; ++j) mask |= (1LL << id[comp[i][j]]);
				for (int j = 0; j < 60; ++j) if (!(mask >> j & 1)) rem.push_back(j);
				for (int j = 0; j < sz; ++j) id[comp[i][j]] = rem.back(), rem.pop_back();
				for (int u : comp[i]) vis[u] = false;
			}
		}
	}

	void assign() {
		JOI::prepare();
		for (int i = 0; i < n; ++i) MessageBoard(i, (X >> id[i] & 1));
	}
};

void Joi(int N, int M, int A[], int B[], long long X, int T) {
  JOI::n = N; 
  JOI::m = M;
  JOI::X = X;
  for (int i = 0; i < M; ++i) JOI::G[A[i]].push_back(B[i]), JOI::G[B[i]].push_back(A[i]);
  JOI::assign();
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;

const int MAX = 10005;

namespace IOI {
	int n, m;
	int pos[MAX];
	int par[MAX];
	int id[MAX];
	bool vis[MAX];
	int ncomp;
	vector<int> comp[MAX];
	vector<int> G[MAX];
	long long X;
	
	void build() {
		vector< pair<int,int> > edges;
		for (int i = 0; i < n; ++i) pos[i] = 0;
		queue <int> q; q.push(0); pos[0] = 1;
	
		while(!q.empty()) {
			int u = q.front(); q.pop();
			for (int v : G[u]) {
				if (!pos[v]) q.push(v), pos[v] = 1, edges.push_back(make_pair(u,v));
			}
		}
		for (int i = 0; i < n; ++i) G[i].clear(), pos[i] = 0;
		for (auto e : edges) G[e.first].push_back(e.second), G[e.second].push_back(e.first);
	}

	void dfs(int u) {
		if (comp[ncomp].size() == 60) return;
		pos[u] = ncomp;
		comp[ncomp].push_back(u);
		for (int v : G[u]) if (!pos[v]) {
			par[v] = u;
			dfs(v);
		}
	}

	void add(int u, int c) {
		if (comp[c].size() == 60) return;
		comp[c].push_back(u);
		vis[u] = 1;
		for (int v : G[u]) {
			if (pos[v] == pos[u] && !vis[v]) add(v, c);
		}
	}

	void prepare() {
		build();
		for (int i = 0; i < n; ++i) if (!pos[i]) ++ncomp, dfs(i);

		for (int i = 1; i <= ncomp; ++i) if (comp[i].size() == 60) {
			for (int j = 0; j < comp[i].size(); ++j) id[comp[i][j]] = j;
		}
		if (comp[ncomp].empty()) --ncomp;
		
		for (int i = 1; i <= ncomp; ++i) {
			if (comp[i].size() < 60) {
				int sz = comp[i].size();
				int root = comp[i][0];
				root = par[root];
				add(root, i);

				long long mask = 0;
				vector<int> rem;
				for (int j = sz; j < 60; ++j) mask |= (1LL << id[comp[i][j]]);
				for (int j = 0; j < 60; ++j) if (!(mask >> j & 1)) rem.push_back(j);
				for (int j = 0; j < sz; ++j) id[comp[i][j]] = rem.back(), rem.pop_back();
				for (int u : comp[i]) vis[u] = false;
			}
		}
	}

	void Ask(int u, int p, int c) {
		pos[u] = 1;
		for (int v : G[u]) if (find(comp[c].begin(), comp[c].end(), v) != comp[c].end()) {
			if (pos[v] == 0) {
				int k = Move(v); X |= ((1LL << id[v]) * k);
				Ask(v, u, c);
			}
		}
		if (p != -1) Move(p);
	}

	void solve(int P, int V) {
		prepare();
		int c = pos[P];
		X |= ((1LL << id[P]) * V);
		for (int i = 0; i < n; ++i) pos[i] = 0;
		Ask(P, -1, c);
	}
};

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
  IOI::n = N; 
  IOI::m = M;
  for (int i = 0; i < M; ++i) IOI::G[A[i]].push_back(B[i]), IOI::G[B[i]].push_back(A[i]);
  IOI::solve(P, V);
	return IOI::X;
}

Compilation message

Joi.cpp: In function 'void JOI::prepare()':
Joi.cpp:57:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < comp[i].size(); ++j) id[comp[i][j]] = j;
                      ^

Ioi.cpp: In function 'void IOI::prepare()':
Ioi.cpp:57:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < comp[i].size(); ++j) id[comp[i][j]] = j;
                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5948 KB Output is correct
2 Correct 0 ms 5948 KB Output is correct
3 Correct 0 ms 5948 KB Output is correct
4 Incorrect 0 ms 5948 KB Wrong Answer [7]
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 7284 KB Output is correct
2 Correct 28 ms 7284 KB Output is correct
3 Incorrect 39 ms 7292 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5948 KB Output is correct
2 Correct 0 ms 5948 KB Output is correct
3 Correct 0 ms 5948 KB Output is correct
4 Correct 0 ms 6212 KB Output is correct
5 Correct 0 ms 6212 KB Output is correct
6 Correct 0 ms 6212 KB Output is correct
7 Correct 0 ms 6212 KB Output is correct
8 Correct 0 ms 6212 KB Output is correct
9 Correct 22 ms 7012 KB Output is correct
10 Correct 9 ms 7012 KB Output is correct
11 Correct 9 ms 7012 KB Output is correct
12 Correct 0 ms 5948 KB Output is correct
13 Correct 0 ms 5948 KB Output is correct
14 Correct 0 ms 5948 KB Output is correct
15 Correct 0 ms 5948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 7292 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 7284 KB Output is correct
2 Correct 39 ms 7284 KB Output is correct
3 Incorrect 32 ms 7292 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -