Submission #793103

# Submission time Handle Problem Language Result Execution time Memory
793103 2023-07-25T13:58:06 Z MODDI Xylophone (JOI18_xylophone) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "xylophone.h"
#include "grader.cpp"
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
//static int A[5000];
void solve(int n) {
	int l = 1, r = n; // position where one is at
	while(r-l>1){
		int mid = (l + r) / 2;
		int ans = query(mid, n);
		if(ans == n-1){
			l = mid;
		}
		else
			r = mid;
	}
	answer(l, 1);
	int arr[n+1];
	memset(arr, -1, sizeof arr);
	arr[l] = 1;
	bool vis[n+1];
	memset(vis, false, sizeof vis);
	vis[1] = true;
	if(l + 1 <= n){
		int d = query(l, l+1);
		arr[l+1] = d+1;
		vis[arr[l+1]]=true;
		answer(l+1, arr[l+1]);
	}
	for(int j = l + 2; j <= n; j++){
		int d = query(j-1, j);
		if(arr[j-1] - d < 1 || vis[arr[j-1]-d]){
			vis[arr[j-1]+d] = true;
			arr[j] = arr[j-1] + d;
			answer(j, arr[j]);
		}
		else if(arr[j-1]+d > n || vis[arr[j-1]+d]){
			vis[arr[j-1]-d] = true;
			arr[j] = arr[j-1] - d;
			answer(j, arr[j]);
		}
		else{
			int l = query(j-2, j);
			if(l == max(d, abs(arr[j-1] - arr[j-2]))){
				if(arr[j-2] < arr[j-1]){
					vis[arr[j-1] - d] = true;
					arr[j] = arr[j-1]-d;
					answer(j, arr[j]);
				}
				else{
					vis[arr[j-1]+d] = true;
					arr[j] = arr[j-1]+d;
					answer(j, arr[j]);
				}
			}
			else{
				if(arr[j-2] < arr[j-1]){
					vis[arr[j-1] + d] = true;
					arr[j] = arr[j-1]+d;
					answer(j, arr[j]);
				}
				else{
					vis[arr[j-1]-d] = true;
					arr[j] = arr[j-1]-d;
					answer(j, arr[j]);
				}
			}
		}
	}
	if(l-1 > 0){
		int d = query(l-1, l);
		arr[l-1] = d + 1;
		vis[arr[l-1]] = true;
		answer(l-1, arr[l-1]);
	}
	for(int i = l - 2; i >= 1; i--){
		int d=query(i,i+1);
        if(arr[i+1]-d<1||vis[arr[i+1]-d]){
			arr[i] = arr[i+1] + d;
			vis[arr[i]] = true;
			answer(i, arr[i]);
		}
        else if(arr[i+1]+d>n||vis[arr[i+1]+d]){
			arr[i] = arr[i+1] - d;
			vis[arr[i]] = true;
			answer(i, arr[i]);
		}
        else
        {
            int l=query(i,i+2);
            if(l==max(d,abs(arr[i+1]-arr[i+2])))
            {
                if(arr[i+2]<arr[i+1]){
					arr[i] = arr[i+1] - d;
					vis[arr[i]] = true;
					answer(i, arr[i]);
				}
                else{
					arr[i] = arr[i+1] + d;
					vis[arr[i]] = true;
					answer(i, arr[i]);
				}
            }
            else
            {
                if(arr[i+2]<arr[i+1]){
					arr[i] = arr[i+1] + d;
					vis[arr[i]] = true;
					answer(i, arr[i]);
				}
                else{
					arr[i] = arr[i+1] - d;
					vis[arr[i]] = true;
					answer(i, arr[i]);
				}
            }
        }
	}
}

Compilation message

/usr/bin/ld: /tmp/ccv2JKRY.o: in function `query(int, int)':
grader.cpp:(.text+0x0): multiple definition of `query(int, int)'; /tmp/ccbewUSY.o:xylophone.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccv2JKRY.o: in function `answer(int, int)':
grader.cpp:(.text+0xa0): multiple definition of `answer(int, int)'; /tmp/ccbewUSY.o:xylophone.cpp:(.text+0xa0): first defined here
/usr/bin/ld: /tmp/ccv2JKRY.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccbewUSY.o:xylophone.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status