답안 #98840

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98840 2019-02-26T13:06:42 Z janchomath Xylophone (JOI18_xylophone) C++14
컴파일 오류
0 ms 0 KB
#include "grader.cpp"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool fix[200005];
ll ans[200005],ind;
void solve(int n) {
	ll l = 2,r = n,mid = 0;
	
	while(l <= r){
		mid = (l + r) / 2;
		ll curans = query(1,mid);
	//	cout << 1 << " " << mid << " " << curans << endl;
		if(curans != n - 1){
			l = mid + 1;
		}
		else {
			ind = mid;
			r = mid - 1;
		}
	}
	
	cout << ind << endl;
	
	ans[ind] = n;
	fix[n] = 1;
	if(ind != n)ans[ind + 1] = n - query(ind,ind + 1);
	
	for(int i=ind+1; i<=n; i++){
		fix[ans[i]] = 1;
		if(i == n){
			break;
		}
		ll k1 = query(i,i + 1);
		if(ans[i] + k1 >= n || fix[ans[i] + k1]){
			ans[i + 1] = ans[i] - k1;
			continue;
		}
		if(ans[i] - k1 <= 0 || fix[ans[i] - k1]){
			ans[i + 1] = ans[i] - k1;
			continue;
		}
		ll k2 = query(i - 1,i + 1);
		
		if(ans[i - 1] < ans[i]){
			if(k2 == k1 + ans[i] - ans[i - 1]){
				ans[i + 1] = ans[i] + k1;
			}
			else {
				ans[i + 1] = ans[i] - k1;
			}
		}
		else {
			if(k2 == k1 + ans[i - 1] - ans[i]){
				ans[i + 1] = ans[i] - k1;
			}
			else {
				ans[i + 1] = ans[i] + k1;
			}
		}
	}
	
	if(ind > 1)ans[ind - 1] = n - query(ind-1,ind);
	cout << ans[2] << " ";
	for(int i=ind - 1; i>=1; i--){
		if(i == 1){
			break;
		}
		ll k1 = query(i - 1,i);
		if(ans[i] + k1 >= n || fix[ans[i] + k1]){
			ans[i - 1] = ans[i] - k1;
			continue;
		}
		if(ans[i] - k1 <= 0 || fix[ans[i] - k1]){
			ans[i - 1] = ans[i] - k1;
			continue;
		}
		cout << "GG";
		ll k2 = query(i - 1,i + 1);
		
		if(ans[i + 1] < ans[i]){
			if(k2 == k1 + ans[i] - ans[i - 1]){
				ans[i - 1] = ans[i] + k1;
			}
			else {
				ans[i - 1] = ans[i] - k1;
			}
		}
		else {
			if(k2 == k1 + ans[i + 1] - ans[i]){
				ans[i - 1] = ans[i] - k1;
			}
			else {
				ans[i - 1] = ans[i] + k1;
			}
		}
	}
	
	for(int i=1; i<=n; i++){
		cout << ans[i] << " ";
		answer(i,ans[i]);
	}
	
}

Compilation message

/tmp/ccyL1Irl.o: In function `query(int, int)':
grader.cpp:(.text+0x0): multiple definition of `query(int, int)'
/tmp/cc3bUMxg.o:xylophone.cpp:(.text+0x0): first defined here
/tmp/ccyL1Irl.o: In function `answer(int, int)':
grader.cpp:(.text+0x90): multiple definition of `answer(int, int)'
/tmp/cc3bUMxg.o:xylophone.cpp:(.text+0x90): first defined here
/tmp/ccyL1Irl.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc3bUMxg.o:xylophone.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status