Submission #261545

# Submission time Handle Problem Language Result Execution time Memory
261545 2020-08-11T20:51:39 Z tincamatei Sailing Race (CEOI12_race) C++14
5 / 100
1016 ms 2680 KB
#include <bits/stdc++.h>

const int MAX_N = 500;

bool graph[MAX_N][MAX_N];
int asc[MAX_N][MAX_N], desc[MAX_N][MAX_N];

int main() {
  int N, K;

  scanf("%d%d", &N, &K);

  for(int i = 0; i < N; ++i) {
    int t;
    scanf("%d", &t);
    while(t != 0) {
      graph[i][t - 1] = true;
      scanf("%d", &t);
    }
  }

  for(int len = 2; len <= N; ++len) {
    for(int i = 0; i < N; ++i) {
      int j = (i + len - 1) % N, k = i;

      while(k != j) {
        if(graph[i][k])
          asc[i][j] = 1 + std::max(asc[k][j], desc[k][(i + 1) % N]);
        k = (k + 1) % N;
      }

      j = (i + N - len + 1) % N;
      k = i;

      while(k != j) {
        if(graph[i][k])
          desc[i][j] = 1 + std::max(desc[k][j], asc[k][(i - 1 + N) % N]);
        k = (k + N - 1) % N;
      }
    }
  }

  int best_len = 0, start_path = 0;

  for(int i = 0; i < N; ++i) {
    int ii = ((i + N - 1) % N);

    if(asc[i][ii] > best_len) {
      best_len = asc[i][ii];
      start_path = i;
    }

    ii = (i + 1) % N;
    if(desc[i][ii] > best_len) {
      best_len = desc[i][ii];
      start_path = i;
    }
  }

  printf("%d\n%d", best_len, start_path + 1);

  return 0;
}

Compilation message

race.cpp: In function 'int main()':
race.cpp:11: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:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &t);
     ~~~~~^~~~~~~~~~
race.cpp:18:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &t);
       ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Incorrect 1 ms 512 KB Output isn't correct
5 Incorrect 2 ms 512 KB Output isn't correct
6 Incorrect 3 ms 640 KB Output isn't correct
7 Incorrect 5 ms 640 KB Output isn't correct
8 Incorrect 5 ms 640 KB Output isn't correct
9 Incorrect 8 ms 768 KB Output isn't correct
10 Incorrect 13 ms 768 KB Output isn't correct
11 Incorrect 12 ms 768 KB Output isn't correct
12 Incorrect 66 ms 1152 KB Output isn't correct
13 Incorrect 181 ms 1664 KB Output isn't correct
14 Incorrect 406 ms 2048 KB Output isn't correct
15 Incorrect 891 ms 2680 KB Output isn't correct
16 Incorrect 938 ms 2560 KB Output isn't correct
17 Incorrect 876 ms 2680 KB Output isn't correct
18 Incorrect 736 ms 2680 KB Output isn't correct
19 Incorrect 1016 ms 2560 KB Output isn't correct
20 Incorrect 997 ms 2680 KB Output isn't correct