Submission #37222

#TimeUsernameProblemLanguageResultExecution timeMemory
37222DoanPhuDucSailing Race (CEOI12_race)C++98
40 / 100
99 ms4192 KiB
#include <bits/stdc++.h>

#define FOR(x, a, b) for (int x = a; x <= b; ++x)
#define FOD(x, a, b) for (int x = a; x >= b; --x)
#define REP(x, a, b) for (int x = a; x < b; ++x)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A, n) { cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl; }
#define PR0(A, n)  { cout << #A << " = "; REP(_, 0, n) cout << A[_] << " "; cout << endl; }
#define BitCount(x) __builtin_popcount(x)

using namespace std;

typedef long long LL;
typedef pair <int, int> II;

const int N = 5e2 + 10;

int n, request;
int dp[N][N][2];

vector <int> adj[N];

int CCW(int i, int j, int k) {
    if (i == k || j == k) return -1;
    if (i < j) {
        return (j < k && k < n) || (k < i);
    } else return (j < k && k < i);
}

int DP(int l, int r, int k) {
    if (l == r) return dp[l][r][k] = 0;
    int &ans = dp[l][r][k];
    if (ans != -1) return ans;
    ans = 0;
    REP(i, 0, adj[r].size()) {
        int v = adj[r][i];
        int d = CCW(l, r, v); if (d == -1) continue;
        if (d == k) {
            ans = max(ans, 1 + DP(l, v, k));
            ans = max(ans, 1 + DP(r, v, k ^ 1));
        }
    }
    return ans;
}

int main() {
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // LOCAL
    scanf("%d%d", &n, &request);
    assert(request == 0);
    REP(u, 0, n) {
        int v;
        while (scanf("%d", &v) == 1) {
            if (v == 0) break;
            adj[u].push_back(v - 1);
        }
    }
    memset(dp, -1, sizeof dp);
    int ans = 0, num = -1;
    REP(u, 0, n) {
        REP(k, 0, adj[u].size()) {
            int v = adj[u][k];
            int can = DP(u, v, 0) + 1;
            if (can > ans) {
                ans = can;
                num = u;
            }
                can = DP(u, v, 1) + 1;
            if (can > ans) {
                ans = can;
                num = u;
            }
        }
    }
    printf("%d\n%d", ans, num + 1);
    return 0;
}

Compilation message (stderr)

race.cpp: In function 'int DP(int, int, int)':
race.cpp:5:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(x, a, b) for (int x = a; x < b; ++x)
                                        ^
race.cpp:35:5: note: in expansion of macro 'REP'
     REP(i, 0, adj[r].size()) {
     ^
race.cpp: In function 'int main()':
race.cpp:5:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(x, a, b) for (int x = a; x < b; ++x)
                                        ^
race.cpp:63:9: note: in expansion of macro 'REP'
         REP(k, 0, adj[u].size()) {
         ^
race.cpp:51:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &request);
                                ^
#Verdict Execution timeMemoryGrader output
Fetching results...