結果

問題 No.2367 Painting Gascket
ユーザー 👑 kmjpkmjp
提出日時 2023-06-30 23:53:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,434 bytes
コンパイル時間 2,020 ms
コンパイル使用メモリ 202,884 KB
実行使用メモリ 14,164 KB
最終ジャッジ日時 2023-09-21 18:00:36
合計ジャッジ時間 6,201 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,656 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int K,N;
const ll mo=1000000007;

ll memo[101010][8];

ll hoge(int K,int pat) {
	if(K==0) {
		if(pat==0) return N;
		if(pat==1||pat==2||pat==3) return N-1;
		if(pat==4||pat==5) return N-2;
		return N-3;
	}
	if(memo[K][pat]>=0) return memo[K][pat];
	
	ll ret=0;
	if(pat==0) {
		ret=N*hoge(K-1,1)%mo*hoge(K-1,1)%mo*hoge(K-1,1)%mo;     // *** -> X**,X**,X**
	}
	if(pat==1) {
		ret=(N-1)*hoge(K-1,4)%mo*hoge(K-1,4)%mo*hoge(K-1,1)%mo; // A** -> AX*,AX*,X**
		ret+=hoge(K-1,2)%mo*hoge(K-1,2)%mo*hoge(K-1,1)%mo;      // A** -> AA*,AA*,A**
	}
	if(pat==2) {
		ret=(N-1)*hoge(K-1,5)%mo*hoge(K-1,4)%mo*hoge(K-1,4)%mo; // AA* -> AAX,AX*,AX*
		ret+=hoge(K-1,3)%mo*hoge(K-1,2)%mo*hoge(K-1,2)%mo;      // AA* -> AAA,AA*,AA*
	}
	if(pat==3) {
		ret=(N-1)*hoge(K-1,5)%mo*hoge(K-1,5)%mo*hoge(K-1,5)%mo; // AAA -> AAX,AAX,AAX
		ret+=hoge(K-1,3)%mo*hoge(K-1,3)%mo*hoge(K-1,3)%mo;      // AAA -> AAA,AAA,AAA
	}
	if(pat==4) {
		ret=(N-2)*hoge(K-1,6)%mo*hoge(K-1,4)%mo*hoge(K-1,4)%mo; // AB* -> ABX,AX*,BX*
		ret+=2*hoge(K-1,5)%mo*hoge(K-1,2)%mo*hoge(K-1,4)%mo;    // AB* -> AAB,AA*,AB*
	}
	if(pat==5) {
		ret=(N-2)*hoge(K-1,6)%mo*hoge(K-1,6)%mo*hoge(K-1,5)%mo; // ABB -> ABX,ABX,BBX
		ret+=hoge(K-1,5)%mo*hoge(K-1,5)%mo*hoge(K-1,5)%mo;      // ABB -> AAB,AAB,ABB
		ret+=hoge(K-1,3)%mo*hoge(K-1,5)%mo*hoge(K-1,5)%mo;      // ABB -> ABB,ABB,BBB
	}
	if(pat==6) {
		ret=(N-3)*hoge(K-1,6)%mo*hoge(K-1,6)%mo*hoge(K-1,6)%mo; // ABC -> ABX,BCX,ACX
		ret+=3*hoge(K-1,5)%mo*hoge(K-1,5)%mo*hoge(K-1,6)%mo;    // ABC -> AAB,ABC,AAC
	}
	
	return memo[K][pat]=ret%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>K>>N;
	MINUS(memo);
	cout<<hoge(K,0)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0