Submission #94337

#TimeUsernameProblemLanguageResultExecution timeMemory
94337fedoseevtimofeyXylophone (JOI18_xylophone)C++14
100 / 100
392 ms424 KiB
#include "xylophone.h"
#include "bits/stdc++.h"

using namespace std;

int my_query(int l, int r, vector <int> &a) {
    int mx = -1e9, mn = 1e9;
    for (int i = l; i <= r; ++i) {
        mx = max(mx, a[i]);
        mn = min(mn, a[i]);
    }
    return mx - mn;
}

void solve(int n) {
    vector <int> a(n + 1);
    a[1] = 0;
    a[2] = query(1, 2);
    for (int i = 3; i <= n; ++i) {
        int x = query(i - 2, i);
        int y = query(i - 1, i);
        for (int z = -n; z <= n; ++z) {
            a[i] = z;
            if (my_query(i - 2, i, a) == x && my_query(i - 1, i, a) == y) {
                break;
            }
        }
    }
    int mn = 1e9;
    for (int i = 1; i <= n; ++i) mn = min(mn, a[i]);
    for (int i = 1; i <= n; ++i) a[i] -= mn - 1;
    bool fl = false;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (a[i] == 1 && a[j] == n) {
                if (i > j) {
                    fl = true;
                }   
            }
        }
    }
    if (fl) {
        for (int i = 1; i <= n; ++i) {
            a[i] = n - a[i] + 1;
        }
    }
    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...