Submission #73122

# Submission time Handle Problem Language Result Execution time Memory
73122 2018-08-27T17:21:42 Z IvanC None (JOI16_snowy) C++17
100 / 100
31 ms 26228 KB
#include "Anyalib.h"
#include <bits/stdc++.h>
using namespace std;
 
const int MAXN = 1010;

static vector<int> grafo[MAXN],lista; 
static int N,distancia[MAXN],pai[MAXN],custo[MAXN],lastPtr,resposta[MAXN];
static int e1[MAXN],e2[MAXN],ini[MAXN],fim[MAXN],especial[MAXN],marcado[MAXN],jafoi[MAXN];

static void doSpecial(int v){

	if(marcado[v]) return;

	for(int passo = 1;passo <= 11;passo++){
		if(especial[v]) return;
		marcado[v] = 1;
		int i = pai[v];
		int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
		v = u;
	}

	marcado[v] = 1;
	especial[v] = 1;

}

static void bfs(){

	queue<int> fila;
	fila.push(0);
	jafoi[0] = 1;
	marcado[0] = 1;
	especial[0] = 1;

	while(!fila.empty()){
		int v = fila.front();
		fila.pop();
		lista.push_back(v);
		for(int i : grafo[v]){
			int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
			if(!jafoi[u]){
				jafoi[u] = 1;
				pai[u] = i;
				fila.push(u);
			}
		}
	}

	for(vector<int>::reverse_iterator it = lista.rbegin();it != lista.rend();it++){
		doSpecial(*it);
	}

}


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

	lastPtr = N-1;

	bfs();
	especial[0] = 0;

	for(int i = 0;i<N;i++){
		if(!especial[i]) continue;
		ini[i] = lastPtr;
		fim[i] = lastPtr + 8;
		lastPtr += 9;
	}

}
 
void Anya(int C[]){
	 
	 memset(resposta,0,sizeof(resposta));

	 for(int i = 0;i<N-1;i++){
	 	custo[i] = C[i];
	 	resposta[i] = C[i];
	 }

	for(int v : lista){
		if(v == 0){
			distancia[v] = 0;
			continue;
		}
		int i = pai[v];
		int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
		distancia[v] = distancia[u] + custo[i];
	}

	for(int v : lista){
		if(v == 0) continue;
		if(!especial[v]) continue;
		for(int i = ini[v],j = 0;i <= fim[v];i++,j++){
			if(distancia[v] & (1 << j)) resposta[i] = 1;
			else resposta[i] = 0;
		}
	}

	for(int i = 0 ; i < 1000 ; i++){
		Save(i , resposta[i]);
	}
 
}
#include "Borislib.h"
#include <bits/stdc++.h>
using namespace std;
 
const int MAXN = 1010;

static vector<int> grafo[MAXN],lista; 
static int N,pai[MAXN],lastPtr;
static int e1[MAXN],e2[MAXN],ini[MAXN],fim[MAXN],especial[MAXN],marcado[MAXN],jafoi[MAXN];

static void doSpecial(int v){

	if(marcado[v]) return;

	for(int passo = 1;passo <= 11;passo++){
		if(especial[v]) return;
		marcado[v] = 1;
		int i = pai[v];
		int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
		v = u;
	}

	marcado[v] = 1;
	especial[v] = 1;

}

static void bfs(){

	queue<int> fila;
	fila.push(0);
	jafoi[0] = 1;
	marcado[0] = 1;
	especial[0] = 1;

	while(!fila.empty()){
		int v = fila.front();
		fila.pop();
		lista.push_back(v);
		for(int i : grafo[v]){
			int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
			if(!jafoi[u]){
				jafoi[u] = 1;
				pai[u] = i;
				fila.push(u);
			}
		}
	}

	for(vector<int>::reverse_iterator it = lista.rbegin();it != lista.rend();it++){
		doSpecial(*it);
	}

}


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

	lastPtr = N-1;

	bfs();
	especial[0] = 0;

	for(int i = 0;i<N;i++){
		if(!especial[i]) continue;
		ini[i] = lastPtr;
		fim[i] = lastPtr + 8;
		lastPtr += 9;
	}

}

static int doQuery(int v){
	if(v == 0) return 0;
	if(especial[v]){
		int numero = 0;
		for(int i = ini[v],j = 0;i <= fim[v];i++,j++){
			if(Ask(i)) numero += (1 << j);
		}
		return numero;
	}
	else{
		int i = pai[v];
		int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
		return doQuery(u) + Ask(i);
	}
}
 
