Submission #994276


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

const ll mod = 1e9+7;
ll add(ll a, ll b) { return (a + b) % mod; }
ll mul(ll a, ll b) { return a * b % mod; }
ll fact(ll n) {
    ll res = 1;
    FOR(i, 1, n+1) {
        res = mul(res, i);
    }
    return res;
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, m; cin >> n >> m;
    if (m < n) {
        cout << 0 << endl;
        return 0;
    }
    vector< vector< vector<ll> > > dp(2, vector<vector<ll>>(n, vector<ll>(n, 0)));
    dp[0][0][0] = 1;
    REP(i, m) REP(j, n) REP(k, n) {
        if (dp[i&1][j][k] == 0) continue;
        // キーアイテム(k以下)挿入
        dp[i+1&1][j][j] = add(dp[i+1&1][j][j], mul(dp[i&1][j][k], k+1));
        // 新しいもの(j+1)を挿入
        if (j+1 < n) {
            dp[i+1&1][j+1][k] = add(dp[i+1&1][j+1][k], dp[i&1][j][k]);
        }
        // それ以外(k+1以上j以下)挿入
        dp[i+1&1][j][k] = add(dp[i+1&1][j][k], mul(dp[i&1][j][k], j-k));
    }
    // cout << dp[m][n-1] << endl;
    ll ans = mul(dp[m&1][n-1][n-1], fact(n-1));
    cout << ans << endl;
}

Submission Info

Submission Time
Task F - Road of the King
User drafear
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2166 Byte
Status WA
Exec Time 65 ms
Memory 2432 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 0 / 1000
Status
AC × 2
WA × 1
AC × 7
WA × 6
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
Case Name Status Exec Time Memory
01-01.txt AC 2 ms 256 KB
01-02.txt AC 2 ms 256 KB
01-03.txt WA 2 ms 256 KB
01-04.txt AC 2 ms 256 KB
01-05.txt WA 2 ms 256 KB
01-06.txt WA 13 ms 512 KB
01-07.txt WA 63 ms 2304 KB
01-08.txt WA 64 ms 2432 KB
01-09.txt AC 65 ms 2432 KB
01-10.txt AC 65 ms 2432 KB
sample-01.txt AC 2 ms 256 KB
sample-02.txt WA 29 ms 768 KB
sample-03.txt AC 2 ms 256 KB