답안 #26163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26163 2017-06-28T07:50:38 Z Kendrick Lamar(#1107) Snowy Roads (JOI16_snowy) C++14
100 / 100
25 ms 4192 KB
#include "Anyalib.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;

static int par[505], ia[505], ib[505], dep[505], n;

static vector<int> gph[505];
static vector<pi> el;

static void dfs(int x, int p){
	for(auto &i : gph[x]){
		if(i == p) continue;
		par[i] = x;
		dep[i] = dep[x] + 1;
		el.push_back(pi(x, i));
		dfs(i, x);
		el.push_back(pi(i, x));
	}
}

static int getL;

void InitAnya(int N , int A[] , int B[]) {
	n = N;
	memcpy(ia, A, sizeof(int) * (N-1));
	memcpy(ib, B, sizeof(int) * (N-1));
	for(int i=0; i<N-1; i++){
		gph[ia[i]].push_back(ib[i]);
		gph[ib[i]].push_back(ia[i]);
	}
	dfs(0, -1);
}

int pchk[505], sum[1005];

void Anya(int C[]) {
	for(int i=0; i<n-1; i++){
		Save(i, C[i]);
		if(par[ia[i]] == ib[i]) swap(ia[i], ib[i]);
		pchk[ib[i]] = C[i];
	}
	memset(sum, 0, sizeof(sum));
	for(int i=0; i<el.size(); i++){
		if(dep[el[i].first] < dep[el[i].second]){
			sum[i] = pchk[el[i].second];
		}
		else{
			sum[i] = -pchk[el[i].first];
		}
	}
	for(int i=1; i<=1000; i++) sum[i] += sum[i-1];
	int pnt = n - 1;
	for(int i=19; i<=999; i+=20){
		for(int j=0; j<9; j++){
			Save(pnt++, (sum[i] >> j) & 1);
		}
	}
}


#include "Borislib.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;

static int par[505], ia[505], ib[505], dep[505], n;

static vector<int> gph[505];
static vector<pi> el;

static void dfs(int x, int p){
	for(auto &i : gph[x]){
		if(i == p) continue;
		par[i] = x;
		dep[i] = dep[x] + 1;
		el.push_back(pi(x, i));
		dfs(i, x);
		el.push_back(pi(i, x));
	}
}

void InitBoris(int N , int A[] , int B[]) {
	memcpy(ia, A, sizeof(int) * (N-1));
	memcpy(ib, B, sizeof(int) * (N-1));
	n = N;
	for(int i=0; i<N-1; i++){
		gph[A[i]].push_back(B[i]);
		gph[B[i]].push_back(A[i]);
	}
	dfs(0, -1);
}

int querya(int x){
	if(x < 0) return 0;
	assert(x % 20 == 19);
	x = 9 * (x / 20) + n-1;
	int ans = 0;
	for(int j=0; j<9; j++){
		ans |= (Ask(x + j) << j);
	}
	return ans;
}

int get_pchk(int node){
	for(int i=0; i<n-1; i++){
		if(par[ia[i]] == ib[i]) swap(ia[i], ib[i]);
		if(ib[i] == node) return Ask(i);
	}
	assert(0);
}

int queryb(int x){
	if(x >= el.size()) return 0;
	if(dep[el[x].first] < dep[el[x].second]){
		return get_pchk(el[x].second);
	}
	else return -get_pchk(el[x].first);
}

int Boris(int city) {
	int gs = 0;
	for(int i=0; i<el.size(); i++){
		if(el[i].second == city){
			gs = i;
			break;
		}
	}
	if(gs % 20 >= 10){
		int up = (gs / 20 + 1) * 20;
		int sum = querya(up - 1);
		for(int i=gs+1; i<up; i++){
			sum -= queryb(i);
		}
		return sum;
	}
	else{
		int up = (gs / 20) * 20;
		int sum = querya(up - 1);
		for(int i=up; i<=gs; i++){
			sum += queryb(i);
		}
		return sum;
	}
}

Compilation message

