Submission #67183

# Submission time Handle Problem Language Result Execution time Memory
67183 2018-08-13T13:54:38 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;
}

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 solve(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 'void solve(int)':
xylophone.cpp:69:43: error: 'ask' was not declared in this scope
  for(int i = 0; i + 1 < n; i++) ask2[i] = ask(i, i + 1);
                                           ^~~
xylophone.cpp:69:43: note: suggested alternative: 'ask3'
  for(int i = 0; i + 1 < n; i++) ask2[i] = ask(i, i + 1);
                                           ^~~
                                           ask3
xylophone.cpp:70:43: error: 'ask' was not declared in this scope
  for(int i = 0; i + 2 < n; i++) ask3[i] = ask(i, i + 2);
                                           ^~~
xylophone.cpp:70:43: note: suggested alternative: 'ask3'
  for(int i = 0; i + 2 < n; i++) ask3[i] = ask(i, i + 2);
                                           ^~~
                                           ask3