제출 #763296

#제출 시각아이디문제언어결과실행 시간메모리
763296giaminh2211Xylophone (JOI18_xylophone)C++14
100 / 100
87 ms568 KiB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

int re[300005];
int a[300005];
int b[300005];

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

    for (int i = 1; i <= N - 2; i++) {
        b[i] = query(i, i + 2);
    }

    re[1] = 1;

    for (int i = 1; i <= N - 2; i++) {
        if (a[i] + a[i + 1] == b[i]) {
            re[i + 1] = re[i];
        } else {
            re[i + 1] = -re[i];
        }
    }

    a[N] = 0;
    int Min = 0;

    for (int i = N - 1; i >= 1; i--) {
        a[i] = a[i + 1] - re[i] * a[i];
        Min = min(Min, a[i]);
    }

    for (int i = 1; i <= N; i++) {
        a[i] = a[i] - Min + 1;
    }

    for (int i = 1; i <= N; i++) {
        if (a[i] == 1) {
            break;
        }

        if (a[i] == N) {
            for (int j = 1; j <= N; j++) {
                a[j] = N + 1 - a[j];
            }
            break;
        }
    }

    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...