Submission #26198

# Submission time Handle Problem Language Result Execution time Memory
26198 2017-06-28T10:20:02 Z kdh9949 None (JOI16_snowy) C++14
100 / 100
22 ms 2508 KB
#include "Anyalib.h"
#include <vector>
#include <algorithm>
using namespace std;

struct E{ int x, i; };

static int n, c[500], s[500];
static vector<int> sv;
static vector<E> e[500], t[500];

static int g(int x, int p){
	int ret = 0;
	for(auto &i : e[x]){
		if(i.x == p) continue;
		t[x].push_back(i);
		ret = max(ret, g(i.x, x) + 1);
	}
	if(ret >= 10){
		sv.push_back(x);
		ret = 0;
	}
	return ret;
}

static void f(int x, int d){
	s[x] = d;
	for(auto &i : t[x]){
		f(i.x, d + c[i.i]);
	}
}

void InitAnya(int N, int A[], int B[]){ 
	n = N;
	for(int i = 0; i < n - 1; i++){
		e[A[i]].push_back({B[i], i});
		e[B[i]].push_back({A[i], i});
	}
	g(0, 0);
}

void Anya(int C[]) {
	for(int i = 0; i < n - 1; i++){
		c[i] = C[i];
		Save(i, c[i]);
	}
	f(0, 0);
	for(int i = 0; i < sv.size(); i++){
		for(int j = 0; j < 10; j++){
			Save(n + 10 * i + j, !!(s[sv[i]] & (1 << j)));
		}
	}
}
#include "Borislib.h"
#include <vector>
#include <algorithm>
using namespace std;

struct F{ int x, i; };

static int n, s[500], sn[500];
static F par[500];
static vector<int> sv;
static vector<F> e[500], t[500];

static int g(int x, int p){
	int ret = 0;
	for(auto &i : e[x]){
		if(i.x == p) continue;
		par[i.x] = {x, i.i};
		t[x].push_back(i);
		ret = max(ret, g(i.x, x) + 1);
	}
	if(ret >= 10){
		sn[x] = int(sv.size() + 1);
		sv.push_back(x);
		ret = 0;
	}
	return ret;
}

static int f(int x){
	if(!x) return 0;
	if(sn[x]){
		int ret = 0;
		for(int i = 0; i < 10; i++) ret += Ask(n + (sn[x] - 1) * 10 + i) << i;
		return ret;
	}
	return f(par[x].x) + Ask(par[x].i);
}

void InitBoris(int N, int A[], int B[]) {
	n = N;
	for(int i = 0; i < n - 1; i++){
		e[A[i]].push_back({B[i], i});
		e[B[i]].push_back({A[i], i});
	}
	g(0, 0);
}

int Boris(int x){
	return f(x);
}

Compilation message

Anya.cpp: In function 'void Anya(int*)':
Anya.cpp:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < sv.size(); i++){
                   ^

Boris.cpp:8:15: warning: 's' defined but not used [-Wunused-variable]
 static int n, s[500], sn[500];
               ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2508 KB Output is correct
2 Correct 0 ms 2508 KB Output is correct
3 Correct 0 ms 2508 KB Output is correct
4 Correct 0 ms 2508 KB Output is correct
5 Correct 3 ms 2508 KB Output is correct
6 Correct 3 ms 2508 KB Output is correct
7 Correct 3 ms 2508 KB Output is correct
8 Correct 3 ms 2508 KB Output is correct
9 Correct 3 ms 2508 KB Output is correct
10 Correct 3 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2508 KB Output is correct
2 Correct 9 ms 2508 KB Output is correct
3 Correct 6 ms 2508 KB Output is correct
4 Correct 3 ms 2508 KB Output is correct
5 Correct 9 ms 2508 KB Output is correct
6 Correct 9 ms 2508 KB Output is correct
7 Correct 6 ms 2508 KB Output is correct
8 Correct 9 ms 2508 KB Output is correct
9 Correct 9 ms 2508 KB Output is correct
10 Correct 6 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2508 KB Output is correct
2 Correct 19 ms 2508 KB Output is correct
3 Correct 12 ms 2508 KB Output is correct
4 Correct 19 ms 2508 KB Output is correct
5 Correct 19 ms 2508 KB Output is correct
6 Correct 22 ms 2508 KB Output is correct
7 Correct 12 ms 2508 KB Output is correct
8 Correct 12 ms 2508 KB Output is correct
9 Correct 12 ms 2508 KB Output is correct
10 Correct 12 ms 2508 KB Output is correct
11 Correct 12 ms 2508 KB Output is correct
12 Correct 12 ms 2508 KB Output is correct
13 Correct 16 ms 2508 KB Output is correct
14 Correct 9 ms 2508 KB Output is correct
15 Correct 15 ms 2508 KB Output is correct
16 Correct 12 ms 2508 KB Output is correct
17 Correct 12 ms 2508 KB Output is correct
18 Correct 12 ms 2508 KB Output is correct
19 Correct 12 ms 2508 KB Output is correct
20 Correct 12 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2508 KB Output is correct
2 Correct 9 ms 2508 KB Output is correct
3 Correct 12 ms 2508 KB Output is correct
4 Correct 16 ms 2508 KB Output is correct
5 Correct 9 ms 2508 KB Output is correct
6 Correct 6 ms 2508 KB Output is correct
7 Correct 12 ms 2508 KB Output is correct
8 Correct 12 ms 2508 KB Output is correct
9 Correct 16 ms 2508 KB Output is correct
10 Correct 9 ms 2508 KB Output is correct
11 Correct 12 ms 2508 KB Output is correct
12 Correct 9 ms 2508 KB Output is correct
13 Correct 19 ms 2508 KB Output is correct
14 Correct 12 ms 2508 KB Output is correct
15 Correct 12 ms 2508 KB Output is correct
16 Correct 9 ms 2508 KB Output is correct
17 Correct 9 ms 2508 KB Output is correct
18 Correct 12 ms 2508 KB Output is correct
19 Correct 16 ms 2508 KB Output is correct
20 Correct 12 ms 2508 KB Output is correct
21 Correct 16 ms 2508 KB Output is correct
22 Correct 12 ms 2508 KB Output is correct
23 Correct 12 ms 2508 KB Output is correct
24 Correct 12 ms 2508 KB Output is correct
25 Correct 12 ms 2508 KB Output is correct
26 Correct 16 ms 2508 KB Output is correct
27 Correct 19 ms 2508 KB Output is correct
28 Correct 9 ms 2508 KB Output is correct
29 Correct 12 ms 2508 KB Output is correct
30 Correct 12 ms 2508 KB Output is correct
31 Correct 12 ms 2508 KB Output is correct
32 Correct 12 ms 2508 KB Output is correct
33 Correct 9 ms 2508 KB Output is correct
34 Correct 12 ms 2508 KB Output is correct
35 Correct 9 ms 2508 KB Output is correct
36 Correct 9 ms 2508 KB Output is correct
37 Correct 12 ms 2508 KB Output is correct
38 Correct 16 ms 2508 KB Output is correct
39 Correct 12 ms 2508 KB Output is correct
40 Correct 9 ms 2508 KB Output is correct
41 Correct 12 ms 2508 KB Output is correct
42 Correct 9 ms 2508 KB Output is correct
43 Correct 16 ms 2508 KB Output is correct
44 Correct 12 ms 2508 KB Output is correct
45 Correct 9 ms 2508 KB Output is correct
46 Correct 9 ms 2508 KB Output is correct
47 Correct 9 ms 2508 KB Output is correct
48 Correct 12 ms 2508 KB Output is correct
49 Correct 9 ms 2508 KB Output is correct
50 Correct 12 ms 2508 KB Output is correct