Submission #982574

# Submission time Handle Problem Language Result Execution time Memory
982574 2024-05-14T12:35:38 Z PanosPask Sailing Race (CEOI12_race) C++14
40 / 100
547 ms 4568 KB
#include <bits/stdc++.h>
#define pb push_back
#define MOD(var, M) (((var) >= (M)) ? ((var) - M) : (var))

using namespace std;

const int MAXN = 500;
const int INF = 1e9;

int N, K;
bool adj_list[MAXN][MAXN];

// dp[l][r][k]:  Maximum number of stages if enclosed by l, r
// and being in the stages such that l < s < r'
// Where r' = l > r ? r = r + N : r

// k == 0: Starting in l
// k == 1: Starting in r
int dp[MAXN][MAXN][2];

// Before the intersection with the first stage
// You can only choose one way to follow
// Either from l to r or from r to l
int bef[MAXN][MAXN][2];

// True if a stage can be organized from i to j
bool stage(int i, int j)
{
    return adj_list[i][j];
}

int main(void)
{
    scanf("%d %d", &N, &K);

    for (int i = 0; i < N; i++) {
        int v;
        scanf("%d", &v);

        while (v != 0) {
            v--;
            adj_list[i][v] = true;
            scanf("%d", &v);
        }
    }

    for (int len = 1; len <= N; len++) {
        for (int l = 0; l < N; l++) {
            int r_actual = l + len - 1;
            int r = MOD(r_actual, N);

            bef[l][r][0] = bef[l][r][1] = -INF;

            for (int i_actual = l + 1; i_actual < r_actual; i_actual++) {
                int i = MOD(i_actual, N);

                dp[l][r][0] = max(dp[l][r][0], dp[l][i][0]);
                dp[l][r][1] = max(dp[l][r][1], dp[i][r][1]);

                if (bef[l][i][0] != -INF && bef[i][r][0] != -INF) {
                    bef[l][r][0] = max(bef[l][r][0], bef[l][i][0] + bef[i][r][0]);
                }
                if (bef[l][i][1] != -INF && bef[i][r][1] != -INF) {
                    bef[l][r][1] = max(bef[l][r][1], bef[l][i][1] + bef[i][r][1]);
                }

                if (stage(l, i)) {
                    dp[l][r][0] = max(dp[l][r][0], 1 + dp[i][r][0]);
                }
                if (stage(r, i)) {
                    dp[l][r][1] = max(dp[l][r][1], 1 + dp[l][i][1]);
                }
            }

            if (stage(l, r)) {
                int res = 1 + dp[MOD(l + 1, N)][r][1];
                if (res >= dp[l][r][0]) {
                    // first[l][r][0] = true;
                    dp[l][r][0] = res;
                }

                bef[l][r][0] = max(bef[l][r][0], 1);
            }
            if (stage(r, l)) {
                int res = 1 + dp[l][MOD(r_actual - 1, N)][0];
                if (res >= dp[l][r][1]) {
                    // first[l][r][1] = true;
                    dp[l][r][1] = res;
                }

                bef[l][r][1] = max(bef[l][r][1], INF);
            }
        }
    }

    int ans = 0;
    int starting = 0;
    if (K == 0) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (dp[i][j][0] > ans) {
                    ans = dp[i][j][0];
                    starting = i;
                }
                if (dp[i][j][1] > ans) {
                    ans = dp[i][j][1];
                    starting = j;
                }
            }
        }

        printf("%d\n%d\n", ans, starting + 1);
        return 0;
    }


    return 0;
}

Compilation message

race.cpp: In function 'int main()':
race.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d %d", &N, &K);
      |     ~~~~~^~~~~~~~~~~~~~~~~
race.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%d", &v);
      |         ~~~~~^~~~~~~~~~
race.cpp:43:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |             scanf("%d", &v);
      |             ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 604 KB Unexpected end of file - int32 expected
3 Incorrect 1 ms 604 KB Unexpected end of file - int32 expected
4 Incorrect 1 ms 604 KB Unexpected end of file - int32 expected
5 Correct 3 ms 2652 KB Output is correct
6 Incorrect 3 ms 2652 KB Unexpected end of file - int32 expected
7 Correct 3 ms 2648 KB Output is correct
8 Incorrect 4 ms 2652 KB Unexpected end of file - int32 expected
9 Correct 6 ms 2796 KB Output is correct
10 Correct 5 ms 2648 KB Output is correct
11 Correct 8 ms 2652 KB Output is correct
12 Incorrect 41 ms 3164 KB Unexpected end of file - int32 expected
13 Incorrect 128 ms 3676 KB Unexpected end of file - int32 expected
14 Correct 286 ms 3932 KB Output is correct
15 Incorrect 509 ms 4444 KB Unexpected end of file - int32 expected
16 Incorrect 517 ms 4444 KB Unexpected end of file - int32 expected
17 Incorrect 535 ms 4444 KB Unexpected end of file - int32 expected
18 Correct 547 ms 4568 KB Output is correct
19 Incorrect 531 ms 4444 KB Unexpected end of file - int32 expected
20 Incorrect 546 ms 4440 KB Unexpected end of file - int32 expected