結果

問題 No.824 Many Shifts Hard
ユーザー chocoruskchocorusk
提出日時 2020-04-19 03:51:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,971 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 128,540 KB
実行使用メモリ 220,820 KB
最終ジャッジ日時 2024-04-14 21:27:36
合計ジャッジ時間 20,347 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,688 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 48 ms
56,980 KB
testcase_03 AC 420 ms
96,052 KB
testcase_04 AC 243 ms
83,580 KB
testcase_05 AC 1,511 ms
182,528 KB
testcase_06 AC 10 ms
19,980 KB
testcase_07 AC 129 ms
64,712 KB
testcase_08 AC 1,261 ms
173,620 KB
testcase_09 AC 794 ms
133,968 KB
testcase_10 AC 34 ms
43,248 KB
testcase_11 AC 101 ms
70,076 KB
testcase_12 AC 374 ms
104,312 KB
testcase_13 AC 1,020 ms
161,088 KB
testcase_14 TLE -
testcase_15 AC 1,707 ms
201,656 KB
testcase_16 AC 59 ms
66,616 KB
testcase_17 AC 1,981 ms
220,180 KB
testcase_18 AC 3 ms
7,760 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 4 ms
7,628 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;
using ll=unsigned long long;
const ll MOD=1e9+7;
ll comb[303][303];
ll dp[303][303][303];
ll s[303][303];
int c[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;
    }
    s[1][0]=1;
    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];
                    if(!(c[j][l]&15)) dp[i][j][l]%=MOD;
                    c[j][l]++;
                }
            }
        }
        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;
                }
            }
        }
        s[i][0]=1;
        for(int j=1; j<=k; j++) s[i][j]=dp[i][j][1];
    }
    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*s[m][k-j])%=MOD;
            (p*=(n-m))%=MOD;
        }
    }
    cout<<ans<<endl;
	return 0;
}
0