結果

問題 No.824 Many Shifts Hard
ユーザー chocoruskchocorusk
提出日時 2020-04-19 04:33:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 658 ms / 2,000 ms
コード長 1,617 bytes
コンパイル時間 1,334 ms
コンパイル使用メモリ 128,640 KB
実行使用メモリ 435,236 KB
最終ジャッジ日時 2024-04-14 21:28:20
合計ジャッジ時間 8,601 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 58 ms
54,068 KB
testcase_03 AC 226 ms
183,436 KB
testcase_04 AC 145 ms
124,092 KB
testcase_05 AC 508 ms
358,460 KB
testcase_06 AC 5 ms
7,408 KB
testcase_07 AC 77 ms
68,048 KB
testcase_08 AC 448 ms
332,852 KB
testcase_09 AC 320 ms
243,656 KB
testcase_10 AC 28 ms
26,852 KB
testcase_11 AC 67 ms
60,612 KB
testcase_12 AC 205 ms
162,548 KB
testcase_13 AC 406 ms
303,332 KB
testcase_14 AC 658 ms
434,652 KB
testcase_15 AC 588 ms
397,700 KB
testcase_16 AC 70 ms
63,172 KB
testcase_17 AC 605 ms
432,392 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 611 ms
434,376 KB
testcase_20 AC 602 ms
434,576 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 608 ms
435,236 KB
権限があれば一括ダウンロードができます

ソースコード

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 dp[2][303][303][303];
int main()
{
    int n, k;
    cin>>n>>k;
    for(int i=1; i<=min(k, n-1); i++){
        dp[0][0][i][i+1]=1;
    }
    dp[1][0][k][k+1]=1;
    for(int i=0; i<k; i++){
        for(int j=0; j<=k; j++){
            for(int l=j+1; l<=k+1; l++){
                for(int t=0; t<2; t++){
                    int c=1;
                    if(j) (dp[t][i+1][j-1][l]+=dp[t][i][j][l])%=MOD, c++;
                    if(j+1<l) (dp[t][i+1][j][l-1]+=dp[t][i][j][l])%=MOD;
                    (dp[t][i+1][j][l]+=(n-c)*dp[t][i][j][l])%=MOD;
                }
            }
        }
    }
    ll ans=1;
    for(int i=0; i<k; i++) (ans*=(n-1))%=MOD;
    for(int i=0; i<=k; i++){
        for(int j=i+1; j<=k+1; j++){
            (ans+=dp[0][k][i][j]*j)%=MOD;
        }
    }
    if(n>=k+2){
        for(int i=0; i<=k; i++){
            for(int j=i+1; j<=k+1; j++){
                ll c=(n-k-1)*j+(ll)(n-k-1)*(n-k)/2;
                c%=MOD;
                (ans+=dp[1][k][i][j]*c)%=MOD;
            }
        }
    }
    cout<<ans<<endl;
	return 0;
}
0