# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1091422 | kkkkkkkk | Sailing Race (CEOI12_race) | C++14 | 393 ms | 2652 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |