답안 #66110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66110 2018-08-09T15:07:55 Z khohko Dungeon 2 (JOI16_dungeon2) C++17
100 / 100
32 ms 4092 KB
#include "dungeon2.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define ARRS ((ll)(2e6+100))
#define MAX ((ll)(1e9+100))
#define MOD ((ll)(1e9+7))

//void Inspect(int R);
//void Answer(int D, int A);
//void Move(int I, int V);
//int NumberOfRoads();
//int LastRoad();
//int Color();
#define num NumberOfRoads
#define lst LastRoad
#define clr Color

stack<ll> g;
vector<pair<ll,ll> > v[400];
ll C=1;
ll pr[400];
ll nm[400];
void mvb(){
	ll t=g.top();
	g.pop();
	if(t>=0)Move(t,clr());
}

ll n=0;
ll f[400][400];
ll ef[700][700];

ll go(ll f){
	g.push(LastRoad());
	ll k=Color();
	if(k==2){mvb(); return 0;}
	if(k==3){mvb(); return -1;}
	n++;
	ll x=n;
	pr[x]=lst();
	if(f)v[x].pb({f,pr[x]});
	ll m=num();
	nm[x]=m;
	for(int i=1; i<=m; i++){
		if(i==g.top())continue;
		Move(i,2);
		ll k=go(x);
		if(k==-1)ef[x][i]=1;
		if(k>0)v[x].pb({k,i});
	}
	ll t=g.top();
	g.pop();
	if(t>=0)Move(t,3);
	return x;
}

ll dp[400][400];
ll bk[400][400];
ll pw[400];
ll pas[400];
ll cr;

ll gc(ll x){
	return (x/pw[cr])%3+1;
}
ll gcc(ll x){
	return (x/pw[cr+1])%3+1;
}

vector<ll> ord;
ll out[400];
//void dfs(ll x){
//	for(auto y:v[x]){
//		if(y.sc==pr[x])continue;
//		Move(y.sc,gc(x));
//		dfs(y.fr);
//	}
//	if(pr[x]>=0)
//	Move(pr[x],gc(x));
//}

void slv(ll x){
	for(auto y:v[x]){
		if(y.sc==pr[x])continue;
		Move(y.sc,gc(x));
		slv(y.fr);
	}
	for(int i=1; i<=num(); i++){
		if(ef[x][i])continue;
		Move(i,clr());
		f[x][i]+=(clr()-1)*pw[cr];
		bk[x][i]=lst();
		Move(lst(),clr());
	}
	if(pr[x]>=0)
		Move(pr[x],gc(x));
}


void Inspect(int R) {
//	string s="ITO";
//	for(int i=0; i<s.size(); i++)s[i]=s[i]-'A'+'a';
//	cout<<s<<endl;
//	return;
	go(0);

	for(int i=1; i<=n; i++){
		for(auto x:v[i]){
			ef[i][x.sc]=1;
			f[i][x.sc]=x.fr;
		}
	}

	pw[0]=1;
	for(int i=1; i<15; i++)pw[i]=pw[i-1]*3;
//	dfs(1);
	for(cr=0; pw[cr]-1<n+1; cr++)
		slv(1);
	//reverse(ord.begin(),ord.end());
	for(int i=1; i<=n; i++)
		for(int j=1; j<=nm[i]; j++){
			if(ef[i][j])continue;
			f[f[i][j]][bk[i][j]]=i;
		}

	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			dp[i][j]=MAX;

	for(int i=1; i<=n; i++)
		for(int j=1; j<=nm[i]; j++)
			dp[i][f[i][j]]=1;

	for(int k=1; k<=n; k++)
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);

	for(int i=1; i<=n; i++)
		for(int j=i+1; j<=n; j++)
			pas[dp[i][j]]++;

	for(int i = 1; i <= R; i++)
		Answer(i, pas[i]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1020 KB Output is correct
2 Correct 3 ms 1128 KB Output is correct
3 Correct 3 ms 1228 KB Output is correct
4 Correct 4 ms 1228 KB Output is correct
5 Correct 4 ms 1236 KB Output is correct
6 Correct 3 ms 1236 KB Output is correct
7 Correct 3 ms 1236 KB Output is correct
8 Correct 3 ms 1236 KB Output is correct
9 Correct 3 ms 1236 KB Output is correct
10 Correct 3 ms 1244 KB Output is correct
11 Correct 4 ms 1244 KB Output is correct
12 Correct 3 ms 1244 KB Output is correct
13 Correct 3 ms 1244 KB Output is correct
14 Correct 4 ms 1244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1244 KB Output is correct
2 Correct 3 ms 1244 KB Output is correct
3 Correct 3 ms 1244 KB Output is correct
4 Correct 3 ms 1244 KB Output is correct
5 Correct 3 ms 1364 KB Output is correct
6 Correct 3 ms 1364 KB Output is correct
7 Correct 3 ms 1364 KB Output is correct
8 Correct 3 ms 1364 KB Output is correct
9 Correct 3 ms 1364 KB Output is correct
10 Correct 3 ms 1364 KB Output is correct
11 Correct 3 ms 1364 KB Output is correct
12 Correct 3 ms 1364 KB Output is correct
13 Correct 3 ms 1364 KB Output is correct
14 Correct 3 ms 1388 KB Output is correct
15 Correct 3 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3068 KB Output is correct
2 Correct 21 ms 3324 KB Output is correct
3 Correct 16 ms 3708 KB Output is correct
4 Correct 31 ms 3964 KB Output is correct
5 Correct 3 ms 3964 KB Output is correct
6 Correct 6 ms 3964 KB Output is correct
7 Correct 15 ms 3964 KB Output is correct
8 Correct 17 ms 3964 KB Output is correct
9 Correct 15 ms 3964 KB Output is correct
10 Correct 15 ms 3964 KB Output is correct
11 Correct 15 ms 3964 KB Output is correct
12 Correct 18 ms 3964 KB Output is correct
13 Correct 16 ms 3964 KB Output is correct
14 Correct 17 ms 3964 KB Output is correct
15 Correct 20 ms 3964 KB Output is correct
16 Correct 9 ms 3964 KB Output is correct
17 Correct 32 ms 4092 KB Output is correct
18 Correct 27 ms 4092 KB Output is correct
19 Correct 31 ms 4092 KB Output is correct