結果
問題 | No.824 Many Shifts Hard |
ユーザー | beet |
提出日時 | 2019-04-27 13:57:51 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 183 ms / 2,000 ms |
コード長 | 2,098 bytes |
コンパイル時間 | 2,574 ms |
コンパイル使用メモリ | 199,824 KB |
実行使用メモリ | 225,188 KB |
最終ジャッジ日時 | 2023-08-18 14:20:19 |
合計ジャッジ時間 | 6,618 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 98 ms
225,036 KB |
testcase_01 | AC | 99 ms
225,016 KB |
testcase_02 | AC | 104 ms
224,976 KB |
testcase_03 | AC | 127 ms
225,048 KB |
testcase_04 | AC | 116 ms
225,036 KB |
testcase_05 | AC | 161 ms
225,136 KB |
testcase_06 | AC | 85 ms
225,136 KB |
testcase_07 | AC | 95 ms
224,984 KB |
testcase_08 | AC | 150 ms
225,028 KB |
testcase_09 | AC | 127 ms
225,092 KB |
testcase_10 | AC | 86 ms
225,056 KB |
testcase_11 | AC | 97 ms
225,024 KB |
testcase_12 | AC | 109 ms
225,132 KB |
testcase_13 | AC | 143 ms
225,096 KB |
testcase_14 | AC | 181 ms
224,988 KB |
testcase_15 | AC | 169 ms
225,032 KB |
testcase_16 | AC | 89 ms
225,136 KB |
testcase_17 | AC | 179 ms
225,080 KB |
testcase_18 | AC | 85 ms
225,188 KB |
testcase_19 | AC | 181 ms
225,016 KB |
testcase_20 | AC | 181 ms
224,972 KB |
testcase_21 | AC | 84 ms
225,028 KB |
testcase_22 | AC | 183 ms
225,020 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; // 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; }