Submission #67184

# Submission time Handle Problem Language Result Execution time Memory
67184 2018-08-13T13:55:51 Z radoslav11 Xylophone (JOI18_xylophone) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "xylophone.h"
//#include "Lgrader.cpp"

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (5042);

int n;

bool check(vector<int> p)
{
	vector<bool> used(p.size(), 0);

	int pmax, pmin, mx = -1, mn = (int)1e9;
	for(int i = 0; i < n; i++)
	{
		if(chkmax(mx, p[i])) pmax = i;
		if(chkmin(mn, p[i])) pmin = i;
	
		if(p[i] >= n) return false;
		if(used[p[i]]) return false;
		used[p[i]] = true;
	}

	if((mx != (int)p.size() - 1) || mn != 0 || pmax < pmin)
		return false;

	return true;
}

int ask(int l, int r) { return query(l, r); }

void fix(vector<int> &p)
{
	int mn = 1e9;
	for(int &x: p)
		chkmin(mn, x);

	for(int &x: p)
		x += -mn;

	//for(int x: p)
	//	cerr << x << " ";
	//cerr << endl << flush;
}

int ask2[MAXN], ask3[MAXN];

int my_ask(int a, int b, int c)
{
	int ret = 0;
	
	chkmax(ret, a - b);
	chkmax(ret, b - a);

	chkmax(ret, a - c);
	chkmax(ret, c - a);

	chkmax(ret, c - b);
	chkmax(ret, b - c);

	return ret;
}

void detect_pitch(int N) 
{
	n = N;

	for(int i = 0; i + 1 < n; i++) ask2[i] = ask(i, i + 1);
	for(int i = 0; i + 2 < n; i++) ask3[i] = ask(i, i + 2);

	vector<int> A(n, 0);
	A[0] = 0;
	A[1] = ask2[0];

	for(int i = 2; i < n; i++)
	{
		if(my_ask(A[i - 2], A[i - 1], A[i - 1] + ask2[i - 1]) == ask3[i - 2]) A[i] = A[i - 1] + ask2[i - 1];
		else A[i] = A[i - 1] - ask2[i - 1];
	}

	fix(A);
	if(check(A))
	{
		for(int i = 0; i < n; i++)
			answer(i, A[i]);
		return;
	}

	A.assign(n, 0);
	A[0] = 0;
	A[1] = -ask2[0];

	for(int i = 2; i < n; i++)
	{
		if(my_ask(A[i - 2], A[i - 1], A[i - 1] + ask2[i - 1]) == ask3[i - 2]) A[i] = A[i - 1] + ask2[i - 1];
		else A[i] = A[i - 1] - ask2[i - 1];
	}

	fix(A);
	if(check(A))
	{
		for(int i = 0; i < n; i++)
			answer(i, A[i]);
		return;
	}
}

Compilation message

xylophone.cpp: In function 'bool check(std::vector<int>)':
xylophone.cpp:27:42: warning: 'pmin' may be used uninitialized in this function [-Wmaybe-uninitialized]
  if((mx != (int)p.size() - 1) || mn != 0 || pmax < pmin)
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
xylophone.cpp:27:42: warning: 'pmax' may be used uninitialized in this function [-Wmaybe-uninitialized]
/tmp/cca2gzPt.o: In function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `solve(int)'
collect2: error: ld returned 1 exit status