Submission #328780

#TimeUsernameProblemLanguageResultExecution timeMemory
328780thecodingwizardSailing Race (CEOI12_race)C++11
40 / 100
83 ms2540 KiB
#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 timeMemoryGrader output
Fetching results...