Submission #894575

# Submission time Handle Problem Language Result Execution time Memory
894575 2023-12-28T13:04:07 Z lunaTu Xylophone (JOI18_xylophone) C++17
47 / 100
42 ms 504 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#include "xylophone.h"
typedef long long ll;
using namespace std;
 
 
void solve(int N) {
 
    vector<int> a(N + 1), u(2 * N + 1);
 
    int l = 1, r = N + 1;
    while (r - l > 1) {
        int m = (l + r) / 2;
 
        int get = 0;
        if (m < N) get = query(m, N);
 
        if (get != N - 1) r = m;
        else l = m;
    }
 
    answer(l, 1);
    a[l] = 1;
    u[1] = 1;
    if (l != N) {
        a[l + 1] = 1 + query(l, l + 1);
        answer(l + 1, a[l + 1]);
        u[a[l + 1]] = 1;
    }
 
    for (int i = l + 2; i <= N; i++) {
        int x = query(i - 2, i);
 
        int r = abs(a[i - 1] - a[i - 2]) - x;
 
        if (a[i - 1] < a[i - 2]) {
            if (r == 0) {
                int y = query(i - 1, i);
                a[i] = a[i - 1] + y;
            }
            else {
                if (u[a[i - 2] - x]) a[i] = a[i - 1] + x;
                else if (u[a[i - 1] + x]) a[i] = a[i - 2] - x;
                else {
                    int y = query(i - 1, i);
                    if (y == x) a[i] = a[i - 1] + x;
                    else a[i] = a[i - 2] - x;
                }
            }
        }
        else {
            if (r == 0) {
                int y = query(i - 1, i);
                a[i] = a[i - 1] - y;
            }
            else {
                if (u[a[i - 1] - x]) a[i] = a[i - 2] + x;
                else if (u[a[i - 2] + x]) a[i] = a[i - 1] - x;
                else {
                    int y = query(i - 1, i);
                    if (y == x) a[i] = a[i - 1] - x;
                    else a[i] = a[i - 2] + x;
                }
            }
        }
 
        answer(i, a[i]);
        u[a[i]] = 1;
    }
 
    if (l != 1) {
        a[l - 1] = 1 + query(l - 1, l);
        answer(l - 1, a[l - 1]);
		u[a[l - 1]] = 1;
    }
 
    for (int i = l - 2; i >= 1; i--) {
        int x = query(i, i + 2);
        int r = abs(a[i + 1] - a[i + 2]) - x;
 
        if (a[i + 1] < a[i + 2]) {
            if (r == 0) {
                int y = query(i, i + 1);
                a[i] = a[i + 1] + y;
            }
            else {
                if (u[a[i + 2] - x]) a[i] = a[i + 1] + x;
                else if (u[a[i + 1] + x]) a[i] = a[i + 2] - x;
                else {
                    int y = query(i, i + 1);
                    if (y == x) a[i] = a[i + 1] + x;
                    else a[i] = a[i + 2] - x;
                }
            }
        }
        else {
            if (r == 0) {
                int y = query(i, i + 1);
                a[i] = a[i + 1] - y;
            }
            else {
                if (u[a[i + 1] - x]) a[i] = a[i + 2] + x;
                else if (u[a[i + 2] + x]) a[i] = a[i + 1] - x;
                else {
                    int y = query(i, i + 1);
                    if (y == x) a[i] = a[i + 1] - x;
                    else a[i] = a[i + 2] + x;
                }
            }
        }
 
        answer(i, a[i]);
        u[a[i]] = 1;
    }
}
# 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 1 ms 356 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 340 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 1 ms 356 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 340 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 7 ms 344 KB Output is correct
20 Correct 9 ms 344 KB Output is correct
21 Correct 9 ms 344 KB Output is correct
22 Correct 9 ms 344 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 10 ms 344 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 10 ms 344 KB Output is correct
27 Correct 7 ms 344 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 10 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 1 ms 356 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 340 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 7 ms 344 KB Output is correct
20 Correct 9 ms 344 KB Output is correct
21 Correct 9 ms 344 KB Output is correct
22 Correct 9 ms 344 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 10 ms 344 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 10 ms 344 KB Output is correct
27 Correct 7 ms 344 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 10 ms 344 KB Output is correct
31 Correct 18 ms 504 KB Output is correct
32 Correct 22 ms 344 KB Output is correct
33 Correct 35 ms 344 KB Output is correct
34 Correct 36 ms 344 KB Output is correct
35 Correct 42 ms 344 KB Output is correct
36 Correct 28 ms 340 KB Output is correct
37 Incorrect 42 ms 344 KB Wrong Answer [2]
38 Halted 0 ms 0 KB -