Submission #1991494


Source Code Expand

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 302;

ll add(ll x,ll y)
{
    return (x + y)%MOD;
}

ll sub(ll x,ll y)
{
    return (x+MOD-y)%MOD;
}

ll mul(ll x,ll y)
{
    return x*y%MOD;
}

int dp[MAX_N][MAX_N][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    dp[0][1][1] = 1;
    rep(i,m){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=j;k++){
                dp[i+1][j+1][k] = add(dp[i+1][j+1][k],mul(dp[i][j][k],n-j));
                dp[i+1][j][j] = add(dp[i+1][j][j],mul(dp[i][j][k],k));
                dp[i+1][j][k] = add(dp[i+1][j][k],mul(dp[i][j][k],j-k));
            }
        }
    }
    cout << dp[m][n][n] << "\n";
    return 0;
}

Submission Info

Submission Time
Task F - Road of the King
User kopricky
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 1868 Byte
Status AC
Exec Time 154 ms
Memory 107136 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 21 ms 104704 KB
01-04.txt AC 2 ms 640 KB
01-05.txt AC 22 ms 104832 KB
01-06.txt AC 34 ms 105472 KB
01-07.txt AC 145 ms 106752 KB
01-08.txt AC 152 ms 107136 KB
01-09.txt AC 153 ms 107136 KB
01-10.txt AC 154 ms 107136 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 55 ms 105984 KB
sample-03.txt AC 78 ms 55168 KB