Submission #846087

# Submission time Handle Problem Language Result Execution time Memory
846087 2023-09-07T09:38:13 Z LucaIlie Xylophone (JOI18_xylophone) C++17
47 / 100
58 ms 97212 KB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 5000;
int v[MAX_N + 1], ans[MAX_N + 1][MAX_N + 1];

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;
    }

    int p1 = l;
    for ( int l = 1; l <= n; l++ ) {
        for ( int r = l; r <= n; r++ )
            ans[l][r] = -1;
    }
    for ( int i = 1; i <= n - 1; i++ )
        ans[i][i + 1] = query( i, i + 1 );
    for ( int i = 1; i <= n - 2; i++ )
        ans[i][i + 2] = query( i, i + 2 );

    v[p1] = 1;
    v[p1 + 1] = 1 + ans[p1][p1 + 1];
    if ( p1 > 1 )
        v[p1 - 1] = 1 + ans[p1 - 1][p1];

    for ( int i = p1 + 2; i <= n; i++ ) {
        if ( v[i - 2] < v[i - 1] ) {
            if ( ans[i - 2][i] == ans[i - 2][i - 1] )
                v[i] = v[i - 1] - ans[i - 1][i];
            else if ( ans[i - 2][i] == ans[i - 1][i] )
                v[i] = v[i - 1] - ans[i - 1][i];
            else
                v[i] = v[i - 1] + ans[i - 1][i];
        } else {
            if ( ans[i - 2][i] == ans[i - 2][i - 1] )
                v[i] = v[i - 1] + ans[i - 1][i];
            else if ( ans[i - 2][i] == ans[i - 1][i] )
                v[i] = v[i - 1] + ans[i - 1][i];
            else
                v[i] = v[i - 1] - ans[i - 1][i];
        }
    }

    for ( int i = p1 - 2; i >= 1; i-- ) {
        if ( v[i + 2] < v[i + 1] ) {
            if ( ans[i][i + 2] == ans[i + 1][i + 2] )
                v[i] = v[i + 1] - ans[i][i + 1];
            else if ( ans[i][i + 2] == ans[i][i + 1] )
                v[i] = v[i + 1] - ans[i][i + 1];
            else
                v[i] = v[i + 1] + ans[i][i + 1];
        } else {
            if ( ans[i][i + 2] == ans[i + 1][i + 2] )
                v[i] = v[i + 1] + ans[i][i + 1];
            else if ( ans[i][i + 2] == ans[i][i + 1] )
                v[i] = v[i + 1] + ans[i][i + 1];
            else
                v[i] = v[i + 1] - ans[i][i + 1];
        }
    }

    for ( int i = 1; i <= n; i++ )
        answer( i, v[i] );
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 452 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 2492 KB Output is correct
4 Correct 1 ms 2492 KB Output is correct
5 Correct 1 ms 2492 KB Output is correct
6 Correct 1 ms 2748 KB Output is correct
7 Correct 1 ms 2748 KB Output is correct
8 Correct 1 ms 2740 KB Output is correct
9 Correct 2 ms 2748 KB Output is correct
10 Correct 1 ms 2492 KB Output is correct
11 Correct 1 ms 2744 KB Output is correct
12 Correct 1 ms 2492 KB Output is correct
13 Correct 1 ms 2744 KB Output is correct
14 Correct 1 ms 2492 KB Output is correct
15 Correct 1 ms 2736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 452 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 2492 KB Output is correct
4 Correct 1 ms 2492 KB Output is correct
5 Correct 1 ms 2492 KB Output is correct
6 Correct 1 ms 2748 KB Output is correct
7 Correct 1 ms 2748 KB Output is correct
8 Correct 1 ms 2740 KB Output is correct
9 Correct 2 ms 2748 KB Output is correct
10 Correct 1 ms 2492 KB Output is correct
11 Correct 1 ms 2744 KB Output is correct
12 Correct 1 ms 2492 KB Output is correct
13 Correct 1 ms 2744 KB Output is correct
14 Correct 1 ms 2492 KB Output is correct
15 Correct 1 ms 2736 KB Output is correct
16 Correct 2 ms 6744 KB Output is correct
17 Correct 5 ms 10944 KB Output is correct
18 Correct 9 ms 17080 KB Output is correct
19 Correct 9 ms 21176 KB Output is correct
20 Correct 10 ms 21180 KB Output is correct
21 Correct 11 ms 21180 KB Output is correct
22 Correct 10 ms 21180 KB Output is correct
23 Correct 11 ms 21184 KB Output is correct
24 Correct 12 ms 21012 KB Output is correct
25 Correct 10 ms 21180 KB Output is correct
26 Correct 9 ms 21180 KB Output is correct
27 Correct 11 ms 21176 KB Output is correct
28 Correct 13 ms 21028 KB Output is correct
29 Correct 14 ms 21368 KB Output is correct
30 Correct 12 ms 21024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 452 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 2492 KB Output is correct
4 Correct 1 ms 2492 KB Output is correct
5 Correct 1 ms 2492 KB Output is correct
6 Correct 1 ms 2748 KB Output is correct
7 Correct 1 ms 2748 KB Output is correct
8 Correct 1 ms 2740 KB Output is correct
9 Correct 2 ms 2748 KB Output is correct
10 Correct 1 ms 2492 KB Output is correct
11 Correct 1 ms 2744 KB Output is correct
12 Correct 1 ms 2492 KB Output is correct
13 Correct 1 ms 2744 KB Output is correct
14 Correct 1 ms 2492 KB Output is correct
15 Correct 1 ms 2736 KB Output is correct
16 Correct 2 ms 6744 KB Output is correct
17 Correct 5 ms 10944 KB Output is correct
18 Correct 9 ms 17080 KB Output is correct
19 Correct 9 ms 21176 KB Output is correct
20 Correct 10 ms 21180 KB Output is correct
21 Correct 11 ms 21180 KB Output is correct
22 Correct 10 ms 21180 KB Output is correct
23 Correct 11 ms 21184 KB Output is correct
24 Correct 12 ms 21012 KB Output is correct
25 Correct 10 ms 21180 KB Output is correct
26 Correct 9 ms 21180 KB Output is correct
27 Correct 11 ms 21176 KB Output is correct
28 Correct 13 ms 21028 KB Output is correct
29 Correct 14 ms 21368 KB Output is correct
30 Correct 12 ms 21024 KB Output is correct
31 Correct 28 ms 43628 KB Output is correct
32 Correct 27 ms 62128 KB Output is correct
33 Correct 58 ms 86764 KB Output is correct
34 Incorrect 51 ms 97212 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -