結果

問題 No.824 Many Shifts Hard
ユーザー chocoruskchocorusk
提出日時 2020-04-19 02:43:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,755 bytes
コンパイル時間 1,199 ms
コンパイル使用メモリ 128,600 KB
実行使用メモリ 219,608 KB
最終ジャッジ日時 2024-04-14 21:26:57
合計ジャッジ時間 21,532 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 47 ms
59,000 KB
testcase_03 AC 434 ms
110,516 KB
testcase_04 AC 253 ms
88,100 KB
testcase_05 AC 1,608 ms
181,548 KB
testcase_06 AC 12 ms
16,116 KB
testcase_07 AC 139 ms
66,328 KB
testcase_08 AC 1,342 ms
171,380 KB
testcase_09 AC 846 ms
132,584 KB
testcase_10 AC 36 ms
42,816 KB
testcase_11 AC 109 ms
62,784 KB
testcase_12 AC 393 ms
104,488 KB
testcase_13 AC 1,068 ms
157,528 KB
testcase_14 TLE -
testcase_15 AC 1,799 ms
200,412 KB
testcase_16 AC 58 ms
59,044 KB
testcase_17 TLE -
testcase_18 AC 2 ms
6,940 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 4 ms
7,620 KB
testcase_22 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll comb[303][303];
ll dp[303][303][303];
int main()
{
    int n, k;
    cin>>n>>k;
    for(int i=0; i<=k; i++){
        comb[i][0]=1, comb[i][i]=1;
        for(int j=1; j<i; j++) comb[i][j]=(comb[i-1][j]+comb[i-1][j-1])%MOD;
    }
    for(int i=2; i<=k+1; i++){
        dp[i][1][1]=i-1;
        dp[i][1][2]=1;
        for(int j=2; j<=k; j++){
            for(int m=1; m<j; m++){
                for(int l=2; l<=min(i, m+2); l++){
                    (dp[i][j][l]+=dp[i-1][m][l-1]*comb[j-1][m])%=MOD;
                }
            }
        }
        for(int j=2; j<=k; j++) dp[i][j][2]++;
        for(int j=2; j<=k; j++){
            for(int l=1; l<=min(i, j+1); l++){
                if(l==1){
                    (dp[i][j][l]+=dp[i][j-1][l]*(i-1)+dp[i][j-1][l+1])%=MOD;
                }else{
                    (dp[i][j][l]+=dp[i][j-1][l]*(i-2)+dp[i][j-1][l+1])%=MOD;
                }
            }
        }
    }
    ll ans=0;
    for(int i=1; i<=n; i++){
        int m=min(n-i+1, k+1);
        ll p=1;
        for(int j=0; j<=k; j++){
            (ans+=comb[k][j]*p%MOD*i%MOD*((j==k)?1:dp[m][k-j][1]))%=MOD;
            (p*=(n-m))%=MOD;
        }
    }
    cout<<ans<<endl;
	return 0;
}
0