Submission #702854

#TimeUsernameProblemLanguageResultExecution timeMemory
702854ecxxXylophone (JOI18_xylophone)C++17
100 / 100
114 ms380 KiB
#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;

void solve(int N) {
    vector<int> pairwise(N);
    vector<int> triplet(N-1);

    for (int i = 0; i < N-1; i++) pairwise[i]=query(i+1,i+2);
    for (int i = 0; i < N-2; i++) triplet[i]=query(i+1,i+3);

    vector<int> ans(N, 0);

    ans[1] = pairwise[0];

    for (int i = 2; i < N; i++) {
        if (triplet[i-2] == pairwise[i-2] + pairwise[i-1]) {
            if (ans[i-2] < ans[i-1]) {
                ans[i] = ans[i-1] + pairwise[i-1];
            } else {
                ans[i] = ans[i-1] - pairwise[i-1];
            }
        } else {
            if (ans[i-2] < ans[i-1]) {
                ans[i] = ans[i-1] - pairwise[i-1];
            } else {
                ans[i] = ans[i-1] + pairwise[i-1];
            }
        }
    }

    int mn=10000, mx=-10000;
    int mnpos=-1, mxpos=-1;

    for (int i = 0; i < N; i++) {
        if (mn>ans[i]) {mnpos=i; mn = ans[i];}
        if (mx<ans[i]) {mxpos=i; mx = ans[i];}
    }

    for (int i = 0; i < N; i++) ans[i] -= (mn-1);

    if (mnpos > mxpos) {
        for (int i = 0; i < N; i++) {
            ans[i] = N+1 - ans[i];
        }
    }

    for (int i = 0; i < N; i++) answer(i+1, ans[i]);

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