Submission #163551

# Submission time Handle Problem Language Result Execution time Memory
163551 2019-11-13T19:34:40 Z DS007 Xylophone (JOI18_xylophone) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

/*int query(int u, int v) {return -1;}
void answer(int u, int v) {;}
void solve(int n);
int main() {
    solve(69);
}*/

int solve(int n) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int d = query(1, n);
    int l = 1, h = n, ans1 = -1;
    while (l <= h) {
        int m = (l + h) / 2;
        if (query(1, m) == d)
            ans1 = m, h = m - 1;
        else
            l = m + 1;
    }

    int a[n];
    a[ans1 - 1] = n;

    /*int ans2 = -1;
    l = 1, h = ans1 - 1;
    while (l <= h) {
        int m = (l + h) / 2;
        if (query(m, ans1) == d)
            ans2 = m, l = m + 1;
        else
            h = m - 1;
    }
    a[ans2 - 1] = 1;*/

    bool check[n];
    fill(check, check + n, false);
    check[n - 1] = true;

    if (ans1 != n)
        a[ans1] = n - query(ans1, ans1 + 1), check[a[ans1] - 1] = true;
    a[ans1 - 2] = n - query(ans1 - 1, ans1);
    check[a[ans1 - 2] - 1] = true;

    for (int i = ans1 + 1; i < n; i++) {
        int d1 = query(i, i + 1);
        if (a[i - 1] + d1 >= n || check[a[i - 1] + d1 - 1]) {
            a[i] = a[i - 1] - d1, check[a[i] - 1] = true;
            continue;
        } else if (a[i - 1] - d1 <= 1 || check[a[i - 1] - d1 - 1]) {
            a[i] = a[i - 1] + d1, check[a[i] - 1] = true;
            continue;
        }
        int d2 = query(i - 1, i + 1);
        if (d2 == abs(a[i - 1] - a[i - 2])) {
            if (a[i - 1] > a[i - 2])
                a[i] = a[i - 1] - d1;
            else
                a[i] = a[i - 1] + d1;
        } else {
            int temp = a[i - 1] + d1;
            if (abs(temp - a[i - 2]) == d2)
                a[i] = temp;
            else
                a[i] = temp - 2 * a[i];
        }
        check[a[i] - 1] = true;
    }

    for (int i = ans1 - 3; i >= 0; i--) {
        int d1 = query(i + 1, i + 2);
        if (a[i + 1] + d1 >= n || check[a[i + 1] + d1 - 1]) {
            a[i] = a[i + 1] - d1, check[a[i] + 1] = true;
            continue;
        } else if (a[i + 1] - d1 < 1 || check[a[i + 1] - d1 - 1]) {
            a[i] = a[i + 1] + d1, check[a[i] - 1] = true;
            continue;
        }
        int d2 = query(i + 1, i + 3);
        if (d2 == abs(a[i + 1] - a[i + 2])) {
            if (a[i + 1] > a[i + 2])
                a[i] = a[i + 1] - d1;
            else
                a[i] = a[i + 1] + d1;
        } else {
            int temp = a[i + 1] + d1;
            if (abs(temp - a[i + 2]) == d2)
                a[i] = temp;
            else
                a[i] = temp - 2 * a[i];
        }
        check[a[i] - 1] = true;
    }

    for (int i = 1; i <= n; i++)
        answer(i, a[i - 1]);
  
  	return 0;
}

Compilation message

xylophone.cpp: In function 'int solve(int)':
xylophone.cpp:16:13: error: 'query' was not declared in this scope
     int d = query(1, n);
             ^~~~~
xylophone.cpp:100:9: error: 'answer' was not declared in this scope
         answer(i, a[i - 1]);
         ^~~~~~
xylophone.cpp:100:9: note: suggested alternative: 'ans1'
         answer(i, a[i - 1]);
         ^~~~~~
         ans1
xylophone.cpp:99:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = 1; i <= n; i++)
     ^~~
xylophone.cpp:102:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    return 0;
    ^~~~~~