답안 #32174

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
32174 2017-10-02T12:44:08 Z Diuven Snowy Roads (JOI16_snowy) C++11
100 / 100
26 ms 2484 KB
#include "Anyalib.h"
#include <vector>
using namespace std;

namespace AS{
	struct edge{
		int to=-1, idx=-1;
		edge(int to, int idx): to(to), idx(idx){};
		edge(){};
	} P[500]; // 올라가는 간선
	vector<edge> G[500];
	vector<int> V;
	int N, S[500], now, dep[500], C[500], X, rem, cnt[10];
	void idfs(int v, int p){
		dep[v]=now++;
		for(edge e:G[v])
			if(e.to!=p){
				P[e.to]={v, e.idx};
				idfs(e.to, v);
			}
		now--;
	}
	void dfs(int v, int p, int d){
		S[v]=d;
		for(edge e:G[v])
			if(e.to!=p)
				dfs(e.to, v, d+C[e.idx]);
	}
}

using namespace AS;

void InitAnya(int _N, int A[], int B[]){
	V.clear();
	N=_N;
	for(int i=0; i<=N-2; i++){
		G[A[i]].push_back({B[i], i});
		G[B[i]].push_back({A[i], i});
	}
	idfs(0,-1);
	for(int i=0; i<N; i++)
		cnt[dep[i]%10]++;
	int mn=N;
	for(int i=0; i<=9; i++)
		if(mn>cnt[i])
			mn=cnt[i], rem=i;
	for(int i=0; i<N; i++)
		if(dep[i]%10==rem)
			V.push_back(i);
	X=(int)V.size()*9;
}

void Anya(int _C[]){
	fill(S, S+N, 0);
	for(int i=0; i<=N-2; i++)
		C[i]=_C[i];
	dfs(0, -1, 0);
	for(int i=0; i<(int)V.size(); i++)
		for(int k=0; k<9; k++)
			Save(9*i+k, !!(S[V[i]]&(1<<k)));
	for(int i=0; i<=N-2; i++)
		Save(X+i, C[i]);
}
#include "Borislib.h"
#include <vector>
using namespace std;

namespace BS{
	struct edge{
		int to=-1, idx=-1;
		edge(int to, int idx): to(to), idx(idx){};
		edge(){};
	} P[500];
	vector<edge> G[500];
	int N, dep[500], now, X, bck, pos[500], cnt[10], rem;
	void idfs(int v, int p){
		dep[v]=now++;
		for(edge e:G[v])
			if(e.to!=p){
				P[e.to]={v, e.idx};
				idfs(e.to, v);
			}
		now--;
	}
}

using namespace BS;

