結果

問題 No.840 ほむほむほむら
ユーザー PulmnPulmn
提出日時 2019-06-14 21:37:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 147 ms / 4,000 ms
コード長 1,414 bytes
コンパイル時間 1,401 ms
コンパイル使用メモリ 154,780 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-08 17:33:45
合計ジャッジ時間 4,229 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 21 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 38 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 11 ms
4,384 KB
testcase_13 AC 96 ms
4,380 KB
testcase_14 AC 13 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 23 ms
4,376 KB
testcase_18 AC 121 ms
4,376 KB
testcase_19 AC 147 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 140 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 140 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353 ;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

vvl mul(vvl A,vvl B){
	vvl C(A.size(),vl(B[0].size()));
	for(int i=0;i<A.size();i++) for(int k=0;k<B.size();k++) for(int j=0;j<B[0].size();j++) (C[i][j]+=A[i][k]*B[k][j])%=mod;
	return C;
}

vvl pow(vvl A,ll n){
	vvl B(A.size(),vl(A.size()));
	for(int i=0;i<A.size();i++) B[i][i]=1;
	while(n>0){
		if(n&1) B=mul(B,A);
		A=mul(A,A);
		n>>=1;
	}
	return B;
}

int n,k;

int main(){
	cin>>n>>k;
	int N=k*k*k;
	vvl a(N,vl(N));
	for(int i=0;i<N;i++) for(int j=0;j<3;j++){
		int I=i%k,J=i/k%k,K=i/(k*k);
		if(j==0) (I+=1)%=k;
		if(j==1) (J+=I)%=k;
		if(j==2) (K+=J)%=k;
		a[i][I+J*k+K*k*k]++;
	}
	a=pow(a,n);
	vvl b(N,vl(1));
	b[0][0]++;
	a=mul(a,b);
	ll res=0;
	for(int i=0;i<N;i++) if(i/(k*k)==0) (res+=a[i][0])%=mod;
	cout<<res<<endl;
}
0