제출 #1335458

#제출 시각아이디문제언어결과실행 시간메모리
1335458trandaihao5555Xylophone (JOI18_xylophone)C++20
100 / 100
34 ms448 KiB
#include "xylophone.h"

#include <bits/stdc++.h>
using namespace std;

const int MaxN = 5007;
int a[MaxN];
int pos[MaxN];

void solve(int N) {

//	int value = query(1, N);
//
//	for(int i = 1; i <= N; i++) {
//		answer(i, i);
//	}


    a[1] = 0;
    a[2] = query(1,2);
    for(int i=3;i<=N;i++) {
        int bc = query(i-1,i);
        int abc = query(i-2,i);
        int ab = abs(a[i-1] - a[i-2]);
        if (ab == abc || bc == abc) {
            if (a[i-2] < a[i-1]) {
                a[i] = a[i-1] - bc;
            }
            else a[i] = a[i-1] + bc;
        }
        else {
            if (a[i-2] < a[i-1]) a[i] = a[i-1] + bc;
            else a[i] = a[i -1] - bc;
        }
    }
//    for (int i=1;i<=N;i++) cerr << a[i] << ' '; cerr << '\n';
    int amin = 1e6;
    for (int i=1;i<=N;i++) amin = min(amin,a[i]);
    for (int i=1;i<=N;i++) a[i] -= amin - 1;
    for (int i=1;i<=N;i++) pos[a[i]] = i;
    if (pos[1] > pos[N]) {
        for (int i=1;i<=N;i++) a[i] = N + 1 - a[i];
    }
//    for (int i=1;i<=N;i++) cerr << a[i] << ' '; cerr << '\n';
    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...