답안 #39374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
39374 2018-01-13T08:32:21 Z aome Sailing Race (CEOI12_race) C++14
40 / 100
373 ms 5168 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5164 KB Output is correct
2 Runtime error 0 ms 5168 KB Execution killed because of forbidden syscall gettid (186)
3 Runtime error 0 ms 5168 KB Execution killed because of forbidden syscall gettid (186)
4 Runtime error 0 ms 5168 KB Execution killed because of forbidden syscall gettid (186)
5 Correct 0 ms 5164 KB Output is correct
6 Runtime error 0 ms 5168 KB Execution killed because of forbidden syscall gettid (186)
7 Correct 3 ms 5164 KB Output is correct
8 Runtime error 0 ms 5168 KB Execution killed because of forbidden syscall gettid (186)
9 Correct 6 ms 5164 KB Output is correct
10 Correct 16 ms 5164 KB Output is correct
11 Correct 9 ms 5164 KB Output is correct
12 Runtime error 0 ms 5168 KB Execution killed because of forbidden syscall gettid (186)
13 Runtime error 0 ms 5168 KB Execution killed because of forbidden syscall gettid (186)
14 Correct 226 ms 5164 KB Output is correct
15 Runtime error 0 ms 5168 KB Execution killed because of forbidden syscall gettid (186)
16 Runtime error 0 ms 5168 KB Execution killed because of forbidden syscall gettid (186)
17 Runtime error 0 ms 5168 KB Execution killed because of forbidden syscall gettid (186)
18 Correct 373 ms 5164 KB Output is correct
19 Runtime error 0 ms 5168 KB Execution killed because of forbidden syscall gettid (186)
20 Runtime error 0 ms 5168 KB Execution killed because of forbidden syscall gettid (186)