void InitBoris(int _N, int A[], int B[]){
	bck=0;
	N=_N;
	for(int i=0; i<=N-2; i++){
		G[A[i]].push_back({B[i], i});
		G[B[i]].push_back({A[i], i});
	}
	idfs(0,-1);
	for(int i=0; i<N; i++)
		cnt[dep[i]%10]++;
	int mn=N;
	for(int i=0; i<10; i++)
		if(mn>cnt[i])
			mn=cnt[i], rem=i;
	for(int i=0; i<N; i++)
		if(dep[i]%10==rem)
			pos[i]=bck++;
	X=bck*9;
}
int Boris(int city){
	int ans=0;
	while(city>0&&dep[city]%10!=rem){
		ans+=Ask(X+P[city].idx);
		city=P[city].to;
	}
	if(dep[city]%10!=rem)	return ans;
	for(int k=0; k<9; k++)
		ans+=(Ask(pos[city]*9+k)<<k);
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2484 KB Output is correct
2 Correct 0 ms 2484 KB Output is correct
3 Correct 0 ms 2484 KB Output is correct
4 Correct 0 ms 2484 KB Output is correct
5 Correct 6 ms 2484 KB Output is correct
6 Correct 3 ms 2484 KB Output is correct
7 Correct 6 ms 2484 KB Output is correct
8 Correct 6 ms 2484 KB Output is correct
9 Correct 3 ms 2484 KB Output is correct
10 Correct 3 ms 2484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2484 KB Output is correct
2 Correct 6 ms 2484 KB Output is correct
3 Correct 6 ms 2484 KB Output is correct
4 Correct 3 ms 2484 KB Output is correct
5 Correct 9 ms 2484 KB Output is correct
6 Correct 6 ms 2484 KB Output is correct
7 Correct 3 ms 2484 KB Output is correct
8 Correct 3 ms 2484 KB Output is correct
9 Correct 9 ms 2484 KB Output is correct
10 Correct 3 ms 2484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 2484 KB Output is correct
2 Correct 16 ms 2484 KB Output is correct
3 Correct 22 ms 2484 KB Output is correct
4 Correct 16 ms 2484 KB Output is correct
5 Correct 16 ms 2484 KB Output is correct
6 Correct 16 ms 2484 KB Output is correct
7 Correct 19 ms 2484 KB Output is correct
8 Correct 12 ms 2484 KB Output is correct
9 Correct 13 ms 2484 KB Output is correct
10 Correct 16 ms 2484 KB Output is correct
11 Correct 16 ms 2484 KB Output is correct
12 Correct 6 ms 2484 KB Output is correct
13 Correct 3 ms 2484 KB Output is correct
14 Correct 12 ms 2484 KB Output is correct
15 Correct 13 ms 2484 KB Output is correct
16 Correct 19 ms 2484 KB Output is correct
17 Correct 19 ms 2484 KB Output is correct
18 Correct 16 ms 2484 KB Output is correct
19 Correct 16 ms 2484 KB Output is correct
20 Correct 16 ms 2484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2484 KB Output is correct
2 Correct 19 ms 2484 KB Output is correct
3 Correct 12 ms 2484 KB Output is correct
4 Correct 6 ms 2484 KB Output is correct
5 Correct 16 ms 2484 KB Output is correct
6 Correct 9 ms 2484 KB Output is correct
7 Correct 12 ms 2484 KB Output is correct
8 Correct 9 ms 2484 KB Output is correct
9 Correct 12 ms 2484 KB Output is correct
10 Correct 12 ms 2484 KB Output is correct
11 Correct 16 ms 2484 KB Output is correct
12 Correct 12 ms 2484 KB Output is correct
13 Correct 16 ms 2484 KB Output is correct
14 Correct 12 ms 2484 KB Output is correct
15 Correct 12 ms 2484 KB Output is correct
16 Correct 12 ms 2484 KB Output is correct
17 Correct 16 ms 2484 KB Output is correct
18 Correct 22 ms 2484 KB Output is correct
19 Correct 16 ms 2484 KB Output is correct
20 Correct 26 ms 2484 KB Output is correct
21 Correct 19 ms 2484 KB Output is correct
22 Correct 22 ms 2484 KB Output is correct
23 Correct 16 ms 2484 KB Output is correct
24 Correct 16 ms 2484 KB Output is correct
25 Correct 12 ms 2484 KB Output is correct
26 Correct 12 ms 2484 KB Output is correct
27 Correct 12 ms 2484 KB Output is correct
28 Correct 16 ms 2484 KB Output is correct
29 Correct 19 ms 2484 KB Output is correct
30 Correct 16 ms 2484 KB Output is correct
31 Correct 16 ms 2484 KB Output is correct
32 Correct 9 ms 2484 KB Output is correct
33 Correct 16 ms 2484 KB Output is correct
34 Correct 12 ms 2484 KB Output is correct
35 Correct 16 ms 2484 KB Output is correct
36 Correct 16 ms 2484 KB Output is correct
37 Correct 13 ms 2484 KB Output is correct
38 Correct 19 ms 2484 KB Output is correct
39 Correct 16 ms 2484 KB Output is correct
40 Correct 12 ms 2484 KB Output is correct
41 Correct 12 ms 2484 KB Output is correct
42 Correct 6 ms 2484 KB Output is correct
43 Correct 12 ms 2484 KB Output is correct
44 Correct 12 ms 2484 KB Output is correct
45 Correct 16 ms 2484 KB Output is correct
46 Correct 12 ms 2484 KB Output is correct
47 Correct 22 ms 2484 KB Output is correct
48 Correct 9 ms 2484 KB Output is correct
49 Correct 16 ms 2484 KB Output is correct
50 Correct 22 ms 2484 KB Output is correct