Submission #8522824
Source Code Expand
#include<iostream> #include<iomanip> #include<cassert> #include<stdexcept> #include<utility> #include<functional> #include<numeric> #include<cmath> #include<algorithm> #include<cstdio> #include<cstdlib> #include<array> #include<stack> #include<queue> #include<deque> #include<vector> #include<complex> #include<set> #include<map> #include<unordered_map> #include<unordered_set> #include<string> #include<bitset> #include<memory> using namespace std; using ll=long long; int main(){ int N,K; ll M; cin>>N>>K>>M; vector<vector<ll>> pat(N+2,vector<ll>(N+2)); pat[1][0]=1; for(int i=0;i<pat.size();i++){ for(int j=0;j<pat[0].size();j++){ if(j+1<pat[0].size()) (pat[i][j+1]+=pat[i][j]*i)%=M; if(i+1<pat.size()) (pat[i+1][j]+=pat[i][j])%=M; } } vector<vector<ll>> dp(K+1,vector<ll>(N+2)); dp[0][1]=1; for(int i=0;i<K;i++){ for(int j=0;j<=N+1;j++){ for(int k=0;j+k<=N+1;k++){ (dp[i+1][j+k]+=dp[i][j]*pat[j][k])%=M; } } } cout<<dp[K][N+1]<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Sequence Growing Hard |
User | nikutto |
Language | C++14 (GCC 5.4.1) |
Score | 1200 |
Code Size | 1160 Byte |
Status | AC |
Exec Time | 141 ms |
Memory | 1664 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1200 / 1200 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, s1.txt, s2.txt, s3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 141 ms | 1664 KB |
02.txt | AC | 124 ms | 1536 KB |
03.txt | AC | 83 ms | 1280 KB |
04.txt | AC | 1 ms | 256 KB |
05.txt | AC | 137 ms | 1664 KB |
06.txt | AC | 4 ms | 1024 KB |
07.txt | AC | 1 ms | 256 KB |
08.txt | AC | 135 ms | 1664 KB |
09.txt | AC | 132 ms | 1664 KB |
10.txt | AC | 79 ms | 1152 KB |
11.txt | AC | 55 ms | 1024 KB |
12.txt | AC | 1 ms | 256 KB |
13.txt | AC | 1 ms | 256 KB |
14.txt | AC | 141 ms | 1664 KB |
15.txt | AC | 16 ms | 896 KB |
16.txt | AC | 95 ms | 1408 KB |
17.txt | AC | 1 ms | 256 KB |
18.txt | AC | 108 ms | 1536 KB |
19.txt | AC | 137 ms | 1664 KB |
20.txt | AC | 31 ms | 896 KB |
21.txt | AC | 4 ms | 1024 KB |
22.txt | AC | 109 ms | 1536 KB |
23.txt | AC | 124 ms | 1536 KB |
24.txt | AC | 2 ms | 256 KB |
25.txt | AC | 5 ms | 384 KB |
26.txt | AC | 120 ms | 1536 KB |
27.txt | AC | 3 ms | 384 KB |
28.txt | AC | 27 ms | 1024 KB |
29.txt | AC | 100 ms | 1408 KB |
30.txt | AC | 5 ms | 384 KB |
31.txt | AC | 120 ms | 1536 KB |
32.txt | AC | 140 ms | 1664 KB |
s1.txt | AC | 1 ms | 256 KB |
s2.txt | AC | 1 ms | 256 KB |
s3.txt | AC | 19 ms | 640 KB |