Submission #931935

# Submission time Handle Problem Language Result Execution time Memory
931935 2024-02-22T15:34:31 Z a_l_i_r_e_z_a Xylophone (JOI18_xylophone) C++17
100 / 100
56 ms 1720 KB
// In the name of God
// Hope is last to die

#include <bits/stdc++.h>
#include "xylophone.h";
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
// #define int long long
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())

const int maxn = 10000 + 5;
const int inf = 1e9 + 7, mod = 1e9 + 7;
int n, a[maxn], b[maxn];
bool mark[maxn];

void solve(int N){
    n = N;
    for(int i = 1; i <= n - 1; i++) b[i] = query(i, i + 1);
    int l = 1, r = n + 1;
    while(r - l > 1){
        int mid = (l + r) / 2;
        if(query(1, mid) == n - 1) r = mid;
        else l = mid;
    }
    int psn = r;
    mark[n] = 1;
    mark[n - b[psn - 1]] = 1;
    a[psn] = n;
    a[psn - 1] = n - b[psn - 1];
    if(psn < n){
        a[psn + 1] = n - b[psn];
        mark[n - b[psn]] = 1;
    }
    for(int i = psn + 2; i <= n; i++){
        if(mark[a[i - 1] + b[i - 1]]){
            a[i] = a[i - 1] - b[i - 1];
            mark[a[i - 1] - b[i - 1]] = 1;
            continue;
        }
        else if(a[i - 1] - b[i - 1] >= 1 && mark[a[i - 1] - b[i - 1]]){
            a[i] = a[i - 1] + b[i - 1];
            mark[a[i - 1] + b[i - 1]] = 1;
            continue;
        }
        int x = query(i - 2, i);
        int mn = min(a[i - 2], a[i - 1]);
        int mx = a[i - 2] + a[i - 1] - mn;
        if(max(mx, a[i - 1] + b[i - 1]) - mn == x){
            a[i] = a[i - 1] + b[i - 1];
            mark[a[i - 1] + b[i - 1]] = 1;
        }
        else{
            a[i] = a[i - 1] - b[i - 1];
            mark[a[i - 1] - b[i - 1]] = 1;
        }
    }
    for(int i = psn - 2; i >= 1; i--){
        if(mark[a[i + 1] + b[i]]){
            a[i] = a[i + 1] - b[i];
            mark[a[i + 1] - b[i]] = 1;
            continue;
        }
        else if(a[i + 1] - b[i] >= 1 && mark[a[i + 1] - b[i]]){
            a[i] = a[i + 1] + b[i];
            mark[a[i + 1] + b[i]] = 1;
            continue;
        }
        int x = query(i, i + 2);
        int mn = min(a[i + 2], a[i + 1]);
        int mx = a[i + 2] + a[i + 1] - mn;
        if(max(mx, a[i + 1] + b[i]) - mn == x){
            a[i] = a[i + 1] + b[i];
            mark[a[i + 1] + b[i]] = 1;
        }
        else{
            a[i] = a[i + 1] - b[i];
            mark[a[i + 1] - b[i]] = 1;
        }
    }
    for(int i = 1; i <= n; i++) answer(i, a[i]);
}

// int32_t main()
// {
//     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//     return 0;
// }

Compilation message

xylophone.cpp:5:23: warning: extra tokens at end of #include directive
    5 | #include "xylophone.h";
      |                       ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 440 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 1 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 440 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 1 ms 440 KB Output is correct
16 Correct 3 ms 696 KB Output is correct
17 Correct 3 ms 692 KB Output is correct
18 Correct 6 ms 700 KB Output is correct
19 Correct 8 ms 948 KB Output is correct
20 Correct 7 ms 700 KB Output is correct
21 Correct 7 ms 696 KB Output is correct
22 Correct 8 ms 696 KB Output is correct
23 Correct 4 ms 692 KB Output is correct
24 Correct 8 ms 708 KB Output is correct
25 Correct 8 ms 704 KB Output is correct
26 Correct 8 ms 956 KB Output is correct
27 Correct 6 ms 696 KB Output is correct
28 Correct 8 ms 456 KB Output is correct
29 Correct 8 ms 952 KB Output is correct
30 Correct 7 ms 960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 440 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 1 ms 440 KB Output is correct
16 Correct 3 ms 696 KB Output is correct
17 Correct 3 ms 692 KB Output is correct
18 Correct 6 ms 700 KB Output is correct
19 Correct 8 ms 948 KB Output is correct
20 Correct 7 ms 700 KB Output is correct
21 Correct 7 ms 696 KB Output is correct
22 Correct 8 ms 696 KB Output is correct
23 Correct 4 ms 692 KB Output is correct
24 Correct 8 ms 708 KB Output is correct
25 Correct 8 ms 704 KB Output is correct
26 Correct 8 ms 956 KB Output is correct
27 Correct 6 ms 696 KB Output is correct
28 Correct 8 ms 456 KB Output is correct
29 Correct 8 ms 952 KB Output is correct
30 Correct 7 ms 960 KB Output is correct
31 Correct 15 ms 712 KB Output is correct
32 Correct 26 ms 688 KB Output is correct
33 Correct 36 ms 968 KB Output is correct
34 Correct 45 ms 696 KB Output is correct
35 Correct 45 ms 1196 KB Output is correct
36 Correct 19 ms 1212 KB Output is correct
37 Correct 56 ms 1208 KB Output is correct
38 Correct 33 ms 952 KB Output is correct
39 Correct 32 ms 696 KB Output is correct
40 Correct 45 ms 944 KB Output is correct
41 Correct 42 ms 1212 KB Output is correct
42 Correct 34 ms 448 KB Output is correct
43 Correct 46 ms 1228 KB Output is correct
44 Correct 44 ms 960 KB Output is correct
45 Correct 34 ms 1460 KB Output is correct
46 Correct 47 ms 1196 KB Output is correct
47 Correct 38 ms 1216 KB Output is correct
48 Correct 26 ms 1216 KB Output is correct
49 Correct 36 ms 1720 KB Output is correct
50 Correct 37 ms 704 KB Output is correct
51 Correct 42 ms 952 KB Output is correct
52 Correct 39 ms 1200 KB Output is correct
53 Correct 40 ms 1204 KB Output is correct
54 Correct 39 ms 964 KB Output is correct
55 Correct 45 ms 696 KB Output is correct
56 Correct 45 ms 1204 KB Output is correct
57 Correct 39 ms 952 KB Output is correct
58 Correct 39 ms 948 KB Output is correct
59 Correct 47 ms 1204 KB Output is correct
60 Correct 35 ms 1472 KB Output is correct