제출 #521309

#제출 시각아이디문제언어결과실행 시간메모리
521309cig32Xylophone (JOI18_xylophone)C++17
100 / 100
106 ms324 KiB
#include "bits/stdc++.h"
#include "xylophone.h"
using namespace std;
void solve(int N) {
    int res[N+1];
	int val = query(1, 2);
    res[1] = 0;
    res[2] = res[1] + val;
    for(int i=3; i<=N; i++) {
        int op1 = query(i-1, i);
        int op2 = query(i-2, i);
        if(op1 + val == op2) {
            res[i] = (res[i-2] < res[i-1] ? res[i-1] + op1 : res[i-1] - op1);
        }
        else {
            res[i] = (res[i-2] < res[i-1] ? res[i-1] - op1 : res[i-1] + op1);
        }
        val = op1;
    }
    int mx = 0;
    for(int i=1; i<=N; i++) mx = max(mx, res[i]);
    for(int i=1; i<=N; i++) res[i] += N - mx;
    int pos[N+1];
    for(int i=1; i<=N; i++) pos[res[i]] = i;
    if(pos[1] > pos[N]) {
        for(int i=1; i<=N; i++) res[i] = N+1 - res[i];
    }
    for(int i=1; i<=N; i++) answer(i, res[i]);

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...