Anya.cpp: In function 'void Anya(int*)':
Anya.cpp:44:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<el.size(); i++){
                ^
Anya.cpp: At global scope:
Anya.cpp:22:12: warning: 'getL' defined but not used [-Wunused-variable]
 static int getL;
            ^

Boris.cpp: In function 'int queryb(int)':
Boris.cpp:53:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(x >= el.size()) return 0;
       ^
Boris.cpp: In function 'int Boris(int)':
Boris.cpp:62:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<el.size(); i++){
                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4192 KB Output is correct
2 Correct 0 ms 4192 KB Output is correct
3 Correct 0 ms 4192 KB Output is correct
4 Correct 3 ms 4192 KB Output is correct
5 Correct 6 ms 4192 KB Output is correct
6 Correct 3 ms 4192 KB Output is correct
7 Correct 9 ms 4192 KB Output is correct
8 Correct 3 ms 4192 KB Output is correct
9 Correct 9 ms 4192 KB Output is correct
10 Correct 3 ms 4192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 4192 KB Output is correct
2 Correct 9 ms 4192 KB Output is correct
3 Correct 9 ms 4192 KB Output is correct
4 Correct 6 ms 4192 KB Output is correct
5 Correct 9 ms 4192 KB Output is correct
6 Correct 6 ms 4192 KB Output is correct
7 Correct 9 ms 4192 KB Output is correct
8 Correct 9 ms 4192 KB Output is correct
9 Correct 12 ms 4192 KB Output is correct
10 Correct 9 ms 4192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 4192 KB Output is correct
2 Correct 9 ms 4192 KB Output is correct
3 Correct 25 ms 4192 KB Output is correct
4 Correct 16 ms 4192 KB Output is correct
5 Correct 12 ms 4192 KB Output is correct
6 Correct 9 ms 4192 KB Output is correct
7 Correct 19 ms 4192 KB Output is correct
8 Correct 13 ms 4192 KB Output is correct
9 Correct 12 ms 4192 KB Output is correct
10 Correct 16 ms 4192 KB Output is correct
11 Correct 16 ms 4192 KB Output is correct
12 Correct 16 ms 4192 KB Output is correct
13 Correct 12 ms 4192 KB Output is correct
14 Correct 15 ms 4192 KB Output is correct
15 Correct 19 ms 4192 KB Output is correct
16 Correct 19 ms 4192 KB Output is correct
17 Correct 12 ms 4192 KB Output is correct
18 Correct 12 ms 4192 KB Output is correct
19 Correct 16 ms 4192 KB Output is correct
20 Correct 9 ms 4192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 4192 KB Output is correct
2 Correct 16 ms 4192 KB Output is correct
3 Correct 6 ms 4192 KB Output is correct
4 Correct 12 ms 4192 KB Output is correct
5 Correct 9 ms 4192 KB Output is correct
6 Correct 15 ms 4192 KB Output is correct
7 Correct 12 ms 4192 KB Output is correct
8 Correct 15 ms 4192 KB Output is correct
9 Correct 22 ms 4192 KB Output is correct
10 Correct 19 ms 4192 KB Output is correct
11 Correct 12 ms 4192 KB Output is correct
12 Correct 12 ms 4192 KB Output is correct
13 Correct 19 ms 4192 KB Output is correct
14 Correct 12 ms 4192 KB Output is correct
15 Correct 19 ms 4192 KB Output is correct
16 Correct 9 ms 4192 KB Output is correct
17 Correct 9 ms 4192 KB Output is correct
18 Correct 16 ms 4192 KB Output is correct
19 Correct 16 ms 4192 KB Output is correct
20 Correct 15 ms 4192 KB Output is correct
21 Correct 19 ms 4192 KB Output is correct
22 Correct 16 ms 4192 KB Output is correct
23 Correct 22 ms 4192 KB Output is correct
24 Correct 12 ms 4192 KB Output is correct
25 Correct 19 ms 4192 KB Output is correct
26 Correct 22 ms 4192 KB Output is correct
27 Correct 25 ms 4192 KB Output is correct
28 Correct 12 ms 4192 KB Output is correct
29 Correct 16 ms 4192 KB Output is correct
30 Correct 16 ms 4192 KB Output is correct
31 Correct 12 ms 4192 KB Output is correct
32 Correct 16 ms 4192 KB Output is correct
33 Correct 19 ms 4192 KB Output is correct
34 Correct 9 ms 4192 KB Output is correct
35 Correct 12 ms 4192 KB Output is correct
36 Correct 19 ms 4192 KB Output is correct
37 Correct 9 ms 4192 KB Output is correct
38 Correct 12 ms 4192 KB Output is correct
39 Correct 9 ms 4192 KB Output is correct
40 Correct 16 ms 4192 KB Output is correct
41 Correct 9 ms 4192 KB Output is correct
42 Correct 12 ms 4192 KB Output is correct
43 Correct 12 ms 4192 KB Output is correct
44 Correct 9 ms 4192 KB Output is correct
45 Correct 16 ms 4192 KB Output is correct
46 Correct 16 ms 4192 KB Output is correct
47 Correct 16 ms 4192 KB Output is correct
48 Correct 16 ms 4192 KB Output is correct
49 Correct 16 ms 4192 KB Output is correct
50 Correct 9 ms 4192 KB Output is correct