結果
問題 | No.824 Many Shifts Hard |
ユーザー | beet |
提出日時 | 2019-04-27 13:56:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 153 ms / 2,000 ms |
コード長 | 2,148 bytes |
コンパイル時間 | 2,180 ms |
コンパイル使用メモリ | 201,000 KB |
実行使用メモリ | 225,268 KB |
最終ジャッジ日時 | 2023-08-18 14:16:44 |
合計ジャッジ時間 | 5,472 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 58 ms
225,228 KB |
testcase_01 | AC | 59 ms
225,112 KB |
testcase_02 | AC | 63 ms
225,040 KB |
testcase_03 | AC | 84 ms
224,964 KB |
testcase_04 | AC | 74 ms
225,020 KB |
testcase_05 | AC | 127 ms
225,136 KB |
testcase_06 | AC | 58 ms
225,268 KB |
testcase_07 | AC | 64 ms
225,016 KB |
testcase_08 | AC | 123 ms
225,016 KB |
testcase_09 | AC | 99 ms
224,988 KB |
testcase_10 | AC | 61 ms
225,104 KB |
testcase_11 | AC | 64 ms
225,104 KB |
testcase_12 | AC | 80 ms
225,044 KB |
testcase_13 | AC | 113 ms
225,136 KB |
testcase_14 | AC | 150 ms
224,960 KB |
testcase_15 | AC | 138 ms
224,964 KB |
testcase_16 | AC | 65 ms
225,048 KB |
testcase_17 | AC | 150 ms
224,964 KB |
testcase_18 | AC | 59 ms
225,124 KB |
testcase_19 | AC | 59 ms
224,992 KB |
testcase_20 | AC | 153 ms
225,100 KB |
testcase_21 | AC | 59 ms
224,980 KB |
testcase_22 | AC | 150 ms
224,980 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} template<typename T,T MOD = 1000000007> struct Mint{ T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0) v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;}; Mint operator-(Mint a) const{return Mint(v)-=a;}; Mint operator*(Mint a) const{return Mint(v)*=a;}; Mint operator/(Mint a) const{return Mint(v)/=a;}; Mint operator-(){return v?MOD-v:v;} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} bool operator <(const Mint a)const{return v <a.v;} }; //INSERT ABOVE HERE const int MAX = 305; using M = Mint<int>; M dp[2][MAX][MAX][MAX]; signed main(){ int n,k; cin>>n>>k; if(n==1){ cout<<0<<endl; return 0; } // x != 1 dp[0][0][0][1]=1; // x == 1 dp[1][0][0][1]=1; for(int l=0;l<k;l++){ for(int i=0;i<=k;i++){ for(int j=i+1;j<=k+1;j++){ if(i+1<j){ dp[0][l+1][i+1][j]+=dp[0][l][i][j]; dp[1][l+1][i+1][j]+=dp[1][l][i][j]; } dp[0][l+1][i][j+1]+=dp[0][l][i][j]; dp[1][l+1][i][j+1]+=dp[0][l][i][j]; dp[0][l+1][i][j]+=dp[0][l][i][j]*M(n-2); dp[1][l+1][i][j]+=dp[1][l][i][j]*M(n-1); } } } M ans(0); { int l=k; for(int i=0;i<=k;i++){ for(int j=i+1;j<=k+1;j++){ if(j>n) break; ans+=dp[0][l][i][j]*M(1LL*((j-i+1)+(n-i))*(n-j)/2); ans+=dp[1][l][i][j]*M(j-i); } } } cout<<ans.v<<endl; return 0; }