# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
261555 | tincamatei | Sailing Race (CEOI12_race) | C++14 | 1074 ms | 2680 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>
const int MAX_N = 500;
bool graph[MAX_N][MAX_N];
int asc[MAX_N][MAX_N], desc[MAX_N][MAX_N];
int main() {
int N, K;
scanf("%d%d", &N, &K);
for(int i = 0; i < N; ++i) {
int t;
scanf("%d", &t);
while(t != 0) {
graph[i][t - 1] = true;
scanf("%d", &t);
}
}
for(int len = 2; len <= N; ++len) {
for(int i = 0; i < N; ++i) {
int j = (i + len - 1) % N, k = i;
do {
k = (k + 1) % N;
if(graph[i][k])
asc[i][j] = std::max(asc[i][j], 1 + std::max(asc[k][j], desc[k][(i + 1) % N]));
} while(k != j);
j = (i + N - len + 1) % N;
k = i;
do {
k = (k + N - 1) % N;
if(graph[i][k])
desc[i][j] = std::max(desc[i][j], 1 + std::max(desc[k][j], asc[k][(i - 1 + N) % N]));
} while(k != j);
}
}
int best_len = 0, start_path = 0;
for(int i = 0; i < N; ++i) {
int ii = ((i + N - 1) % N);
if(asc[i][ii] > best_len) {
best_len = asc[i][ii];
start_path = i;
}
ii = (i + 1) % N;
if(desc[i][ii] > best_len) {
best_len = desc[i][ii];
start_path = i;
}
}
printf("%d\n%d", best_len, start_path + 1);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |