#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define inf 1000000007
#define N 505
using namespace std;
int n, d, x, dp[N][N], h[N][N];
vector < int > g[N];
pair < int , int > ans;
int f(int bas, int son){
int &r = dp[bas][son];
if(r != -1)
return r;
r = -inf;
if(bas == son)
return r = 0;
if(h[bas][son])
r = 1;
if(bas < son)
for(int i = bas + 1; i < son; i++)
r = max(r, f(bas, i) + f(i, son));
else
for(int i = son + 1; i < bas; i++)
r = max(r, f(bas, i) + f(i, son));
return r;
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
memset(dp, -1, sizeof dp);
scanf("%d %d",&n ,&d);
for(int i = 1; i <= n; i++){
while(1){
scanf("%d",&x);
if(!x)
break;
g[i].pb(x);
h[i][x] = 1;
}
}
for(int i = 1; i <= n; i++)
for(int j = 0; j < g[i].size(); j++){
for(int k = 1; k <= n; k++)
if(k != i)
ans = max(ans, mp(f(g[i][j], k) + 1, i) );
// printf("dp[%d][%d] = %d\n", g[i][j], k, f(g[i][j], k));}
}
printf("%d\n%d\n", ans.st, ans.nd);
return 0;
}
Compilation message
race.cpp: In function 'int main()':
race.cpp:49:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < g[i].size(); j++){
~~^~~~~~~~~~~~~
race.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n ,&d);
~~~~~^~~~~~~~~~~~~~~~
race.cpp:41:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&x);
~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1272 KB |
Output is correct |
2 |
Incorrect |
3 ms |
1532 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
1548 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
1548 KB |
Output isn't correct |
5 |
Incorrect |
4 ms |
1548 KB |
Output isn't correct |
6 |
Incorrect |
4 ms |
1768 KB |
Output isn't correct |
7 |
Incorrect |
5 ms |
1768 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
1768 KB |
Output isn't correct |
9 |
Incorrect |
6 ms |
1768 KB |
Output isn't correct |
10 |
Incorrect |
15 ms |
1884 KB |
Output isn't correct |
11 |
Incorrect |
7 ms |
1884 KB |
Output isn't correct |
12 |
Incorrect |
25 ms |
2012 KB |
Output isn't correct |
13 |
Incorrect |
62 ms |
2256 KB |
Output isn't correct |
14 |
Incorrect |
127 ms |
2396 KB |
Output isn't correct |
15 |
Incorrect |
304 ms |
2652 KB |
Output isn't correct |
16 |
Incorrect |
328 ms |
2908 KB |
Output isn't correct |
17 |
Incorrect |
287 ms |
2908 KB |
Output isn't correct |
18 |
Incorrect |
235 ms |
2908 KB |
Output isn't correct |
19 |
Incorrect |
350 ms |
2920 KB |
Output isn't correct |
20 |
Incorrect |
337 ms |
2920 KB |
Output isn't correct |