結果
| 問題 |
No.2367 Painting Gascket
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-30 22:44:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 1,765 bytes |
| コンパイル時間 | 1,895 ms |
| コンパイル使用メモリ | 194,352 KB |
| 最終ジャッジ日時 | 2025-02-15 04:18:59 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) ((int)a.size())
const int N=100005;
const int mod=1000000007;
int add(int x, int y){x+=y; if(x>=mod) x-=mod; return x;}
int sub(int x, int y){x-=y; if(x<0) x+=mod; return x;}
int mul(int x, int y){return ((ll)x)*y%mod;}
int Pow(int x, ll y=mod-2){int res=1; for(; y; x=mul(x,x),y>>=1) if(y&1) res=mul(res,x); return res;}
int k,n,dp[N][7];
// 0
// 1
// 2, same
// 2, different
// 3, all same
// 3, two same
// 3, all different
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> k >> n;
dp[0][0]=max(n,0);
dp[0][1]=dp[0][2]=dp[0][4]=max(n-1,0);
dp[0][3]=dp[0][5]=max(n-2,0);
dp[0][6]=max(n-3,0);
for(int i=1; i<=k; ++i){
dp[i][0]=mul(mul(n,dp[i-1][1]),mul(dp[i-1][1],dp[i-1][1]));
dp[i][1]=add(mul(dp[i-1][1],mul(dp[i-1][2],dp[i-1][2])),mul(mul(n-1,dp[i-1][1]),mul(dp[i-1][3],dp[i-1][3])));
dp[i][2]=add(mul(dp[i-1][4],mul(dp[i-1][2],dp[i-1][2])),mul(mul(n-1,dp[i-1][5]),mul(dp[i-1][3],dp[i-1][3])));
dp[i][4]=add(mul(dp[i-1][4],mul(dp[i-1][4],dp[i-1][4])),mul(mul(n-1,dp[i-1][5]),mul(dp[i-1][5],dp[i-1][5])));
if(n>=2){
dp[i][3]=add(mul(mul(2,dp[i-1][5]),mul(dp[i-1][2],dp[i-1][3])),mul(mul(n-2,dp[i-1][6]),mul(dp[i-1][3],dp[i-1][3])));
dp[i][5]=add(add(mul(dp[i-1][4],mul(dp[i-1][5],dp[i-1][5])),mul(dp[i-1][5],mul(dp[i-1][5],dp[i-1][5]))),mul(mul(n-2,dp[i-1][5]),mul(dp[i-1][6],dp[i-1][6])));
}
if(n>=3){
dp[i][6]=add(mul(mul(3,dp[i-1][6]),mul(dp[i-1][5],dp[i-1][5])),mul(mul(n-3,dp[i-1][6]),mul(dp[i-1][6],dp[i-1][6])));
}
}
cout << dp[k][0] << "\n";
}