답안 #1091422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091422 2024-09-20T19:53:50 Z kkkkkkkk Sailing Race (CEOI12_race) C++14
40 / 100
393 ms 2652 KB
#include <bits/stdc++.h>

using namespace std;

int n, k, a;
bool sosed[505][505];
int dp[505][505][2];

int f(int poc, int kraj, int poz) {
    int nasoka=(poc==poz);
    if (dp[poc][kraj][nasoka]!=-1)
        return dp[poc][kraj][nasoka];
    int rez=0;
    for (int next=poc+1; next!=kraj; next++) {
        if (next>n) next=1;
        if (kraj==next) break;
        if (sosed[poz][next]) {
            rez=max(rez, 1+f(poc, next, next));
            rez=max(rez, 1+f(next, kraj, next));
        }
    }
    return dp[poc][kraj][nasoka]=rez;
}

int main()
{
    cin >> n >> k;
    for (int i=1;i<=n;i++) {
        while (cin >> a) {
            if (a==0) break;
            sosed[i][a]=1;
        }
    }
    memset(dp, -1, sizeof(dp));
    int rez=0, teme;
    for (int i=1;i<=n;i++) {
        if (f(i, i, i)>rez) {
            rez=f(i, i, i);
            teme=i;
        }
    }
    cout << rez << endl << teme;

    return 0;
}

Compilation message

race.cpp: In function 'int main()':
race.cpp:42:28: warning: 'teme' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |     cout << rez << endl << teme;
      |                            ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Incorrect 1 ms 2392 KB Output isn't correct
5 Correct 2 ms 2396 KB Output is correct
6 Incorrect 2 ms 2396 KB Output isn't correct
7 Correct 4 ms 2392 KB Output is correct
8 Incorrect 2 ms 2392 KB Output isn't correct
9 Correct 5 ms 2500 KB Output is correct
10 Correct 9 ms 2396 KB Output is correct
11 Correct 7 ms 2396 KB Output is correct
12 Incorrect 23 ms 2396 KB Output isn't correct
13 Incorrect 47 ms 2396 KB Output isn't correct
14 Correct 89 ms 2652 KB Output is correct
15 Incorrect 275 ms 2648 KB Output isn't correct
16 Incorrect 339 ms 2652 KB Output isn't correct
17 Incorrect 274 ms 2652 KB Output isn't correct
18 Correct 123 ms 2652 KB Output is correct
19 Incorrect 377 ms 2636 KB Output isn't correct
20 Incorrect 393 ms 2652 KB Output isn't correct