Submission #860874

# Submission time Handle Problem Language Result Execution time Memory
860874 2023-10-14T16:48:14 Z vjudge1 Xylophone (JOI18_xylophone) C++
47 / 100
67 ms 98364 KB
#include "xylophone.h"
using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define rall(A) A.rbegin(), A.rend()

using ll = long long;
using ld = long double;

const int N = 5005;
const int M = 405;
const int SQRT = 500;
const int LOG = 20;
const int INF = 1e9;
const int MOD = 1e9+7;
const ld EPS = 1e-9;
const int BASE = 9973;

int memo[N + 1][N + 1];
 
int ask(int l, int r) {
    if (memo[l][r] == -1)
        memo[l][r] = query(l, r);
    return memo[l][r];
}
 
void solve(int n) {
    int l = 1, r = n;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (query(mid, n) == n - 1)l = mid;
        else r = mid;
    }
 
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=n;j++){
            memo[i][j] = -1;
        }
    }

    int A[n+1];

    A[l] = 1;
    A[l + 1] = 1 + ask(l, l + 1);
    if (l > 1) A[l - 1] = 1 + ask(l - 1, l);
 
    for (int i = l + 2;i<=n;i++) {
        int x = ask(i - 1, i);
        if (A[i - 1] - x < 1) {
            A[i] = A[i - 1] + x;
            continue;
        }
        if (A[i - 1] + x > n) {
            A[i] = A[i - 1] - x;
            continue;
        }
 
        if (A[i - 2] < A[i - 1]) {
            if (ask(i - 2, i) == ask(i - 2, i - 1))A[i] = A[i - 1] - ask(i - 1, i);
            else if (ask(i - 2, i) == ask(i - 1, i))A[i] = A[i - 1] - ask(i - 1, i);
            else A[i] = A[i - 1] + ask(i - 1, i);
        } else {
            if (ask(i - 2, i) == ask(i - 2, i - 1))A[i] = A[i - 1] + ask(i - 1, i);
            else if (ask(i - 2, i) == ask(i - 1, i))A[i] = A[i - 1] + ask(i - 1, i);
            else A[i] = A[i - 1] - ask(i - 1, i);
        }
    }
 
    for (int i = l - 2;i>=1;i--) {
        int x = ask(i, i + 1);
        if (A[i + 1] - x < 1) {
            A[i] = A[i + 1] + x;
            continue;
        }
        if (A[i + 1] + x > n) {
            A[i] = A[i + 1] - x;
            continue;
        }
 
        if (A[i + 2] < A[i + 1]) {
            if (ask(i, i + 2) == ask(i + 1, i + 2))A[i] = A[i + 1] - ask(i, i + 1);
            else if (ask(i, i + 2) == ask(i, i + 1))A[i] = A[i + 1] - ask(i, i + 1);
            else A[i] = A[i + 1] + ask(i, i + 1);
        } else {
            if (ask(i, i + 2) == ask(i + 1, i + 2))A[i] = A[i + 1] + ask(i, i + 1);
            else if (ask(i, i + 2) == ask(i, i + 1))A[i] = A[i + 1] + ask(i, i + 1);
            else A[i] = A[i + 1] - ask(i, i + 1);
        }
    }
 
    for (int i = 1;i<=n;i++)answer(i, A[i]);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 432 KB Output is correct
4 Correct 1 ms 2732 KB Output is correct
5 Correct 1 ms 2732 KB Output is correct
6 Correct 1 ms 2732 KB Output is correct
7 Correct 1 ms 2736 KB Output is correct
8 Correct 1 ms 2736 KB Output is correct
9 Correct 1 ms 2740 KB Output is correct
10 Correct 1 ms 2736 KB Output is correct
11 Correct 1 ms 2728 KB Output is correct
12 Correct 1 ms 2736 KB Output is correct
13 Correct 1 ms 2744 KB Output is correct
14 Correct 1 ms 2736 KB Output is correct
15 Correct 1 ms 2736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 432 KB Output is correct
4 Correct 1 ms 2732 KB Output is correct
5 Correct 1 ms 2732 KB Output is correct
6 Correct 1 ms 2732 KB Output is correct
7 Correct 1 ms 2736 KB Output is correct
8 Correct 1 ms 2736 KB Output is correct
9 Correct 1 ms 2740 KB Output is correct
10 Correct 1 ms 2736 KB Output is correct
11 Correct 1 ms 2728 KB Output is correct
12 Correct 1 ms 2736 KB Output is correct
13 Correct 1 ms 2744 KB Output is correct
14 Correct 1 ms 2736 KB Output is correct
15 Correct 1 ms 2736 KB Output is correct
16 Correct 2 ms 4784 KB Output is correct
17 Correct 4 ms 11208 KB Output is correct
18 Correct 8 ms 17072 KB Output is correct
19 Correct 9 ms 19344 KB Output is correct
20 Correct 16 ms 19120 KB Output is correct
21 Correct 7 ms 19376 KB Output is correct
22 Correct 8 ms 19364 KB Output is correct
23 Correct 10 ms 19364 KB Output is correct
24 Correct 7 ms 19112 KB Output is correct
25 Correct 7 ms 19376 KB Output is correct
26 Correct 10 ms 19364 KB Output is correct
27 Correct 9 ms 19376 KB Output is correct
28 Correct 8 ms 19380 KB Output is correct
29 Correct 12 ms 19368 KB Output is correct
30 Correct 10 ms 19356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 432 KB Output is correct
4 Correct 1 ms 2732 KB Output is correct
5 Correct 1 ms 2732 KB Output is correct
6 Correct 1 ms 2732 KB Output is correct
7 Correct 1 ms 2736 KB Output is correct
8 Correct 1 ms 2736 KB Output is correct
9 Correct 1 ms 2740 KB Output is correct
10 Correct 1 ms 2736 KB Output is correct
11 Correct 1 ms 2728 KB Output is correct
12 Correct 1 ms 2736 KB Output is correct
13 Correct 1 ms 2744 KB Output is correct
14 Correct 1 ms 2736 KB Output is correct
15 Correct 1 ms 2736 KB Output is correct
16 Correct 2 ms 4784 KB Output is correct
17 Correct 4 ms 11208 KB Output is correct
18 Correct 8 ms 17072 KB Output is correct
19 Correct 9 ms 19344 KB Output is correct
20 Correct 16 ms 19120 KB Output is correct
21 Correct 7 ms 19376 KB Output is correct
22 Correct 8 ms 19364 KB Output is correct
23 Correct 10 ms 19364 KB Output is correct
24 Correct 7 ms 19112 KB Output is correct
25 Correct 7 ms 19376 KB Output is correct
26 Correct 10 ms 19364 KB Output is correct
27 Correct 9 ms 19376 KB Output is correct
28 Correct 8 ms 19380 KB Output is correct
29 Correct 12 ms 19368 KB Output is correct
30 Correct 10 ms 19356 KB Output is correct
31 Correct 18 ms 44464 KB Output is correct
32 Correct 29 ms 61092 KB Output is correct
33 Correct 38 ms 87732 KB Output is correct
34 Correct 47 ms 98228 KB Output is correct
35 Correct 42 ms 98364 KB Output is correct
36 Incorrect 67 ms 98220 KB Wrong Answer [2]
37 Halted 0 ms 0 KB -