제출 #448346

#제출 시각아이디문제언어결과실행 시간메모리
448346JovanBXylophone (JOI18_xylophone)C++17
100 / 100
140 ms472 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
 
static int A[5000];
 
int dva[5005];
int tri[5005];
int res[5005];
 
int nadji(int a, int b, int c){
    return max(abs(a-c), max(abs(a-b), abs(b-c)));
}
 
void solve(int N) {
    if(N == 1){
        answer(1, 1);
        return;
    }
    for(int i=1; i<N; i++){
        dva[i] = query(i, i+1);
    }
    for(int i=1; i<N-1; i++){
        tri[i] = query(i, i+2);
    }
    res[2] = dva[1];
    for(int i=3; i<=N; i++){
        if(nadji(res[i-2], res[i-1], dva[i-1] + res[i-1]) == tri[i-2]) res[i] = dva[i-1] + res[i-1];
        else res[i] = res[i-1] - dva[i-1];
    }
    int mn = 0;
    for(int i=1; i<=N; i++){
        mn = min(mn, res[i]);
    }
    for(int i=1; i<=N; i++){
        res[i] += 1-mn;
    }
    int b1 = 0, bn = 0;
    for(int i=1; i<=N; i++){
        if(res[i] == 1) b1 = i;
        else if(res[i] == N) bn = i;
    }
    if(b1 > bn){
        for(int i=1; i<=N; i++) res[i] = N-res[i]+1;
    }
    for(int i=1; i<=N; i++){
        answer(i, res[i]);
    }
}

컴파일 시 표준 에러 (stderr) 메시지

xylophone.cpp:6:12: warning: 'A' defined but not used [-Wunused-variable]
    6 | static int A[5000];
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...