Submission #260099

# Submission time Handle Problem Language Result Execution time Memory
260099 2020-08-09T09:57:44 Z MiricaMatei Sailing Race (CEOI12_race) C++14
40 / 100
537 ms 4856 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 505;

int n;
vector<int>G[MAXN];
int dp[MAXN][MAXN][3];
int mc[MAXN][MAXN];

int prv(int i) {
  i--;
  if (i == 0)
    i = n;
  return i;
}

int nxt(int i) {
  i++;
  if (i == n + 1)
    i = 1;
  return i;
}

int solve(int x, int y, int t) {
  if (dp[x][y][t] != -1)
    return dp[x][y][t];
  if (t == 0) {
    int mx = 0;
    for (int i = y; i != x; i = prv(i))
      if (mc[y][i])
        mx = max(mx, max(solve(x, i,  0), solve(y, i, 1)));
    dp[x][y][t] = 1 + mx;
  } else {
    int mx = 0;
    for (int i = y; i != x; i = nxt(i))
      if (mc[y][i])
        mx = max(mx, max(solve(y, i, 0), solve(x, i, 1)));
    dp[x][y][t] = 1 + mx;
  }
  return dp[x][y][t];
}

int main() {
  //freopen("date.in", "r", stdin);
  //freopen("date.out", "w", stdout);

  int k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    while (x != 0) {
      G[i].push_back(x);
      mc[i][x] = 1;
      scanf("%d", &x);
    }
    for (int j = 1; j <= n; ++j)
      dp[i][j][0] = dp[i][j][1] = -1;
  }

  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (mc[i][j]) {
        dp[i][j][0] = solve(i, j, 0);
        dp[i][j][1] = solve(i, j, 1);
      }

  int ans = 0, w = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      for (int t = 0; t <= 1; ++t)
        if (dp[i][j][t] > ans) {
          ans = dp[i][j][t];
          w = i;
        }

  printf("%d\n%d\n", ans, w);

  return 0;
}

Compilation message

race.cpp: In function 'int main()':
race.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &k);
   ~~~~~^~~~~~~~~~~~~~~~
race.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &x);
     ~~~~~^~~~~~~~~~
race.cpp:57:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &x);
       ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 512 KB Output isn't correct
3 Incorrect 1 ms 512 KB Output isn't correct
4 Incorrect 1 ms 640 KB Output isn't correct
5 Correct 2 ms 640 KB Output is correct
6 Incorrect 2 ms 672 KB Output isn't correct
7 Correct 1 ms 768 KB Output is correct
8 Incorrect 2 ms 896 KB Output isn't correct
9 Correct 6 ms 1024 KB Output is correct
10 Correct 8 ms 1152 KB Output is correct
11 Correct 8 ms 1152 KB Output is correct
12 Incorrect 31 ms 1920 KB Output isn't correct
13 Incorrect 66 ms 2816 KB Output isn't correct
14 Correct 144 ms 3704 KB Output is correct
15 Incorrect 375 ms 4480 KB Output isn't correct
16 Incorrect 475 ms 4728 KB Output isn't correct
17 Incorrect 379 ms 4480 KB Output isn't correct
18 Correct 199 ms 4472 KB Output is correct
19 Incorrect 537 ms 4736 KB Output isn't correct
20 Incorrect 519 ms 4856 KB Output isn't correct