답안 #125626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125626 2019-07-06T05:43:29 Z Retro3014 Amusement Park (JOI17_amusement_park) C++17
100 / 100
73 ms 5616 KB
#include "Joi.h"
#include <bits/stdc++.h>

#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL


using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_N = 10000;
const int MAX_M = 20000;

vector<int> grpa[MAX_N+1];
vector<int> grp2[MAX_N+1];

int nmb[MAX_N+1];
int pa[MAX_N+1];

int chc[MAX_N+1];
int dgr[MAX_N+1];

set<int> s;

int find_leafa(int x){
	for(set<int>::iterator it = s.begin(); it!=s.end(); it++){
		dgr[*it] = 0;
	}
	for(set<int>::iterator it = s.begin(); it!=s.end(); it++){
		int k = (*it);
		if(k==0)	continue;
		if(chc[pa[k]]){
			dgr[pa[k]]++;
			dgr[k]++;
		}
	}
	for(set<int>::iterator it = s.begin(); it!=s.end(); it++){
		int k = (*it);
		if(dgr[k]==1 && k!=x)	return k;
	}
}
bool visit[MAX_N+1];

void dfsa(int x){
	visit[x] = true;
	//cout<<x<<endl;
	int t = -1;
	if(s.size()==60){
		int lf = find_leafa(pa[x]);
		t = lf;
		s.erase(lf);
		chc[lf] = false;
		nmb[x] = nmb[lf];
		chc[x] = true;
		s.insert(x);
	}else if(s.size()==59){
		s.insert(x);
		chc[x] = true;
		int cnt = 0;
		for(set<int>::iterator it = s.begin(); it!=s.end(); it++){
			nmb[*it] = cnt;
			cnt++;
		}
	}else{
		s.insert(x);
		chc[x] = true;
	}
	for(int i=0; i<grpa[x].size(); i++){
		if(visit[grpa[x][i]])	continue;
		pa[grpa[x][i]] = x;
		dfsa(grpa[x][i]);
	}
	if(t!=-1){
		s.erase(x);
		s.insert(t);
		chc[t] = true;
		chc[x] = false;
	}
}


void Joi(int N, int M, int A[], int B[], long long X, int T) {
	for(int i=0; i<M; i++){
		grpa[A[i]].pb(B[i]); grpa[B[i]].pb(A[i]);
  	}
  	dfsa(0);
  	for(int i=0; i<N; i++){
  		ll t = ((ll)1<<nmb[i]);
  		MessageBoard(i, ((t & X)>0));
  		//cout<<i<<" "<<nmb[i]<<" "<<((t & X)>0)<<endl;
  		t*=2;
  	}
}
#include "Ioi.h"
#include <bits/stdc++.h>

#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL


using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_N = 10000;
const int MAX_M = 20000;

vector<int> gp[MAX_N+1];
vector<int> gp2[MAX_N+1];

int num[MAX_N+1];
int p[MAX_N+1];

int chk[MAX_N+1];
int deg[MAX_N+1];

set<int> st;

int find_leaf(int x){
	for(set<int>::iterator it = st.begin(); it!=st.end(); it++){
		deg[*it] = 0;
	}
	for(set<int>::iterator it = st.begin(); it!=st.end(); it++){
		int k = (*it);
		if(k==0)	continue;
		if(chk[p[k]]){
			deg[p[k]]++;
			deg[k]++;
		}
	}
	for(set<int>::iterator it = st.begin(); it!=st.end(); it++){
		int k = (*it);
		if(deg[k]==1 && k!=x)	return k;
	}
}

bool found = false;

int pos;
bool visited[MAX_N+1];

void dfs(int x){
	visited[x] = true;
	int t = -1;
	if(st.size()==60){
		int lf = find_leaf(p[x]);
		t = lf;
		st.erase(lf);
		chk[lf] = false;
		num[x] = num[lf];
		chk[x] = true;
		st.insert(x);
		if(x==pos){
			found = true;
			return;
		}
	}else if(st.size()==59){
		st.insert(x);
		chk[x] = true;
		int cnt = 0;
		for(set<int>::iterator it = st.begin(); it!=st.end(); it++){
			num[*it] = cnt;
			cnt++;
		}
		if(st.find(pos)!=st.end()){
			found = true;
			return;
		}
	}else{
		st.insert(x);
		chk[x] = true;
	}
	for(int i=0; i<gp[x].size(); i++){
		if(visited[gp[x][i]])	continue;
		p[gp[x][i]] = x;
		dfs(gp[x][i]);
		if(found)	return;
	}
	if(t!=-1){
		st.erase(x);
		st.insert(t);
		chk[t] = true;
		chk[x] = false;
	}
}


bool vst[MAX_N+1];
int ans[100];

