Submission #67318

# Submission time Handle Problem Language Result Execution time Memory
67318 2018-08-13T23:19:48 Z IvanC Xylophone (JOI18_xylophone) C++17
Compilation error
0 ms 0 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5010;

static int A[MAXN],Q2[MAXN],Q3[MAXN],freq[MAXN],N,distinct;

static void add_num(int x){
	if(freq[x] == 0) distinct++;
	freq[x]++;
}

int coerencia(int X){
	if(abs(A[X+1] - A[X]) != Q2[X]) return 0;
	if(abs(A[X+2] - A[X+1]) != Q2[X+1]) return 0;
	if(max(max(A[X],A[X+1]),A[X+2]) - min(min(A[X],A[X+1]),A[X+2]) != Q3[X]) return 0;
	if(max(max(A[X],A[X+1]),A[X+2]) >= N) return 0;
	if(min(min(A[X],A[X+1]),A[X+2]) < 0) return 0;
	if(freq[A[X]] > 1 || freq[A[X+1]] > 1 || freq[A[X+2]] > 1) return 0;
	return 1;
}

void avanca_direita(int X){
	if(X < 0 || X >= N) return;
	//printf("AD %d\n",X);
	A[X] = (A[X-1] + Q2[X-1]);
	if(!coerencia(X-2)){
		A[X] = (A[X-1] - Q2[X-1]);
		if(!coerencia(X-2)){
			//printf("Falhou\n");
			return;
		}
		else{
			//printf("Foi2 %d\n",A[X]);
			add_num(A[X]);
			avanca_direita(X+1);
		}
	}
	else{
		//printf("Foi1 %d\n",A[X]);
		add_num(A[X]);
		avanca_direita(X+1);
	}
}

void avanca_esquerda(int X){
	if(X < 0 || X >= N) return;
	A[X] = A[X+1] + Q2[X];
	if(!coerencia(X)){
		A[X] = A[X+1] - Q2[X];
		if(!coerencia(X)){
			return;
		}
		else{
			add_num(A[X]);
			avanca_esquerda(X-1);
		}
	}
	else{
		add_num(A[X]);
		avanca_esquerda(X-1);
	}
}

int testa(int pos){
	
	//printf("POS %d\n", pos);

	memset(A,0,sizeof(A));
	memset(freq,0,sizeof(freq));
	distinct = 0;

	add_num(0);
	A[pos] = 0;
	if(pos - 1 >= 0){
		A[pos-1] = 0 + Q2[pos-1];
		add_num(A[pos-1]);
	}
	if(pos + 1 < N){
		A[pos+1] = 0 + Q2[pos];
		add_num(A[pos+1]);
	}

	avanca_direita(pos+2);
	avanca_esquerda(pos-2);

	if(distinct != N){
		//printf("##########\n");
		return 0;
	}

	for(int i = 0;i<N;i++){
		//printf("%d ",A[i]);
		answer(i+1,A[i]+1);
	}
	//printf("\n");

	return 1;

}

void detect_pitch(int n) {

	N = n;

	for(int i = 0;i+1<N;i++) Q2[i] = query(i+1,i+2);
	for(int i = 0;i+2<N;i++) Q3[i] = query(i+1,i+3);
 
 	//printf("#################\n");
 	//for(int i = 0;i+1<N;i++){
 	//	printf("%d ",Q2[i]);
 	//}
 	//printf("\n");
 	//for(int i = 0;i+1<N;i++){
 	//	printf("%d ",Q3[i]);
 	//}
 	//printf("\n");
 	//printf("###################\n");

 	for(int i = 0;i<N;i++){
 		if(testa(i)){
 			break;
 		}
 	} query

Compilation message

xylophone.cpp: In function 'void detect_pitch(int)':
xylophone.cpp:125:5: error: expected ';' at end of input
   } query
     ^~~~~
xylophone.cpp:125:5: warning: statement is a reference, not call, to function 'query' [-Waddress]
xylophone.cpp:125:5: warning: statement has no effect [-Wunused-value]
xylophone.cpp:125:5: error: expected '}' at end of input