int Boris(int city) {
	return doQuery(city);
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 752 KB Output is correct
2 Correct 7 ms 1080 KB Output is correct
3 Correct 7 ms 1252 KB Output is correct
4 Correct 9 ms 1588 KB Output is correct
5 Correct 12 ms 1888 KB Output is correct
6 Correct 12 ms 1888 KB Output is correct
7 Correct 13 ms 1888 KB Output is correct
8 Correct 13 ms 1888 KB Output is correct
9 Correct 12 ms 1888 KB Output is correct
10 Correct 12 ms 1888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1888 KB Output is correct
2 Correct 13 ms 1920 KB Output is correct
3 Correct 13 ms 1920 KB Output is correct
4 Correct 16 ms 1920 KB Output is correct
5 Correct 17 ms 1920 KB Output is correct
6 Correct 15 ms 1920 KB Output is correct
7 Correct 12 ms 1920 KB Output is correct
8 Correct 16 ms 1920 KB Output is correct
9 Correct 13 ms 1920 KB Output is correct
10 Correct 13 ms 1928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1928 KB Output is correct
2 Correct 20 ms 1928 KB Output is correct
3 Correct 20 ms 1928 KB Output is correct
4 Correct 28 ms 1928 KB Output is correct
5 Correct 28 ms 1928 KB Output is correct
6 Correct 31 ms 1928 KB Output is correct
7 Correct 30 ms 1968 KB Output is correct
8 Correct 21 ms 2008 KB Output is correct
9 Correct 20 ms 2008 KB Output is correct
10 Correct 22 ms 2008 KB Output is correct
11 Correct 21 ms 2008 KB Output is correct
12 Correct 20 ms 2008 KB Output is correct
13 Correct 20 ms 2008 KB Output is correct
14 Correct 20 ms 2008 KB Output is correct
15 Correct 23 ms 2008 KB Output is correct
16 Correct 22 ms 2008 KB Output is correct
17 Correct 26 ms 2008 KB Output is correct
18 Correct 23 ms 2008 KB Output is correct
19 Correct 24 ms 2008 KB Output is correct
20 Correct 26 ms 2008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2176 KB Output is correct
2 Correct 18 ms 2176 KB Output is correct
3 Correct 20 ms 2176 KB Output is correct
4 Correct 18 ms 2432 KB Output is correct
5 Correct 23 ms 3008 KB Output is correct
6 Correct 20 ms 3584 KB Output is correct
7 Correct 20 ms 4096 KB Output is correct
8 Correct 25 ms 4608 KB Output is correct
9 Correct 19 ms 5120 KB Output is correct
10 Correct 25 ms 5632 KB Output is correct
11 Correct 22 ms 6144 KB Output is correct
12 Correct 18 ms 6656 KB Output is correct
13 Correct 22 ms 7168 KB Output is correct
14 Correct 22 ms 7744 KB Output is correct
15 Correct 24 ms 8336 KB Output is correct
16 Correct 24 ms 8768 KB Output is correct
17 Correct 21 ms 9384 KB Output is correct
18 Correct 27 ms 9760 KB Output is correct
19 Correct 20 ms 10280 KB Output is correct
20 Correct 25 ms 10904 KB Output is correct
21 Correct 23 ms 11280 KB Output is correct
22 Correct 20 ms 11808 KB Output is correct
23 Correct 20 ms 12320 KB Output is correct
24 Correct 28 ms 13088 KB Output is correct
25 Correct 22 ms 13352 KB Output is correct
26 Correct 23 ms 13856 KB Output is correct
27 Correct 20 ms 14368 KB Output is correct
28 Correct 22 ms 15128 KB Output is correct
29 Correct 25 ms 15392 KB Output is correct
30 Correct 20 ms 15992 KB Output is correct
31 Correct 27 ms 16504 KB Output is correct
32 Correct 25 ms 17016 KB Output is correct
33 Correct 22 ms 17440 KB Output is correct
34 Correct 20 ms 17952 KB Output is correct
35 Correct 28 ms 18720 KB Output is correct
36 Correct 21 ms 19088 KB Output is correct
37 Correct 22 ms 19488 KB Output is correct
38 Correct 20 ms 20000 KB Output is correct
39 Correct 20 ms 20512 KB Output is correct
40 Correct 21 ms 21032 KB Output is correct
41 Correct 20 ms 21536 KB Output is correct
42 Correct 23 ms 22084 KB Output is correct
43 Correct 20 ms 22560 KB Output is correct
44 Correct 20 ms 23080 KB Output is correct
45 Correct 18 ms 23584 KB Output is correct
46 Correct 19 ms 24096 KB Output is correct
47 Correct 24 ms 24864 KB Output is correct
48 Correct 20 ms 25120 KB Output is correct
49 Correct 20 ms 25632 KB Output is correct
50 Correct 22 ms 26228 KB Output is correct