結果

問題 No.2367 Painting Gascket
ユーザー 👑 kmjpkmjp
提出日時 2023-06-30 23:52:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 2,533 bytes
コンパイル時間 2,064 ms
コンパイル使用メモリ 202,444 KB
実行使用メモリ 17,588 KB
最終ジャッジ日時 2023-09-21 18:00:04
合計ジャッジ時間 4,047 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,820 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 4 ms
9,736 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 37 ms
17,532 KB
testcase_09 AC 25 ms
14,828 KB
testcase_10 AC 5 ms
9,780 KB
testcase_11 AC 33 ms
16,612 KB
testcase_12 AC 5 ms
9,800 KB
testcase_13 AC 13 ms
11,668 KB
testcase_14 AC 8 ms
10,764 KB
testcase_15 AC 8 ms
10,688 KB
testcase_16 AC 16 ms
12,328 KB
testcase_17 AC 34 ms
16,828 KB
testcase_18 AC 27 ms
15,116 KB
testcase_19 AC 18 ms
13,180 KB
testcase_20 AC 34 ms
16,708 KB
testcase_21 AC 20 ms
13,868 KB
testcase_22 AC 35 ms
17,260 KB
testcase_23 AC 27 ms
15,356 KB
testcase_24 AC 13 ms
11,852 KB
testcase_25 AC 13 ms
11,884 KB
testcase_26 AC 6 ms
10,204 KB
testcase_27 AC 28 ms
15,472 KB
testcase_28 AC 24 ms
14,600 KB
testcase_29 AC 4 ms
9,760 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 5 ms
9,656 KB
testcase_32 AC 4 ms
9,580 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 37 ms
17,404 KB
testcase_36 AC 37 ms
17,588 KB
権限があれば一括ダウンロードができます

ソースコード

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;
	if(N==1) {
		cout<<(K==0)<<endl;
		return;
	}
	if(N==2) {
		cout<<2<<endl;
		return;
	}
	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