Submission #7901084


Source Code Expand

// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const ll mod = 1e9 + 7;

ll dp[302][302][302];

int main() {
    ll N, M;
    cin >> N >> M;
    dp[0][0][N - 1] = 1;

    for(ll day = 0; day < M; day++) for(ll road = 0; road <= min<ll>(day, N - 1); road++) {
        ll rest = N - road;
        for(ll iso = max<ll>(0, N - (day + 1)); iso < N && 0 <= rest - iso; iso++) {
            ll scc_size = rest - iso;
            DEBUG(make_tuple(day, road, iso));
        
            // go to isolatoin
            if(0 < iso) (dp[day + 1][road + 1][iso - 1] += iso * dp[day][road][iso] % mod) %= mod;
            
            // loop
            (dp[day + 1][road][iso] += road * dp[day][road][iso] % mod) %= mod;

            // return scc
            (dp[day + 1][0][iso] += scc_size * dp[day][road][iso] % mod) %= mod;
        }
    }

    cout << dp[M][0][0] << endl;
    return 0;
}

Submission Info

Submission Time
Task F - Road of the King
User kcvlex
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 2572 Byte
Status AC
Exec Time 90 ms
Memory 213248 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 3
AC × 16
Set Name Test Cases
sample sample-01.txt, sample-02.txt, sample-03.txt
all sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01-01.txt AC 1 ms 256 KB
01-02.txt AC 1 ms 256 KB
01-03.txt AC 42 ms 213248 KB
01-04.txt AC 1 ms 256 KB
01-05.txt AC 43 ms 213248 KB
01-06.txt AC 53 ms 213248 KB
01-07.txt AC 89 ms 213248 KB
01-08.txt AC 90 ms 213248 KB
01-09.txt AC 90 ms 213248 KB
01-10.txt AC 90 ms 213248 KB
sample-01.txt AC 2 ms 2304 KB
sample-02.txt AC 66 ms 213248 KB
sample-03.txt AC 28 ms 106752 KB