Submission #894544

# Submission time Handle Problem Language Result Execution time Memory
894544 2023-12-28T12:06:39 Z lunaTu Xylophone (JOI18_xylophone) C++17
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#include "xylophone.h"
typedef long long ll;
using namespace std;

void solve(int N) {

    vector<int> a(N + 1);

    int l = 1, r = N + 1;
    while (r - l > 1) {
        int m = (l + r) / 2;

        int get = 0;
        if (m < N) get = query(m, N);

        if (get != N - 1) r = m;
        else l = m;
    }

    answer(l, 1);
    a[l] = 1;
    if (l != N) {
        a[l + 1] = 1 + query(l, l + 1);
        answer(l + 1, a[l + 1]);
    }

    for (int i = l + 2; i <= N; i++) {
        int x = query(i - 2, i);
        if (x == abs(a[i - 1] - a[i - 2])) {
            int y = query(i - 1, i);
            if (a[i - 1] < a[i - 2]) a[i] = a[i - 1] + y;
            else a[i] = a[i - 1] - y;
        }
        else if (a[i - 1] < a[i - 2]) a[i] = a[i - 1] + x;
        else a[i] = a[i - 2] + x;

        answer(i, a[i]);
    }

    if (l != 1) {
        a[l - 1] = 1 + query(l - 1, l);
        answer(l - 1, a[l - 1]);
    }

    for (int i = l - 2; i >= 1; i--) {
        int x = query(i, i + 2);
        if (x == abs(a[i + 1] - a[i + 2])) {
            int y = query(i, i + 1);
            if (a[i + 1] < a[i + 2]) a[i] = a[i + 1] + y;
            else a[i] = a[i + 1] - y;
        }
        else if (a[i + 1] < a[i + 2]) a[i] = a[i + 1] + x;
        else a[i] = a[i + 2] + x;

        answer(i, a[i]);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -