답안 #490150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
490150 2021-11-26T01:11:55 Z sberens Sailing Race (CEOI12_race) C++17
40 / 100
891 ms 14580 KB
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename K> using hset = gp_hash_table<K, null_type>;
template <typename K, typename V> using hmap = gp_hash_table<K, V>;


using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define smax(x, y) (x = max(x, y))
#define smin(x, y) (x = min(x, y))

using ll = long long;
using ld = long double;

template <typename T>
using vv = vector<vector<T>>;

using vi = vector<int>;
using ii = array<int, 2>;
using vii = vector<ii>;
using vvi = vv<int>;

using vll = vector<ll>;
using l2 = array<ll, 2>;
using vl2 = vector<l2>;
using vvll = vv<ll>;

template <typename T>
using minq = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxq = priority_queue<T>;

const ll M = 1000000007;

int n, k;

bool in_bounds(int l, int r, int j) {
    if (l <= r) {
        return l <= j && j <= r;
    } else {
        return j <= r || l <= j;
    }
}

struct modint {
    static ll M;
    static ll _reduce(ll n) {
        static ll b = -1ull/M;
        ll r = n-(ll)(__uint128_t(b)*n>>64)*M; return r >= M ? r-M : r;
    }

    static ll _pow(ll n, ll k) {
        ll r = 1;
        for (; k > 0; k >>= 1, n = _reduce(n*n))
            if (k&1) r = _reduce(r*n);
        return r;
    }

    ll v; modint(ll n = 0) : v(_reduce(n)) { v += (M&(0-(v<0))); }

    friend string to_string(const modint n) { return to_string(n.v); }
    friend istream& operator>>(istream& i, modint& n) { return i >> n.v; }
    friend ostream& operator<<(ostream& o, const modint n) { return o << n.v; }
    template<typename T> explicit operator T() { return T(v); }

    friend bool operator==(const modint n, const modint m) { return n.v == m.v; }
    friend bool operator!=(const modint n, const modint m) { return n.v != m.v; }
    friend bool operator<(const modint n, const modint m) { return n.v < m.v; }
    friend bool operator<=(const modint n, const modint m) { return n.v <= m.v; }
    friend bool operator>(const modint n, const modint m) { return n.v > m.v; }
    friend bool operator>=(const modint n, const modint m) { return n.v >= m.v; }

    modint& operator+=(const modint n) { v += n.v; v -= (M&(0-(v>=M))); return *this; }
    modint& operator-=(const modint n) { v -= n.v; v += (M&(0-(v<0))); return *this; }
    modint& operator*=(const modint n) { v = _reduce(v*n.v); return *this; }
    modint& operator/=(const modint n) { v = _reduce(v*_pow(n.v, M-2)); return *this; }
    friend modint operator+(const modint n, const modint m) { return modint(n) += m; }
    friend modint operator-(const modint n, const modint m) { return modint(n) -= m; }
    friend modint operator*(const modint n, const modint m) { return modint(n) *= m; }
    friend modint operator/(const modint n, const modint m) { return modint(n) /= m; }
    modint& operator++() { return *this += 1; }
    modint& operator--() { return *this -= 1; }
    modint operator++(int) { modint t = *this; return *this += 1, t; }
    modint operator--(int) { modint t = *this; return *this -= 1, t; }
    modint operator+() { return *this; }
    modint operator-() { return modint(0) -= *this; }

    // O(logk) modular exponentiation
    modint pow(const ll k) const {
        return k < 0 ? _pow(v, M-1-(-k%(M-1))) : _pow(v, k);
    }
    modint inv() const { return _pow(v, M-2); }
};

ll modint::M = 0;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    modint::M = n;
    vvi g(n);
    for (int i = 0; i < n; ++i) {
        while (true) {
            int x;
            cin >> x;
            if (x == 0) break;
            g[i].pb(x - 1);
        }
    }
    vv<vi> dp(n, vvi(n, vi(2)));
    for (int len = 1; len < n; ++len) {
        for (int l = 0; l < n; ++l) {
            int r = modint(l + len - 1).v;
            for (int i : g[l])
                if (in_bounds(l, r, i))
                    smax(dp[l][r][0], max(dp[modint(l + 1).v][i][1], dp[i][r][0]) + 1);
            for (int i : g[r])
                if (in_bounds(l, r, i))
                    smax(dp[l][r][1], max(dp[l][i][1], dp[i][modint(r - 1).v][0]) + 1);

        }
    }
    ii res{0, 0};
    for (int i = 0; i < n; ++i) {
        int l = i, r = modint(i - 1).v;
        for (int j : g[i]) {
            if (k) {

            } else {
                ii cand{max(dp[modint(l  +1).v][j][1], dp[j][r][0]) + 1, i};
                smax(res, cand);
            }
        }
    }
    cout << res[0] << '\n' << res[1] + 1 << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Incorrect 1 ms 316 KB Output isn't correct
5 Correct 1 ms 464 KB Output is correct
6 Incorrect 1 ms 464 KB Output isn't correct
7 Correct 3 ms 592 KB Output is correct
8 Incorrect 2 ms 576 KB Output isn't correct
9 Correct 7 ms 720 KB Output is correct
10 Correct 11 ms 848 KB Output is correct
11 Correct 9 ms 916 KB Output is correct
12 Incorrect 26 ms 2584 KB Output isn't correct
13 Incorrect 66 ms 5328 KB Output isn't correct
14 Correct 127 ms 9204 KB Output is correct
15 Incorrect 702 ms 14308 KB Output isn't correct
16 Incorrect 781 ms 14432 KB Output isn't correct
17 Incorrect 678 ms 14308 KB Output isn't correct
18 Correct 229 ms 14160 KB Output is correct
19 Incorrect 891 ms 14580 KB Output isn't correct
20 Incorrect 890 ms 14484 KB Output isn't correct