結果

問題 No.840 ほむほむほむら
ユーザー snrnsidysnrnsidy
提出日時 2021-11-27 04:21:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 477 ms / 4,000 ms
コード長 1,540 bytes
コンパイル時間 2,223 ms
コンパイル使用メモリ 205,856 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 08:19:15
合計ジャッジ時間 5,878 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 10 ms
4,380 KB
testcase_03 AC 65 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 21 ms
4,376 KB
testcase_08 AC 118 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 32 ms
4,380 KB
testcase_13 AC 308 ms
4,380 KB
testcase_14 AC 40 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 71 ms
4,380 KB
testcase_18 AC 392 ms
4,380 KB
testcase_19 AC 477 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 7 ms
4,380 KB
testcase_23 AC 458 ms
4,376 KB
testcase_24 AC 7 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 10 ms
4,380 KB
testcase_27 AC 455 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;

const long long int MOD = 998244353;

vector <vector<long long int>> mul(vector <vector<long long int>> a, vector<vector<long long int>> b)
{
	int n = a.size();
	int m = a[0].size();
	int k = b[0].size();
	vector <vector<long long int>>c(n, vector<long long int>(k,0));

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < k; j++)
		{
			for (int k = 0; k < m; k++)
			{
				c[i][j] += ((a[i][k]%MOD) * (b[k][j]%MOD)%MOD);
				c[i][j] %= MOD;
			}
		}
	}

	return c;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,k;

    cin >> n >> k;

	vector <vector<long long int>> A(k*k*k,vector<long long int>(k*k*k,0));
	vector <vector<long long int>> B(k*k*k,vector<long long int>(k*k*k,0));

    B[0][0] = 1;

    for(int a=0;a<k;a++)
    {
        for(int b=0;b<k;b++)
        {
            for(int c=0;c<k;c++)
            {
                int u = k*k*a + b*k + c;
                int v = ((a+1)%k)*k*k + b*k + c;
                A[v][u] += 1;
                v = a*k*k + ((a+b)%k)*k + c;
                A[v][u] += 1;
                v = a*k*k + b*k + (b+c)%k;
                A[v][u] += 1;   
            }
        }
    }

	while(n>0)
	{
		if(n%2==1)
		{
			B = mul(A,B);
		}
		A = mul(A,A);
		n/=2;
	}

	//cout << b[14*A + B][14*A + B] << '\n';
	long long int res = 0;
	for(int i=0;i<k;i++)
    {
        for(int j=0;j<k;j++)
        {
            res += B[i*k*k + j*k][0];
            res%=MOD;   
        }
    }

	cout << res << '\n';
	

    return 0;
}
0