Submission #338424

# Submission time Handle Problem Language Result Execution time Memory
338424 2020-12-23T05:54:03 Z KoD Xylophone (JOI18_xylophone) C++17
100 / 100
157 ms 98540 KB
#include <bits/stdc++.h>

template <class T>
using Vec = std::vector<T>;

#ifdef __APPLE__ 
int query(int, int);
void answer(int, int);
#else 
#include "xylophone.h"
#endif

void solve(int N) {
    Vec<Vec<int>> memo(N, Vec<int>(N, -1));
    const auto ask = [&](int s, int t) {
        if (memo[s][t] != -1) {
            return memo[s][t];
        }
        return memo[s][t] = query(s + 1, t + 1);
    };
    const auto fill = [&](Vec<int> &vec) {
        for (int i = 2; i < N; ++i) {
            const auto a = ask(i - 2, i - 1);
            const auto b = ask(i - 1, i);
            const auto c = ask(i - 2, i);
            if (vec[i - 2] < vec[i - 1]) {
                if (a + b == c) {
                    vec[i] = vec[i - 1] + b;
                }
                else {
                    vec[i] = vec[i - 1] - b;
                }
            }
            else {
                if (a + b == c) {
                    vec[i] = vec[i - 1] - b;
                }
                else {
                    vec[i] = vec[i - 1] + b;
                }
            }
        }
        const auto min = std::min_element(vec.begin(), vec.end());
        const auto max = std::max_element(vec.begin(), vec.end());
        const auto val = *min;
        for (auto &x: vec) {
            x -= val;
            x += 1;
        }
        return max - min > 0;
    };
    Vec<int> A(N);
    A[1] = ask(0, 1);
    if (fill(A)) {
        for (int i = 0; i < N; ++i) {
            answer(i + 1, A[i]);
        }
        return;
    }
    Vec<int> B(N);
    B[1] = -ask(0, 1);
    fill(B);
    for (int i = 0; i < N; ++i) {
        answer(i + 1, B[i]);
    }
}

#ifdef __APPLE__
int Size, QueryCount;
Vec<int> Array, Answer;
Vec<Vec<int>> Query;

int query(int s, int t) {
    QueryCount += 1;
    return Query[s - 1][t - 1];
}

void answer(int i, int a) {
    Answer[i - 1] = a;
}

int main() {
    std::cin >> Size;
    Array.resize(Size);
    Answer.resize(Size);
    Query.resize(Size);
    for (auto &x: Array) {
        std::cin >> x;
    }
    for (int i = 0; i < Size; ++i) {
        Query[i].resize(Size);
        int max = 0, min = Size + 1;
        for (int j = i; j < Size; ++j) {
            max = std::max(max, Array[j]);
            min = std::min(min, Array[j]);
            Query[i][j] = max - min;
        }
    }
    solve(Size);
    std::cout << "Number of queries: " << (double) QueryCount / (double) Size << "N\n";
    std::cout << (Array == Answer ? "Correct" : "Wrong") << '\n';
    for (auto x: Answer) {
        std::cout << x << ' ';
    }
    std::cout << '\n';
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 3 ms 492 KB Output is correct
17 Correct 10 ms 1260 KB Output is correct
18 Correct 10 ms 3048 KB Output is correct
19 Correct 13 ms 4308 KB Output is correct
20 Correct 21 ms 4352 KB Output is correct
21 Correct 17 ms 4332 KB Output is correct
22 Correct 21 ms 4204 KB Output is correct
23 Correct 19 ms 4332 KB Output is correct
24 Correct 25 ms 4352 KB Output is correct
25 Correct 17 ms 4332 KB Output is correct
26 Correct 16 ms 4332 KB Output is correct
27 Correct 25 ms 4224 KB Output is correct
28 Correct 17 ms 4332 KB Output is correct
29 Correct 13 ms 4332 KB Output is correct
30 Correct 17 ms 4332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 3 ms 492 KB Output is correct
17 Correct 10 ms 1260 KB Output is correct
18 Correct 10 ms 3048 KB Output is correct
19 Correct 13 ms 4308 KB Output is correct
20 Correct 21 ms 4352 KB Output is correct
21 Correct 17 ms 4332 KB Output is correct
22 Correct 21 ms 4204 KB Output is correct
23 Correct 19 ms 4332 KB Output is correct
24 Correct 25 ms 4352 KB Output is correct
25 Correct 17 ms 4332 KB Output is correct
26 Correct 16 ms 4332 KB Output is correct
27 Correct 25 ms 4224 KB Output is correct
28 Correct 17 ms 4332 KB Output is correct
29 Correct 13 ms 4332 KB Output is correct
30 Correct 17 ms 4332 KB Output is correct
31 Correct 52 ms 18796 KB Output is correct
32 Correct 77 ms 37868 KB Output is correct
33 Correct 83 ms 74728 KB Output is correct
34 Correct 144 ms 98412 KB Output is correct
35 Correct 134 ms 98412 KB Output is correct
36 Correct 129 ms 98540 KB Output is correct
37 Correct 137 ms 98540 KB Output is correct
38 Correct 129 ms 98412 KB Output is correct
39 Correct 112 ms 98420 KB Output is correct
40 Correct 136 ms 98540 KB Output is correct
41 Correct 157 ms 98412 KB Output is correct
42 Correct 145 ms 98412 KB Output is correct
43 Correct 148 ms 98412 KB Output is correct
44 Correct 145 ms 98412 KB Output is correct
45 Correct 135 ms 98540 KB Output is correct
46 Correct 143 ms 98412 KB Output is correct
47 Correct 152 ms 98540 KB Output is correct
48 Correct 139 ms 98540 KB Output is correct
49 Correct 131 ms 98412 KB Output is correct
50 Correct 141 ms 98540 KB Output is correct
51 Correct 150 ms 98540 KB Output is correct
52 Correct 127 ms 98540 KB Output is correct
53 Correct 129 ms 98540 KB Output is correct
54 Correct 149 ms 98412 KB Output is correct
55 Correct 126 ms 98412 KB Output is correct
56 Correct 139 ms 98412 KB Output is correct
57 Correct 146 ms 98412 KB Output is correct
58 Correct 143 ms 98508 KB Output is correct
59 Correct 139 ms 98412 KB Output is correct
60 Correct 123 ms 98540 KB Output is correct