# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37221 | DoanPhuDuc | Sailing Race (CEOI12_race) | C++98 | 86 ms | 4192 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>
#define FOR(x, a, b) for (int x = a; x <= b; ++x)
#define FOD(x, a, b) for (int x = a; x >= b; --x)
#define REP(x, a, b) for (int x = a; x < b; ++x)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A, n) { cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl; }
#define PR0(A, n) { cout << #A << " = "; REP(_, 0, n) cout << A[_] << " "; cout << endl; }
#define BitCount(x) __builtin_popcount(x)
using namespace std;
typedef long long LL;
typedef pair <int, int> II;
const int N = 5e2 + 10;
int n, request;
int dp[N][N][2];
vector <int> adj[N];
int CCW(int i, int j, int k) {
if (i < j) {
return (j < k && k < n) || (k < i);
} else return (j < k && k < i);
}
int DP(int l, int r, int k) {
if (l == r) return dp[l][r][k] = 0;
int &ans = dp[l][r][k];
if (ans != -1) return ans;
ans = 0;
REP(i, 0, adj[r].size()) {
int v = adj[r][i];
if (CCW(l, r, v) == k) {
ans = max(ans, 1 + DP(l, v, k));
ans = max(ans, 1 + DP(r, v, k ^ 1));
}
}
return ans;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
scanf("%d%d", &n, &request);
assert(request == 0);
REP(u, 0, n) {
int v;
while (scanf("%d", &v) == 1) {
if (v == 0) break;
adj[u].push_back(v - 1);
}
}
memset(dp, -1, sizeof dp);
int ans = 0, num = -1;
REP(u, 0, n) {
REP(k, 0, adj[u].size()) {
int v = adj[u][k];
int can = DP(u, v, 0) + 1;
if (can > ans) {
ans = can;
num = u;
}
can = DP(u, v, 1) + 1;
if (can > ans) {
ans = can;
num = u;
}
}
}
printf("%d\n%d", ans, num + 1);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |