Submission #918535

# Submission time Handle Problem Language Result Execution time Memory
918535 2024-01-30T06:11:41 Z viwlesxq Xylophone (JOI18_xylophone) C++17
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>
using namespace std;
#include "xylophone.h"

void solve(int n) {
    vector<int> a(n);
    int min = 0, max = n - 1;
    for (int i = 1; i < n; ++i) {
        if (query(i + 1, n) != n - 1) break;
        min = i;
    }
    for (int i = n - 2; i >= 0; --i) {
        if (query(1, i + 1) != n - 1) break;
        max = i;
    }
    a[min] = 1, a[max] = n;
    int last = min, sum = 0;
    bool increasing = true;
    for (int i = min - 1; i >= 0; --i) {
        int diff = query(i + 1, last + 1), add = query(i + 1, i + 2);
        if (sum + add != diff) {
            last = i + 1;
            diff = add, sum = 0;
            increasing ^= true;
        }
        a[i] = a[last] + (increasing ? diff : -diff);
        sum += diff;
    }
    last = min, sum = 0;
    increasing = true;
    for (int i = min + 1; i < max; ++i) {
        int diff = query(last + 1, i + 1), add = query(i, i + 1);
        if (sum + add != diff) {
            last = i - 1;
            diff = add, sum = 0;
            increasing ^= true;
        }
        a[i] = a[last] + (increasing ? diff : -diff);
        sum += diff;
    }
    last = max, sum = 0;
    increasing = false;
    for (int i = max + 1; i < n; ++i) {
        int diff = query(last + 1, i + 1), add = query(i, i + 1);
        if (sum + add != diff) {
            last = i - 1;
            diff = add, sum = 0;
            increasing ^= true;
        }
        a[i] = a[last] + (increasing ? diff : -diff);
        sum += diff;
    }
    for (int i = 0; i < n; ++i) {
        //cout << a[i] << ' ';
        answer(i + 1, 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 1 ms 344 KB Wrong Answer [7]
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 1 ms 344 KB Wrong Answer [7]
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 1 ms 344 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -