Submission #381178

# Submission time Handle Problem Language Result Execution time Memory
381178 2021-03-24T16:58:38 Z vishesh312 Xylophone (JOI18_xylophone) C++17
100 / 100
223 ms 98668 KB
#include "bits/stdc++.h"
#include "xylophone.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/

#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()

using ll = long long;
const int mod = 1e9+7;

void solve(int n) {
    vector<vector<int>> diff(n+1, vector<int>(n+1));
    for (int i = 1; i < n; ++i) {
        diff[i][i+1] = query(i, i+1);
    }
    for (int i = 1; i < n-1; ++i) {
        diff[i][i+2] = query(i, i+2);
    }
    vector<int> rel(n);
    rel[1] = diff[1][2];
    bool inc = true;
    for (int i = 2; i < n; ++i) {
        inc ^= (diff[i-1][i] + diff[i][i+1] != diff[i-1][i+1]);
        rel[i] = rel[i-1] + diff[i][i+1] * (inc?1:-1);
    }
    array<int, 2> mx = {0, 0}, mn = {0, 0};
    for (int i = 1; i < n; ++i) {
        if (rel[i] > mx[0]) {
            mx = {rel[i], i};
        }
        if (rel[i] < mn[0]) {
            mn = {rel[i], i};
        }
    }
    if (mn[1] < mx[1]) {
        for (int i = 0; i < n; ++i) {
            answer(i+1, rel[i] - mn[0] + 1);
        }
    } else {
        for (int i = 0; i < n; ++i) {
            answer(i+1, mx[0] - rel[i] + 1);
        }
    }
}
/*
signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int tc = 1;
    //cin >> tc;
    for (int i = 1; i <= tc; ++i) solve(i);
    return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 5 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 4 ms 364 KB Output is correct
10 Correct 5 ms 364 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 396 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 5 ms 364 KB Output is correct
15 Correct 4 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 5 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 4 ms 364 KB Output is correct
10 Correct 5 ms 364 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 396 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 5 ms 364 KB Output is correct
15 Correct 4 ms 364 KB Output is correct
16 Correct 6 ms 492 KB Output is correct
17 Correct 14 ms 1260 KB Output is correct
18 Correct 22 ms 3052 KB Output is correct
19 Correct 21 ms 4328 KB Output is correct
20 Correct 29 ms 4204 KB Output is correct
21 Correct 21 ms 4332 KB Output is correct
22 Correct 21 ms 4332 KB Output is correct
23 Correct 15 ms 4336 KB Output is correct
24 Correct 28 ms 4336 KB Output is correct
25 Correct 19 ms 4336 KB Output is correct
26 Correct 31 ms 4356 KB Output is correct
27 Correct 31 ms 4336 KB Output is correct
28 Correct 30 ms 4332 KB Output is correct
29 Correct 25 ms 4332 KB Output is correct
30 Correct 27 ms 4332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 5 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 4 ms 364 KB Output is correct
10 Correct 5 ms 364 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 396 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 5 ms 364 KB Output is correct
15 Correct 4 ms 364 KB Output is correct
16 Correct 6 ms 492 KB Output is correct
17 Correct 14 ms 1260 KB Output is correct
18 Correct 22 ms 3052 KB Output is correct
19 Correct 21 ms 4328 KB Output is correct
20 Correct 29 ms 4204 KB Output is correct
21 Correct 21 ms 4332 KB Output is correct
22 Correct 21 ms 4332 KB Output is correct
23 Correct 15 ms 4336 KB Output is correct
24 Correct 28 ms 4336 KB Output is correct
25 Correct 19 ms 4336 KB Output is correct
26 Correct 31 ms 4356 KB Output is correct
27 Correct 31 ms 4336 KB Output is correct
28 Correct 30 ms 4332 KB Output is correct
29 Correct 25 ms 4332 KB Output is correct
30 Correct 27 ms 4332 KB Output is correct
31 Correct 58 ms 18800 KB Output is correct
32 Correct 89 ms 37828 KB Output is correct
33 Correct 150 ms 74812 KB Output is correct
34 Correct 144 ms 98316 KB Output is correct
35 Correct 209 ms 98412 KB Output is correct
36 Correct 163 ms 98412 KB Output is correct
37 Correct 157 ms 98436 KB Output is correct
38 Correct 169 ms 98436 KB Output is correct
39 Correct 159 ms 98540 KB Output is correct
40 Correct 181 ms 98480 KB Output is correct
41 Correct 148 ms 98436 KB Output is correct
42 Correct 180 ms 98540 KB Output is correct
43 Correct 138 ms 98412 KB Output is correct
44 Correct 161 ms 98456 KB Output is correct
45 Correct 150 ms 98412 KB Output is correct
46 Correct 223 ms 98412 KB Output is correct
47 Correct 208 ms 98456 KB Output is correct
48 Correct 167 ms 98668 KB Output is correct
49 Correct 148 ms 98412 KB Output is correct
50 Correct 117 ms 98540 KB Output is correct
51 Correct 166 ms 98540 KB Output is correct
52 Correct 174 ms 98600 KB Output is correct
53 Correct 152 ms 98412 KB Output is correct
54 Correct 151 ms 98412 KB Output is correct
55 Correct 141 ms 98540 KB Output is correct
56 Correct 161 ms 98412 KB Output is correct
57 Correct 197 ms 98456 KB Output is correct
58 Correct 181 ms 98456 KB Output is correct
59 Correct 175 ms 98540 KB Output is correct
60 Correct 165 ms 98412 KB Output is correct