제출 #419633

#제출 시각아이디문제언어결과실행 시간메모리
419633Emin2004Xylophone (JOI18_xylophone)C++14
0 / 100
0 ms200 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int, ll>
#define F first
#define S second

const int N = 100005;
const int mod = 1e9;

static int a[5005];
int found[N];

void solve(int n) {
    int l = 1;
    int pos = -1;
    while(l < n - 1){
        int x = query(l + 1, n);
        if(x + 1 != n){
            pos = l;
            break;
        }
        l++;
    }
    a[pos] = 1;
    found[1] = 1;
    int r = query(pos, pos + 1) + 1;
    a[pos + 1] = r;
    found[r] = 1;
    for(int i = pos + 2; i <= n; i++){
        int x = query(i - 1, i);
        int c1 = a[i - 1] - x;
        int c2 = a[i - 1] + x;
        if(c1 < 0 || found[c1] == 1){
            a[i] = c2;
            found[c2] = 1;
        }
        else if(c2 > n || found[c2] == 1){
            a[i] = c1;
            found[c1] = 1;
        }
        else{
            int y = query(i - 2, i);
            if(y > x){
                a[i] = c2;
                found[c2] = 1;
            }
            else{
                a[i] = c1;
                found[c1] = 1;
            }
        }
    }
    for(int i = pos - 1; i > 0; i--){
        int x = query(i, i + 1);
        int c1 = a[i + 1] - x;
        int c2 = a[i + 1] + x;
        if(c1 < 0 || found[c1] == 1){
            a[i] = c2;
            found[c2] = 1;
        }
        else if(c2 < 0 || found[c2] == 1){
            a[i] = c1;
            found[c1] = 1;
        }
        else{
            int y = query(i, i + 2);
            if(y > x){
                a[i] = c2;
                found[c2] = 1;
            }
            else{
                a[i] = c1;
                found[c1] = 1;
            }
        }
    }
	for(int i = 1; i <= n; i++) {
		answer(i, a[i]);
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...