답안 #143355

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
143355 2019-08-13T18:38:44 Z popovicirobert Sailing Race (CEOI12_race) C++14
10 / 100
189 ms 2680 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long



/*const int MOD = ;

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1) ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}

inline int inv(int x) {
    return lgput(x, MOD - 2);
}*/

/*int fact[], invfact[];

inline void prec(int n) {
    fact[0] = 1;
    for(int i = 1; i <= n; i++) {
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    }
    invfact[n] = lgput(fact[n], MOD - 2);
    for(int i = n - 1; i >= 0; i--) {
        invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
    }
}

inline int comb(int n, int k) {
    if(n < k) return 0;
    return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}*/

using namespace std;

const int INF = 1e9;
const int MAXN = 500;

bool edge[MAXN][MAXN];

int dp[MAXN][MAXN][2];
int best[MAXN];

int main() {
#if 0
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int i, j, n, k;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> k;
    for(i = 0; i < n; i++) {
        int x;
        cin >> x;
        while(x != 0) {
            x--;
            edge[i][x] = 1;
            cin >> x;
        }
    }

    auto get = [&](int x) {
        return (x >= n ? x - n : x);
    };
    auto prv = [&](int x) {
        return (x == 0 ? n - 1 : x - 1);
    };
    auto nxt = [&](int x) {
        return (x == n - 1 ? 0 : x + 1);
    };

    for(int len = 2; len < n; len++) {
        for(i = 0; i + len < n; i++) {
            j = get(i + len);
            for(int k = nxt(i); k != j; k = nxt(k)) {
                int cur = 1 + max(dp[i][k][1], dp[k][j][0]);
                if(edge[i][k]) dp[i][j][0] = max(dp[i][j][0], cur);
                if(edge[j][k]) dp[i][j][1] = max(dp[i][j][1], cur);
                cur = 1 + max(dp[j][k][1], dp[k][i][0]);
                if(edge[j][k]) dp[j][i][0] = max(dp[j][i][0], cur);
                if(edge[i][k]) dp[j][i][1] = max(dp[j][i][1], cur);
            }
        }
    }

    auto combine = [&](pair <int, int> &ans, pair <int, int> cur) {
        if(ans.first < cur.first) {
            swap(ans, cur);
        }
    };

    pair <int, int> ans = {0, 0};
    for(i = 0; i < n; i++) {
        for(j = 0; j < n; j++) {
            if(edge[i][j]) {
                combine(ans, {max(dp[j][i][0], dp[i][j][1]) + 1, i});
            }
        }
    }
    if(k == 0) {
        cout << ans.first << "\n" << ans.second + 1;
        return 0;
    }




    return 0;
}

Compilation message

race.cpp: In function 'int main()':
race.cpp:94:10: warning: variable 'prv' set but not used [-Wunused-but-set-variable]
     auto prv = [&](int x) {
          ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
3 Incorrect 2 ms 504 KB Unexpected end of file - int32 expected
4 Incorrect 2 ms 504 KB Unexpected end of file - int32 expected
5 Incorrect 3 ms 632 KB Output isn't correct
6 Incorrect 3 ms 632 KB Unexpected end of file - int32 expected
7 Incorrect 3 ms 632 KB Output isn't correct
8 Incorrect 3 ms 760 KB Unexpected end of file - int32 expected
9 Incorrect 4 ms 760 KB Output isn't correct
10 Correct 4 ms 760 KB Output is correct
11 Incorrect 5 ms 732 KB Output isn't correct
12 Incorrect 14 ms 1144 KB Unexpected end of file - int32 expected
13 Incorrect 34 ms 1656 KB Unexpected end of file - int32 expected
14 Incorrect 73 ms 2184 KB Output isn't correct
15 Incorrect 158 ms 2552 KB Unexpected end of file - int32 expected
16 Incorrect 171 ms 2552 KB Unexpected end of file - int32 expected
17 Incorrect 159 ms 2460 KB Unexpected end of file - int32 expected
18 Incorrect 135 ms 2680 KB Output isn't correct
19 Incorrect 189 ms 2552 KB Unexpected end of file - int32 expected
20 Incorrect 185 ms 2552 KB Unexpected end of file - int32 expected