Submission #819567

# Submission time Handle Problem Language Result Execution time Memory
819567 2023-08-10T11:49:54 Z RecursiveCo Xylophone (JOI18_xylophone) C++14
100 / 100
63 ms 428 KB
// CF template, version 3.0

#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;

#define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0)
#define getTest int t; cin >> t
#define eachTest for (int _var=0;_var<t;_var++)
#define get(name) int (name); cin >> (name)
#define out(o) cout << (o)
#define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
#define sortl(name) sort((name).begin(), (name).end())
#define rev(name) reverse((name).begin(), (name).end())
#define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
#define decision(b) if (b){out("YES");}else{out("NO");}

// #define int long long int

void solve(int n) {
    int l = 1;
    int r = n;
    while (r - l >= 1) {
        int middle = (l + r) / 2;
        int range = query(1, middle + 1);
        if (range == n - 1) r = middle;
        else l = middle + 1;
    }
    vector<int> ans(n);
    vector<bool> used(n + 1, false);
    ans[l] = n;
    used[n] = true;
    for (int i = l - 1; i >= 0; i--) {
        int range = query(i + 1, i + 2);
        int prev = ans[i + 1];
        if (prev + range > n || used[prev + range]) {
            ans[i] = prev - range;
        } else if (1 > prev - range || used[prev - range]) {
            ans[i] = prev + range;
        } else {
            int larger = query(i + 1, i + 3);
            int beforeprev = ans[i + 2];
            if (larger == abs(prev - beforeprev)) {
                if (prev < beforeprev) {
                    ans[i] = prev + range;
                } else {
                    ans[i] = prev - range;
                }
            } else if (prev + range - min(prev, beforeprev) == larger) {
                ans[i] = prev + range;
            } else {
                ans[i] = prev - range;
            }
        }
        used[ans[i]] = true;
    }
    for (int i = l + 1; i < n; i++) {
        if (i == n - 1) {
            forto(n, j) {
                if (!used[j + 1]) {
                    ans[i] = j + 1;
                    break;
                }
            }
            break;
        }
        int range = query(i, i + 1);
        int prev = ans[i - 1];
        if (prev + range > n || used[prev + range]) {
            ans[i] = prev - range;
        } else if (1 > prev - range || used[prev - range]) {
            ans[i] = prev + range;
        } else {
            int larger = query(i - 1, i + 1);
            int beforeprev = ans[i - 2];
            if (larger == abs(prev - beforeprev)) {
                if (prev < beforeprev) {
                    ans[i] = prev + range;
                } else {
                    ans[i] = prev - range;
                }
            } else if (prev + range - min(prev, beforeprev) == larger) {
                ans[i] = prev + range;
            } else {
                ans[i] = prev - range;
            }
        }
        used[ans[i]] = true;
    }
    forto(n, i) {
        answer(i + 1, ans[i]);
    }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:16:35: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
xylophone.cpp:60:13: note: in expansion of macro 'forto'
   60 |             forto(n, j) {
      |             ^~~~~
xylophone.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
xylophone.cpp:91:5: note: in expansion of macro 'forto'
   91 |     forto(n, i) {
      |     ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 3 ms 296 KB Output is correct
18 Correct 7 ms 336 KB Output is correct
19 Correct 8 ms 228 KB Output is correct
20 Correct 11 ms 304 KB Output is correct
21 Correct 10 ms 208 KB Output is correct
22 Correct 8 ms 300 KB Output is correct
23 Correct 6 ms 304 KB Output is correct
24 Correct 7 ms 308 KB Output is correct
25 Correct 7 ms 308 KB Output is correct
26 Correct 12 ms 208 KB Output is correct
27 Correct 8 ms 304 KB Output is correct
28 Correct 8 ms 296 KB Output is correct
29 Correct 12 ms 336 KB Output is correct
30 Correct 5 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 3 ms 296 KB Output is correct
18 Correct 7 ms 336 KB Output is correct
19 Correct 8 ms 228 KB Output is correct
20 Correct 11 ms 304 KB Output is correct
21 Correct 10 ms 208 KB Output is correct
22 Correct 8 ms 300 KB Output is correct
23 Correct 6 ms 304 KB Output is correct
24 Correct 7 ms 308 KB Output is correct
25 Correct 7 ms 308 KB Output is correct
26 Correct 12 ms 208 KB Output is correct
27 Correct 8 ms 304 KB Output is correct
28 Correct 8 ms 296 KB Output is correct
29 Correct 12 ms 336 KB Output is correct
30 Correct 5 ms 292 KB Output is correct
31 Correct 21 ms 300 KB Output is correct
32 Correct 25 ms 296 KB Output is correct
33 Correct 46 ms 292 KB Output is correct
34 Correct 42 ms 296 KB Output is correct
35 Correct 51 ms 304 KB Output is correct
36 Correct 39 ms 312 KB Output is correct
37 Correct 26 ms 208 KB Output is correct
38 Correct 42 ms 300 KB Output is correct
39 Correct 42 ms 300 KB Output is correct
40 Correct 36 ms 300 KB Output is correct
41 Correct 32 ms 428 KB Output is correct
42 Correct 41 ms 312 KB Output is correct
43 Correct 51 ms 296 KB Output is correct
44 Correct 34 ms 328 KB Output is correct
45 Correct 49 ms 300 KB Output is correct
46 Correct 58 ms 296 KB Output is correct
47 Correct 38 ms 320 KB Output is correct
48 Correct 45 ms 208 KB Output is correct
49 Correct 48 ms 304 KB Output is correct
50 Correct 45 ms 316 KB Output is correct
51 Correct 63 ms 300 KB Output is correct
52 Correct 48 ms 316 KB Output is correct
53 Correct 39 ms 312 KB Output is correct
54 Correct 49 ms 300 KB Output is correct
55 Correct 21 ms 312 KB Output is correct
56 Correct 55 ms 316 KB Output is correct
57 Correct 53 ms 296 KB Output is correct
58 Correct 47 ms 304 KB Output is correct
59 Correct 58 ms 300 KB Output is correct
60 Correct 42 ms 304 KB Output is correct