답안 #565869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
565869 2022-05-21T13:20:06 Z errorgorn Amusement Park (JOI17_amusement_park) C++17
0 / 100
429 ms 55332 KB
#include "Joi.h"

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
#define fi first
#define se second

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

namespace{
	
int n,m;
vector<int> al[10005];
int id[10005];
vector<int> cc[100005];

bool vis[10005];
int IDX=0;

bitset<10005> has[10005];

void dfs(int i,int p){
	vis[i]=true;
	
	if (IDX<60){
		id[i]=IDX++;
		if (IDX==60){
			vector<int> v;
			rep(x,0,n) if (vis[x]) v.pub(x);
			for (auto it:v) cc[it]=v;
		}
	}
	else{
		//copy cc[p], remove one guy and add i
		cc[i]=cc[p];
		cc[i].pub(i);
		map<int,int> cnt;
		rep(x,0,sz(cc[i])) rep(y,x+1,sz(cc[i])) if (has[cc[i][x]][cc[i][y]]){
			cnt[x]++,cnt[y]++;
		}
		
		//for (auto [a,b]:cnt) cout<<a<<" "<<cc[i][a]<<" "<<b<<endl;
		
		for (auto [a,b]:cnt) if (b==1){
			cc[i].erase(cc[i].begin()+a);
			break;
		}
		
		set<int> ids;
		rep(x,0,60) ids.insert(x);
		rep(x,0,sz(cc[i])-1) ids.erase(id[cc[i][x]]);
		id[i]=*ids.begin();
	}
	
	for (auto it:al[i]) if (!vis[it]){
		has[it][i]=1;
		has[i][it]=1;
		dfs(it,i);
	}
}

}

void Joi(signed N, signed M, signed A[], signed B[], long long X, signed T) {
	n=N,m=M;
	rep(x,0,m){
		al[A[x]].pub(B[x]);
		al[B[x]].pub(A[x]);
	}
	
	dfs(0,-1);
	
	//rep(x,0,n){
		//for (auto it:cc[x]) cout<<it<<" "; cout<<endl;
	//}
	
	//rep(x,0,n) cout<<id[x]<<" "; cout<<endl;
	rep(x,0,n) MessageBoard(x,(X>>id[x])&1);
}
#include "Ioi.h"

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
#define fi first
#define se second

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

namespace{
	
int n,m;
vector<int> al[10005];
int id[10005];
vector<int> cc[100005];

bool vis[10005];
int IDX=0;

bitset<10005> has[10005];

void dfs(int i,int p){
	vis[i]=true;
	
	if (IDX<60){
		id[i]=IDX++;
		if (IDX==60){
			vector<int> v;
			rep(x,0,n) if (vis[x]) v.pub(x);
			for (auto it:v) cc[it]=v;
		}
	}
	else{
		//copy cc[p], remove one guy and add i
		cc[i]=cc[p];
		cc[i].pub(i);
		map<int,int> cnt;
		rep(x,0,sz(cc[i])) rep(y,x+1,sz(cc[i])) if (has[cc[i][x]][cc[i][y]]){
			cnt[x]++,cnt[y]++;
		}
		
		//for (auto [a,b]:cnt) cout<<a<<" "<<cc[i][a]<<" "<<b<<endl;
		
		for (auto [a,b]:cnt) if (b==1){
			cc[i].erase(cc[i].begin()+a);
			break;
		}
		
		set<int> ids;
		rep(x,0,60) ids.insert(x);
		rep(x,0,sz(cc[i])-1) ids.erase(id[cc[i][x]]);
		id[i]=*ids.begin();
	}
	
	for (auto it:al[i]) if (!vis[it]){
		has[it][i]=1;
		has[i][it]=1;
		dfs(it,i);
	}
}

int k;
set<int> s;
int ans=0;

void dfs2(int i,int p){
	if (p!=-1) ans|=((int)Move(i))<<id[i];
	
	vis[i]=true;
	
	for (auto it:al[i]) if (!vis[it] && s.count(it)){
		dfs2(it,i);
	}
	
	if (p!=-1) ans|=((int)Move(p))<<id[p];
}

}

long long Ioi(signed N, signed M, signed A[], signed B[], signed P, signed V, signed T) {
	n=N,m=M,k=P;
	rep(x,0,m){
		al[A[x]].pub(B[x]);
		al[B[x]].pub(A[x]);
	}
	
	dfs(0,-1);
	
	memset(vis,false,sizeof(vis));
	s=set<int>(all(cc[k]));
	dfs2(k,-1);
	
	cout<<ans<<endl;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 6156 KB Do not print anything on standard output.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 416 ms 55196 KB Do not print anything on standard output.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 6156 KB Do not print anything on standard output.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 424 ms 55228 KB Do not print anything on standard output.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 429 ms 55332 KB Do not print anything on standard output.
2 Halted 0 ms 0 KB -