Submission #72984

# Submission time Handle Problem Language Result Execution time Memory
72984 2018-08-27T12:07:32 Z IvanC None (JOI16_snowy) C++17
0 / 100
23 ms 3016 KB
#include "Anyalib.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 510;
const int L_SZ = 1000;
const int MOD = 12;

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

static void dfs_build(int v,int p,int sp,int depth){

	if(depth % 12 == 0){
		sp = v;
		especial[v] = 1;
		ini[v] = lastPtr;
		fim[v] = lastPtr + 8;
		lastPtr += 9;
	}

	for(int i : grafo[v]){
		int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
		if(u == p) continue;
		pai[u] = i;
		dfs_build(u,v,sp,depth + 1);
	}

}

static void dfs_calculate(int v,int p,int dist){

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

	for(int i : grafo[v]){
		int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
		if(u == p) continue;
		dfs_calculate(u,v,dist + custo[i]);
	}

}

void InitAnya(int n , int A[] , int B[]) {

	N = n;

	for(int i = 0;i<N-1;i++){
		grafo[A[i]].push_back(B[i]);
		grafo[B[i]].push_back(A[i]);
	}

	lastPtr = N - 1;

	dfs_build(0,-1,-1,0);

}

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

	dfs_calculate(0,-1,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 = 510;
const int L_SZ = 1000;
const int MOD = 12;

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

static void dfs_build(int v,int p,int sp,int depth){

	if(depth % 12 == 0){
		sp = v;
		especial[v] = 1;
		ini[v] = lastPtr;
		fim[v] = lastPtr + 8;
		lastPtr += 9;
	}

	for(int i : grafo[v]){
		int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
		if(u == p) continue;
		pai[u] = i;
		dfs_build(u,v,sp,depth + 1);
	}

}

static int doQuery(int v){
	
	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 Ask(i) + doQuery(u);
	}

}

void InitBoris(int n , int A[] , int B[]) {

	N = n;

	for(int i = 0;i<N-1;i++){
		grafo[A[i]].push_back(B[i]);
		grafo[B[i]].push_back(A[i]);
	}

	lastPtr = N - 1;

	dfs_build(0,-1,-1,0);

}

int Boris(int city) {
	return doQuery(city);
}

Compilation message

Anya.cpp: In function 'void Anya(int*)':
Anya.cpp:71:38: warning: iteration 510 invokes undefined behavior [-Waggressive-loop-optimizations]
  for(int i = 0 ; i < 1000 ; i++) Save(i , resposta[i]);
                                  ~~~~^~~~~~~~~~~~~~~~~
Anya.cpp:71:20: note: within this loop
  for(int i = 0 ; i < 1000 ; i++) Save(i , resposta[i]);
                  ~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 812 KB Output is correct
2 Incorrect 6 ms 1172 KB Wrong Answer [7]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1744 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 2476 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 3016 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -