Submission #261543

# Submission time Handle Problem Language Result Execution time Memory
261543 2020-08-11T20:48:12 Z tincamatei Sailing Race (CEOI12_race) C++14
5 / 100
1002 ms 2808 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][(j - 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 9 ms 768 KB Output isn't correct
10 Incorrect 12 ms 768 KB Output isn't correct
11 Incorrect 12 ms 768 KB Output isn't correct
12 Incorrect 64 ms 1280 KB Output isn't correct
13 Incorrect 181 ms 1784 KB Output isn't correct
14 Incorrect 405 ms 2296 KB Output isn't correct
15 Incorrect 888 ms 2680 KB Output isn't correct
16 Incorrect 943 ms 2808 KB Output isn't correct
17 Incorrect 881 ms 2668 KB Output isn't correct
18 Incorrect 736 ms 2600 KB Output isn't correct
19 Incorrect 1002 ms 2808 KB Output isn't correct
20 Incorrect 999 ms 2732 KB Output isn't correct