# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
78641 | ekrem | Sailing Race (CEOI12_race) | C++98 | 516 ms | 2996 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = max(r, -inf);
}
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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |