# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
328780 | thecodingwizard | Sailing Race (CEOI12_race) | C++11 | 83 ms | 2540 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;
using ll = long long;
#define ii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define inf 1000000010
#define maxn 500
int n, k;
vector<int> adj[maxn];
int memo[maxn][maxn][2];
int dp(int x, int y, bool onY) {
if (memo[x][y][onY] != -1) return memo[x][y][onY];
int best = 1;
for (int i : adj[onY ? y : x]) {
if (x < y) {
if (x < i && i < y) {
best = max(best, 1 + max(dp(x, i, 1), dp(i, y, 0)));
}
} else {
if (i > x || i < y) {
best = max(best, 1 + max(dp(x, i, 1), dp(i, y, 0)));
}
}
}
return memo[x][y][onY] = best;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k; assert(!k);
F0R(i, n) {
int x;
while (cin >> x && x != 0) {
--x;
adj[i].pb(x);
}
}
int best = -1, bestIdx = -1;
F0R(i, n) F0R(j, n) F0R(k, 2) memo[i][j][k] = -1;
F0R(i, n) {
for (int j : adj[i]) {
int val = max(dp(i, j, 1), dp(j, i, 0));
if (best < val) {
best = val;
bestIdx = i;
}
}
}
cout << best << endl;
cout << bestIdx+1 << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |