답안 #261549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261549 2020-08-11T21:00:20 Z tincamatei Sailing Race (CEOI12_race) C++14
10 / 100
1061 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;
      
      do {
        k = (k + 1) % N;
        if(graph[i][k])
          asc[i][j] = 1 + std::max(asc[k][j], desc[k][(i + 1) % N]);
      } while(k != j);

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

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

  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);
       ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 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 768 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 Correct 12 ms 768 KB Output is correct
11 Incorrect 13 ms 768 KB Output isn't correct
12 Incorrect 66 ms 1280 KB Output isn't correct
13 Incorrect 186 ms 1664 KB Output isn't correct
14 Incorrect 418 ms 2168 KB Output isn't correct
15 Incorrect 934 ms 2668 KB Output isn't correct
16 Incorrect 975 ms 2808 KB Output isn't correct
17 Incorrect 912 ms 2680 KB Output isn't correct
18 Incorrect 770 ms 2680 KB Output isn't correct
19 Incorrect 1056 ms 2716 KB Output isn't correct
20 Incorrect 1061 ms 2688 KB Output isn't correct