Submission #1091721

# Submission time Handle Problem Language Result Execution time Memory
1091721 2024-09-21T23:28:08 Z raphaelp Xylophone (JOI18_xylophone) C++17
100 / 100
43 ms 608 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
/*vector<int> Tab;
int query(int a, int b)
{
    a--, b--;
    int minn = Tab.size(), maxx = 0;
    for (int i = a; i <= b; i++)
    {
        minn = min(minn, Tab[i]);
        maxx = max(maxx, Tab[i]);
    }
    return maxx - minn;
}
void answer(int i, int val) { cout << val << ' '; }*/
void solve(int N)
{
    int L = 0, R = N;
    while (L != R)
    {
        int m = (L + R) / 2;
        int temp = query(m + 1, N);
        if (temp == N - 1)
            L = m + 1;
        else
            R = m;
    }
    int ref = L - 1;
    vector<int> ans(N, -1), occ(N);
    occ[0] = 1;
    ans[ref] = 0;
    for (int i = ref + 1; i < N; i++)
    {
        int temp = query(i, i + 1);
        if (ans[i - 1] + temp >= N || occ[ans[i - 1] + temp])
            ans[i] = ans[i - 1] - temp;
        else if (ans[i - 1] - temp < 0 || occ[ans[i - 1] - temp])
            ans[i] = ans[i - 1] + temp;
        else
        {
            int temp2 = query(i - 1, i + 1);
            if (temp2 == ans[i - 1] - ans[i - 2] + temp || ans[i - 2] - ans[i - 1] == temp2 || (temp == temp2 && ans[i - 2] > ans[i - 1]))
                ans[i] = ans[i - 1] + temp;
            else
                ans[i] = ans[i - 1] - temp;
        }
        occ[ans[i]] = 1;
    }
    for (int i = ref - 1; i >= 0; i--)
    {
        int temp = query(i + 1, i + 2);
        if (ans[i + 1] + temp >= N || occ[ans[i + 1] + temp])
            ans[i] = ans[i + 1] - temp;
        else if (ans[i + 1] - temp < 0 || occ[ans[i + 1] - temp])
            ans[i] = ans[i + 1] + temp;
        else
        {
            int temp2 = query(i + 1, i + 3);
            if (temp2 == ans[i + 1] - ans[i + 2] + temp || ans[i + 2] - ans[i + 1] == temp2 || (temp == temp2 && ans[i + 2] > ans[i + 1]))
                ans[i] = ans[i + 1] + temp;
            else
                ans[i] = ans[i + 1] - temp;
        }
        occ[ans[i]] = 1;
    }
    for (int i = 0; i < N; i++)
        answer(i + 1, ans[i] + 1);
}
/*int main()
{
    int N;
    cin >> N;
    Tab.assign(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> Tab[i];
    }
    solve(N);
}*/
# 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 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# 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 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 5 ms 344 KB Output is correct
19 Correct 6 ms 436 KB Output is correct
20 Correct 9 ms 448 KB Output is correct
21 Correct 9 ms 444 KB Output is correct
22 Correct 7 ms 600 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 6 ms 448 KB Output is correct
25 Correct 5 ms 344 KB Output is correct
26 Correct 6 ms 608 KB Output is correct
27 Correct 9 ms 440 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 4 ms 344 KB Output is correct
30 Correct 6 ms 344 KB Output is correct
# 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 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 5 ms 344 KB Output is correct
19 Correct 6 ms 436 KB Output is correct
20 Correct 9 ms 448 KB Output is correct
21 Correct 9 ms 444 KB Output is correct
22 Correct 7 ms 600 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 6 ms 448 KB Output is correct
25 Correct 5 ms 344 KB Output is correct
26 Correct 6 ms 608 KB Output is correct
27 Correct 9 ms 440 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 4 ms 344 KB Output is correct
30 Correct 6 ms 344 KB Output is correct
31 Correct 13 ms 592 KB Output is correct
32 Correct 22 ms 452 KB Output is correct
33 Correct 25 ms 344 KB Output is correct
34 Correct 39 ms 468 KB Output is correct
35 Correct 27 ms 464 KB Output is correct
36 Correct 28 ms 452 KB Output is correct
37 Correct 22 ms 468 KB Output is correct
38 Correct 16 ms 344 KB Output is correct
39 Correct 30 ms 592 KB Output is correct
40 Correct 41 ms 456 KB Output is correct
41 Correct 30 ms 452 KB Output is correct
42 Correct 27 ms 464 KB Output is correct
43 Correct 27 ms 452 KB Output is correct
44 Correct 22 ms 472 KB Output is correct
45 Correct 31 ms 344 KB Output is correct
46 Correct 31 ms 452 KB Output is correct
47 Correct 32 ms 448 KB Output is correct
48 Correct 32 ms 592 KB Output is correct
49 Correct 30 ms 344 KB Output is correct
50 Correct 40 ms 448 KB Output is correct
51 Correct 29 ms 456 KB Output is correct
52 Correct 30 ms 448 KB Output is correct
53 Correct 40 ms 344 KB Output is correct
54 Correct 20 ms 464 KB Output is correct
55 Correct 31 ms 452 KB Output is correct
56 Correct 28 ms 344 KB Output is correct
57 Correct 26 ms 464 KB Output is correct
58 Correct 36 ms 448 KB Output is correct
59 Correct 43 ms 452 KB Output is correct
60 Correct 31 ms 448 KB Output is correct