void calc(int x){
	vst[x] = true;
	for(int i=0; i<gp[x].size(); i++){
		if(chk[gp[x][i]] && !vst[gp[x][i]]){
			int t = Move(gp[x][i]);
			ans[num[gp[x][i]]] = t;
			calc(gp[x][i]);
			Move(x);
		}
	}
}



long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
	pos = P;
	for(int i=0; i<M; i++){
		gp[A[i]].pb(B[i]); gp[B[i]].pb(A[i]);
  	}
  	dfs(0);
  	ans[num[P]] = V;
  	calc(P);
  	ll answer=0;
  	ll t = 1;
  	for(int i=0; i<60; i++){
  		answer += (ll)ans[i] * t;
  		t*=2;
  	}
  	//cout<<answer<<endl;
  	return answer;
}

Compilation message

Joi.cpp: In function 'void dfsa(int)':
Joi.cpp:82:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<grpa[x].size(); i++){
               ~^~~~~~~~~~~~~~~
Joi.cpp: In function 'int find_leafa(int)':
Joi.cpp:55:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

Ioi.cpp: In function 'void dfs(int)':
Ioi.cpp:93:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<gp[x].size(); i++){
               ~^~~~~~~~~~~~~
Ioi.cpp: In function 'void calc(int)':
Ioi.cpp:113:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<gp[x].size(); i++){
               ~^~~~~~~~~~~~~
Ioi.cpp: In function 'int find_leaf(int)':
Ioi.cpp:55:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1788 KB Output is correct
2 Correct 5 ms 1888 KB Output is correct
3 Correct 6 ms 1924 KB Output is correct
4 Correct 5 ms 1916 KB Output is correct
5 Correct 5 ms 1788 KB Output is correct
6 Correct 5 ms 1792 KB Output is correct
7 Correct 6 ms 1796 KB Output is correct
8 Correct 5 ms 2036 KB Output is correct
9 Correct 6 ms 1924 KB Output is correct
10 Correct 5 ms 1884 KB Output is correct
11 Correct 9 ms 2160 KB Output is correct
12 Correct 5 ms 1788 KB Output is correct
13 Correct 5 ms 1796 KB Output is correct
14 Correct 6 ms 1912 KB Output is correct
15 Correct 6 ms 1924 KB Output is correct
16 Correct 5 ms 1788 KB Output is correct
17 Correct 5 ms 1916 KB Output is correct
18 Correct 6 ms 2040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 5360 KB Output is correct
2 Correct 68 ms 5508 KB Output is correct
3 Correct 59 ms 5616 KB Output is correct
4 Correct 45 ms 3744 KB Output is correct
5 Correct 63 ms 4384 KB Output is correct
6 Correct 57 ms 4128 KB Output is correct
7 Correct 54 ms 4220 KB Output is correct
8 Correct 41 ms 4080 KB Output is correct
9 Correct 55 ms 4508 KB Output is correct
10 Correct 33 ms 3792 KB Output is correct
11 Correct 37 ms 3752 KB Output is correct
12 Correct 40 ms 3592 KB Output is correct
13 Correct 46 ms 3584 KB Output is correct
14 Correct 36 ms 3700 KB Output is correct
15 Correct 44 ms 3796 KB Output is correct
16 Correct 55 ms 3640 KB Output is correct
17 Correct 41 ms 3736 KB Output is correct
18 Correct 43 ms 3736 KB Output is correct
19 Correct 41 ms 3820 KB Output is correct
20 Correct 46 ms 4560 KB Output is correct
21 Correct 44 ms 4468 KB Output is correct
22 Correct 63 ms 4128 KB Output is correct
23 Correct 61 ms 4384 KB Output is correct
24 Correct 53 ms 4128 KB Output is correct
25 Correct 63 ms 4128 KB Output is correct
26 Correct 57 ms 4384 KB Output is correct
27 Correct 46 ms 4080 KB Output is correct
28 Correct 57 ms 4384 KB Output is correct
29 Correct 46 ms 4080 KB Output is correct
30 Correct 59 ms 4156 KB Output is correct
31 Correct 5 ms 1780 KB Output is correct
32 Correct 5 ms 1652 KB Output is correct
33 Correct 5 ms 2032 KB Output is correct
34 Correct 6 ms 1784 KB Output is correct
35 Correct 5 ms 1916 KB Output is correct
36 Correct 6 ms 1916 KB Output is correct
37 Correct 5 ms 2016 KB Output is correct
38 Correct 6 ms 2016 KB Output is correct
39 Correct 5 ms 2016 KB Output is correct
40 Correct 5 ms 1916 KB Output is correct
41 Correct 4 ms 1816 KB Output is correct
42 Correct 4 ms 1916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1912 KB Output is correct
2 Correct 4 ms 1648 KB Output is correct
3 Correct 4 ms 1780 KB Output is correct
4 Correct 9 ms 2288 KB Output is correct
5 Correct 10 ms 2064 KB Output is correct
6 Correct 9 ms 2064 KB Output is correct
7 Correct 9 ms 2084 KB Output is correct
8 Correct 11 ms 2192 KB Output is correct
9 Correct 38 ms 4848 KB Output is correct
10 Correct 30 ms 4856 KB Output is correct
11 Correct 44 ms 5088 KB Output is correct
12 Correct 5 ms 1812 KB Output is correct
13 Correct 4 ms 1776 KB Output is correct
14 Correct 4 ms 2016 KB Output is correct
15 Correct 4 ms 2020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 5400 KB Output is correct
2 Correct 70 ms 5528 KB Output is correct
3 Correct 70 ms 5504 KB Output is correct
4 Correct 37 ms 3736 KB Output is correct
5 Correct 62 ms 4760 KB Output is correct
6 Correct 41 ms 4336 KB Output is correct
7 Correct 52 ms 4080 KB Output is correct
8 Correct 43 ms 4080 KB Output is correct
9 Correct 53 ms 3864 KB Output is correct
10 Correct 32 ms 3612 KB Output is correct
11 Correct 36 ms 4012 KB Output is correct
12 Correct 38 ms 3588 KB Output is correct
13 Correct 43 ms 3592 KB Output is correct
14 Correct 40 ms 3592 KB Output is correct
15 Correct 44 ms 3744 KB Output is correct
16 Correct 49 ms 3736 KB Output is correct
17 Correct 47 ms 3820 KB Output is correct
18 Correct 49 ms 3608 KB Output is correct
19 Correct 52 ms 3700 KB Output is correct
20 Correct 45 ms 4596 KB Output is correct
21 Correct 44 ms 4612 KB Output is correct
22 Correct 51 ms 4024 KB Output is correct
23 Correct 43 ms 4080 KB Output is correct
24 Correct 55 ms 4336 KB Output is correct
25 Correct 45 ms 4120 KB Output is correct
26 Correct 58 ms 4256 KB Output is correct
27 Correct 63 ms 4388 KB Output is correct
28 Correct 42 ms 4092 KB Output is correct
29 Correct 46 ms 3848 KB Output is correct
30 Correct 43 ms 4108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 5360 KB Output is correct
2 Correct 56 ms 5360 KB Output is correct
3 Correct 73 ms 5512 KB Output is correct
4 Correct 50 ms 3616 KB Output is correct
5 Correct 44 ms 4848 KB Output is correct
6 Correct 41 ms 4024 KB Output is correct
7 Correct 55 ms 4024 KB Output is correct
8 Correct 49 ms 4336 KB Output is correct
9 Correct 52 ms 4080 KB Output is correct
10 Correct 31 ms 3612 KB Output is correct
11 Correct 36 ms 3760 KB Output is correct
12 Correct 40 ms 3848 KB Output is correct
13 Correct 43 ms 3588 KB Output is correct
14 Correct 45 ms 3696 KB Output is correct
15 Correct 48 ms 3668 KB Output is correct
16 Correct 49 ms 3808 KB Output is correct
17 Correct 41 ms 3668 KB Output is correct
18 Correct 50 ms 3616 KB Output is correct
19 Correct 48 ms 3788 KB Output is correct
20 Correct 47 ms 4512 KB Output is correct
21 Correct 44 ms 4512 KB Output is correct
22 Correct 50 ms 4080 KB Output is correct
23 Correct 51 ms 4244 KB Output is correct
24 Correct 51 ms 4224 KB Output is correct
25 Correct 51 ms 4188 KB Output is correct
26 Correct 65 ms 4128 KB Output is correct
27 Correct 61 ms 4464 KB Output is correct
28 Correct 48 ms 4356 KB Output is correct
29 Correct 55 ms 4276 KB Output is correct
30 Correct 43 ms 4164 KB Output is correct
31 Correct 5 ms 1652 KB Output is correct
32 Correct 6 ms 1784 KB Output is correct
33 Correct 9 ms 1936 KB Output is correct
34 Correct 6 ms 1652 KB Output is correct
35 Correct 5 ms 1780 KB Output is correct
36 Correct 4 ms 1780 KB Output is correct
37 Correct 5 ms 1780 KB Output is correct
38 Correct 5 ms 1888 KB Output is correct
39 Correct 4 ms 1784 KB Output is correct
40 Correct 4 ms 1788 KB Output is correct
41 Correct 6 ms 1784 KB Output is correct
42 Correct 5 ms 1896 KB Output is correct