Submission #586889

#TimeUsernameProblemLanguageResultExecution timeMemory
586889stevancvXylophone (JOI18_xylophone)C++14
100 / 100
147 ms328 KiB
#include <bits/stdc++.h>
#include "xylophone.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
void solve(int n) {
    vector<int> a(n);
    for (int i = 1; i < n; i++) {
        a[i] = query(i, i + 1);
    }
    vector<bool> b(n - 1);
    for (int i = 1; i < n - 1; i++) {
        int x = query(i, i + 2);
        if (x == a[i] + a[i + 1]) b[i] = 1;
    }
    vector<int> ans(n + 1);
    auto Can = [&] (int x) {
        ans[x] = 1;
        int tr = 1;
        int up = 1;
        for (int i = x - 1; i >= 1; i--) {
            if (i == x - 1) {
                tr += a[i];
                ans[i] = tr;
                continue;
            }
            if (b[i] == 0) up ^= 1;
            if (up == 1) tr += a[i];
            else tr -= a[i];
            ans[i] = tr;
        }
        tr = 1;
        up = 1;
        for (int i = x + 1; i <= n; i++) {
            if (i == x + 1) {
                tr += a[i - 1];
                ans[i] = tr;
                continue;
            }
            if (b[i - 2] == 0) up ^= 1;
            if (up == 1) tr += a[i - 1];
            else tr -= a[i - 1];
            ans[i] = tr;
        }
        bool p = 0;
        for (int i = 1; i <= n; i++) {
            if (ans[i] <= 0) return false;
            if (i > x && ans[i] == n) p = 1;
        }
        return p;
    };
    for (int i = 1; i <= n; i++) {
        if (Can(i)) {
            for (int j = 1; j <= n; j++) answer(j, ans[j]);
            return;
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...