Submission #7096105


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll N, M;
ll Prev[605][605][2];
ll Next[605][605][2];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    Prev[1][0][0] = 1;
    ll minus;
    while(M--) {
        if(M == 0) minus = Prev[N][0][0] * N % mod;
        for(int i = 0; i <= N; i++) {
            for(int j = 0; j <= N; j++) {
                for(int k = 0; k <= 1; k++) {
                    Next[i][j][k] = 0;
                }
            }
        }
        for(ll i = 0; i <= N; i++) {
            for(ll j = 0; j <= N; j++) {
                Next[i][j][0] += Prev[i][j][0] * i;
                Next[i][j][1] += Prev[i][j][0] * j;
                Next[i][j+1][1] += Prev[i][j][0] * (N - i - j);
                Next[i+j][0][0] += Prev[i][j][1] * i;
                Next[i][j][1] += Prev[i][j][1] * j;
                Next[i][j+1][1] += Prev[i][j][1] * (N - i - j);
                Next[i][j][0] %= mod;
                Next[i][j][1] %= mod;
                Next[i][j+1][1] %= mod;
                Next[i+j][0][0] %= mod;
            }
        }
        swap(Next, Prev);
        /*
        cerr << endl;
        cerr << M << endl;
        for(int i = 0; i <= N; i++) {
            for(int j = 0; j <= N; j++) {
                cerr << i << " " << j << " " << Prev[i][j][0] << " " << Prev[i][j][1] << endl;
            }
        }
        */
    }
    cerr << minus << endl;
    cerr << Prev[N][0][1] << endl;
    //cout << (Prev[N][0][0] - minus + mod) % mod << endl;
    cout << (Prev[N][0][0] + mod) % mod << endl;
    return 0;
}

Submission Info

Submission Time
Task F - Road of the King
User kort0n
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 2100 Byte
Status AC
Exec Time 506 ms
Memory 11648 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 5 ms 11648 KB
01-02.txt AC 6 ms 11648 KB
01-03.txt AC 238 ms 11648 KB
01-04.txt AC 6 ms 11648 KB
01-05.txt AC 239 ms 11648 KB
01-06.txt AC 263 ms 11648 KB
01-07.txt AC 487 ms 11648 KB
01-08.txt AC 503 ms 11648 KB
01-09.txt AC 505 ms 11648 KB
01-10.txt AC 506 ms 11648 KB
sample-01.txt AC 7 ms 11648 KB
sample-02.txt AC 307 ms 11648 KB
sample-03.txt AC 256 ms 11648 KB