結果

問題 No.840 ほむほむほむら
ユーザー Kiona1018Kiona1018
提出日時 2019-09-12 00:31:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,545 bytes
コンパイル時間 1,618 ms
コンパイル使用メモリ 172,432 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-15 14:02:26
合計ジャッジ時間 4,532 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using mat = vector<vector<int>>;
const int MOD = 998244353;

mat matmul(int n, mat A, mat B)
{
    mat C(n, vector<int>(n, 0));
    rep(i, 0, n)
        rep(j, 0, n)
            rep(k, 0, n)
            {
                C[i][j] += A[i][k] * B[k][j];
                C[i][j] %= MOD;
            }
    return C;
}

int main()
{
    int N, K;
    cin >> N >> K;

    // initialize matrix
    int k3 = K * K * K;

    mat A(k3, vector<int>(k3, 0));
    rep(num, 0, k3)
    {
        int i, j, k;
        i = num % K;
        j = (num / K) % K;
        k = (num / (K * K)) % K;

        int num2 = (i + 1) % K + j * K + k * K * K;
        int num3 = i + ((i + j)%K) * K + k * K * K;
        int num4 = i + j * K + ((j + k)%K) * K * K;
        A[num2][num]++;
        A[num3][num]++;
        A[num4][num]++;
    }

    int n = N;
    mat An(k3, vector<int>(k3, 0));
    rep(i, 0, k3)
        An[i][i] = 1;

    while (n)
    {

        if (n & 1)
        {
            An = matmul(k3, A, An);
        }
        A = matmul(k3, A, A);
        n >>= 1;
    }

    ll ans = 0;
    rep(num, 0, k3)
    {
        int i, j, k;
        i = num % K;
        j = (num / K) % K;
        k = (num / (K * K)) % K;

        if (k % K != 0)
            continue;

        ans += An[num][0];
        ans %= MOD;

        cout << An[num][0] << endl;
    }
    cout << ans << endl;
    return 0;
}
0