# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39374 | aome | Sailing Race (CEOI12_race) | C++14 | 373 ms | 5168 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;
const int N = 505;
int n, subtask;
int res, start;
int a[N][N];
int f[2][N][N];
int nxt(int i) { return i == (n - 1) ? 0 : (i + 1); }
int prv(int i) { return i == 0 ? (n - 1) : (i - 1); }
int calF(int t, int l, int r) {
int &F = f[t][l][r];
if (F != -1) return F;
F = 0;
if (t == 0) {
for (int i = l; i != r; i = nxt(i)) {
if (!a[l][i]) continue;
F = max(F, max(calF(1, l, i), calF(0, i, r)) + 1);
}
if (res < F) res = F, start = l;
}
else {
for (int i = nxt(l); i != r; i = nxt(i)) {
if (!a[r][i]) continue;
F = max(F, max(calF(0, i, r), calF(1, l, i)) + 1);
}
if (res < F) res = F, start = r;
}
return F;
}
int main() {
// subtask 0
ios::sync_with_stdio(false);
cin >> n >> subtask;
assert(subtask == 0);
for (int i = 0; i < n; ++i) {
int x;
while (cin >> x && x) a[i][x - 1] = 1;
}
memset(f, -1, sizeof f);
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
calF(i, j, k);
}
}
}
cout << res << ' ' << start + 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |