結果

問題 No.840 ほむほむほむら
ユーザー chocoruskchocorusk
提出日時 2019-06-14 22:34:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 365 ms / 4,000 ms
コード長 1,653 bytes
コンパイル時間 1,125 ms
コンパイル使用メモリ 109,452 KB
実行使用メモリ 4,444 KB
最終ジャッジ日時 2023-08-09 01:54:45
合計ジャッジ時間 4,336 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 8 ms
4,376 KB
testcase_03 AC 51 ms
4,444 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 17 ms
4,380 KB
testcase_08 AC 91 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 26 ms
4,380 KB
testcase_13 AC 236 ms
4,380 KB
testcase_14 AC 31 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 55 ms
4,380 KB
testcase_18 AC 300 ms
4,380 KB
testcase_19 AC 365 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 350 ms
4,376 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 8 ms
4,380 KB
testcase_27 AC 350 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;
int k;
vector<vector<ll>> matrixmul(int l, int m, int n, vector<vector<ll>> a, vector<vector<ll>> b){
	vector<vector<ll>> c;
	for(int i=0; i<l; i++){
		vector<ll> v;
		for(int j=0; j<n; j++){
			ll x=0;
			for(int k=0; k<m; k++){
				x+=(a[i][k]*b[k][j]);
				x%=MOD;
			}
			v.push_back(x);
		}
		c.push_back(v);
	}
	return c;
}
vector<vector<ll>> matrixpow(int n, vector<vector<ll>> a, ll k){
	vector<vector<ll>> ap=a, ans;
	for(int i=0; i<n; i++){
		vector<ll> v;
		for(int j=0; j<n; j++){
			if(i==j){
				v.push_back(1);
			}else{
				v.push_back(0);
			}
		}
		ans.push_back(v);
	}
	while(k){
		if(k&1) ans=matrixmul(n, n, n, ap, ans);
		ap=matrixmul(n, n, n, ap, ap);
		k>>=1;
	}
	return ans;
}
int main()
{
    ll n; cin>>n>>k;
    vector<vector<ll>> mat(k*k*k, vector<ll>(k*k*k));
    for(int i=0; i<k*k*k; i++){
        int i0=i;
        int x=i0%k; i0/=k;
        int y=i0%k; i0/=k;
        int z=i0;
        mat[(x+1)%k+y*k+z*k*k][i]++;
        mat[x+(x+y)%k*k+z*k*k][i]++;
        mat[x+y*k+(y+z)%k*k*k][i]++;
    }
    vector<vector<ll>> mp=matrixpow(k*k*k, mat, n);
    ll ans=0;
    for(int i=0; i<k*k; i++) (ans+=mp[i][0])%=MOD;
    cout<<ans<<endl;
    return 0;
}
0