Submission #1091422

#TimeUsernameProblemLanguageResultExecution timeMemory
1091422kkkkkkkkSailing Race (CEOI12_race)C++14
40 / 100
393 ms2652 KiB
#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 (stderr)

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;
      |                            ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...