結果

問題 No.840 ほむほむほむら
ユーザー parukiparuki
提出日時 2019-07-10 22:41:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 385 ms / 4,000 ms
コード長 1,999 bytes
コンパイル時間 1,834 ms
コンパイル使用メモリ 172,744 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 03:04:57
合計ジャッジ時間 4,756 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 9 ms
6,940 KB
testcase_03 AC 54 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 17 ms
6,940 KB
testcase_08 AC 97 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 26 ms
6,944 KB
testcase_13 AC 247 ms
6,944 KB
testcase_14 AC 32 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 6 ms
6,944 KB
testcase_17 AC 59 ms
6,944 KB
testcase_18 AC 324 ms
6,940 KB
testcase_19 AC 385 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 6 ms
6,940 KB
testcase_23 AC 379 ms
6,944 KB
testcase_24 AC 6 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 9 ms
6,940 KB
testcase_27 AC 365 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

const int MOD = 998244353;

vector<vector<int> > mulMatMod(const vector<vector<int> > &A, const vector<vector<int> > &B) {
    auto n = (int)A.size(), m = (int)A[0].size(), p = (int)B[0].size();
    vector<vector<int> > res(n, vector<int>(p));
    for (int i = 0; i < n; ++i)for (int j = 0; j < p; ++j) for (int k = 0; k < m; ++k)
        res[i][j] = (int)((res[i][j] + (long long)A[i][k] * B[k][j]) % MOD);
    return res;
}

vector<vector<int> > powMatMod(vector<vector<int> > A, long long k) {
    auto n = (int)A.size();
    vector<vector<int> > res(n, vector<int>(n));
    for (int i = 0; i < n; ++i)res[i][i] = 1;
    while (k) {
        if (k % 2)res = mulMatMod(res, A);
        k /= 2;
        A = mulMatMod(A, A);
    }
    return res;
}

void solve() {
    int N, K;
    cin >> N >> K;
    auto f = [&](int h, int m, int r) {
        return h * K * K + m * K + r;
    };

    int M = K * K*K;
    vector<vi> A(M, vi(M));
    rep(h, K)rep(m, K)rep(r, K) {
        int x = f(h, m, r);
        int hh = f((h + 1) % K, m, r);
        int mm = f(h, (h + m) % K, r);
        int rr = f(h, m, (m + r) % K);
        A[hh][x]++;
        A[mm][x]++;
        A[rr][x]++;
    }
    auto B = powMatMod(A, N);
    int ans = 0;
    rep(h, K)rep(m, K) (ans += B[f(h, m, 0)][0]) %= MOD;
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0