# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
64522 | dfistric | Sailing Race (CEOI12_race) | C++14 | 1912 ms | 8128 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(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
const int MAXN = 510;
vector <int> ve[MAXN];
int num_ways[MAXN][MAXN][2];
int max_ways[MAXN][MAXN][2];
int dp[MAXN][MAXN][2];
bool inside(int x, int y, int z, int t) {
if (t == 0) swap(x, y);
if (x < y) {
return ((z > x) && (z < y));
}
return ((z > x) || (z < y));
}
int rek(int x, int y, int t) {
int& out = num_ways[x][y][t];
if (out != -1) return out;
out = 0;
for (int z : ve[y]) {
if (inside(x, y, z, t)) {
out = max(out, 1 + max(rek(y, z, 1 - t), rek(x, z, t)));
}
}
return out;
}
int dfs(int x, int y, int t) {
int& out = dp[x][y][t];
if (out != -1) return out;
out = 0;
for (int z : ve[y]) {
if (inside(x, y, z, t) || z == y) {
out = max(out, 1 + dfs(z, y, t));
}
}
return out;
}
int main() {
ios_base::sync_with_stdio(false);
memset(num_ways, -1, sizeof num_ways);
memset(dp, -1, sizeof dp);
int n, k;
cin >> n >> k;
REP(i, n) {
int x;
cin >> x;
while (x) {
ve[i].push_back(x - 1);
cin >> x;
}
}
int out = 0, st = 0;
REP(i, n) {
for (int j : ve[i]) {
int tr = 1 + max(rek(i, j, 1), rek(i, j, 0));
if (tr > out) {
out = tr;
st = i + 1;
}
}
}
if (!k) {
cout << out << "\n" << st << "\n";
return 0;
}
REP(a, n) {
REP(b, n) {
if (a == b) continue;
int c = a + 1;
while (c != b) {
max_ways[a][b][0] = max(max_ways[a][b][0], rek(b, c, 0));
max_ways[a][b][1] = max(max_ways[a][b][1], rek(a, c, 1));
c = (c + 1) % n;
}
}
}
REP(i, n) dp[i][i][0] = dp[i][i][1] = 0;
REP(a, n) {
for (int b : ve[a]) {
REP(c, n) {
if (c == b || c == a) continue;
int tr = 0;
}
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |