제출 #1330292

#제출 시각아이디문제언어결과실행 시간메모리
1330292AgageldiXylophone (JOI18_xylophone)C++20
100 / 100
35 ms456 KiB
#include "bits/stdc++.h"
#include "xylophone.h"
// #include "grader.cpp"
using namespace std;

int a[5001], D1[100000], D2[100000];

void solve(int N) {
    for(int i = 1; i < N; i++) {
        D1[i] = query(i, i + 1);
    }
    for(int i = 1; i < N - 1; i++) {
        D2[i] = query(i, i + 2);
    }

    a[1] = 0;
    a[2] = D1[1];
    int sign = 1;

    for(int i = 2; i < N; i++) {
        if (D2[i-1] != D1[i-1] + D1[i]) {
            sign *= -1;
        }
        a[i+1] = a[i] + (sign * D1[i]);
    }

    int mn = a[1], mx = a[1];
    int p_min = 1, p_max = 1;
    for(int i = 1; i <= N; i++) {
        if(a[i] < mn) { mn = a[i]; p_min = i; }
        if(a[i] > mx) { mx = a[i]; p_max = i; }
    }

    if(p_min > p_max) {
        for(int i = 1; i <= N; i++) a[i] = -a[i];
        mn = -mx;
    }

    for(int i = 1; i <= N; i++) {
        answer(i, a[i] - mn + 1);
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...