Submission #66277

# Submission time Handle Problem Language Result Execution time Memory
66277 2018-08-10T07:18:24 Z zadrga Xylophone (JOI18_xylophone) C++14
0 / 100
2 ms 248 KB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (int) (2 * 1e9)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 5111

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

//static int A[5000];

int ret[maxn];
bool used[maxn];


void solve(int N){
	int l = 2, d = N, mid, max_ind = N;
	while(l <= d){
		int mid = (l + d) / 2;
		int val = query(1, mid);
		if(val == N - 1){
			max_ind = mid;
			d = mid - 1;
		}
		else
			l = mid + 1; 
	}

	ret[max_ind] = N;
	used[N] = 1;

	int cur = query(max_ind, max_ind + 1);
	ret[max_ind + 1] = N - cur;
	used[N - cur] = 1;

	cur = query(max_ind - 1, max_ind);
	ret[max_ind - 1] = N - cur;
	used[N - cur] = 1;

	for(int i = max_ind + 2; i <= N; i++){
		int diff = query(i - 1, i);
		int opt1 = ret[i - 1] + diff;
		int opt2 = ret[i - 1] - diff;

		if(opt1 < 1 || opt1 > N || used[opt1]){
			ret[i] = opt2;
			used[ret[i]] = 1;
			continue;
		}

		if(opt2 < 1 || opt2 > N || used[opt2]){
			ret[i] = opt1;
			used[ret[i]] = 1;
			continue;
		}



		int updown = query(i - 2, i);
		if(max(ret[i - 2], max(ret[i - 1], opt1)) - min(ret[i - 2], min(ret[i - 1], opt1)) == updown){
			ret[i] = opt1;
		}
		else
			ret[i] = opt2;

		used[ret[i]] = 1;
	}

	for(int i = max_ind - 2; i >= 1; i--){
		int diff = query(i, i + 1);
		int opt1 = ret[i + 1] + diff;
		int opt2 = ret[i + 1] - diff;

		if(opt1 < 1 || opt1 > N || used[opt1]){
			ret[i] = opt2;
			used[ret[i]] = 1;
			continue;
		}

		if(opt2 < 1 || opt2 > N || used[opt2]){
			ret[i] = opt1;
			used[ret[i]] = 1;
			continue;
		}

		int updown = query(i, i + 2);
		if(max(ret[i + 2], max(ret[i + 1], opt1)) - min(ret[i + 2], min(ret[i + 1], opt1)) == updown){
			ret[i] = opt1;
		}
		else
			ret[i] = opt2;

		used[ret[i]] = 1;
	}

	for(int i = 1; i <= N; i++)
		answer(i, ret[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:25:20: warning: unused variable 'mid' [-Wunused-variable]
  int l = 2, d = N, mid, max_ind = N;
                    ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -