結果

問題 No.1513 simple 門松列 problem
ユーザー KudeKude
提出日時 2021-05-21 22:38:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 3,000 ms
コード長 1,779 bytes
コンパイル時間 4,792 ms
コンパイル使用メモリ 256,056 KB
実行使用メモリ 214,592 KB
最終ジャッジ日時 2024-04-18 16:08:26
合計ジャッジ時間 6,512 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
214,332 KB
testcase_01 AC 55 ms
214,588 KB
testcase_02 AC 79 ms
214,584 KB
testcase_03 AC 54 ms
214,460 KB
testcase_04 AC 54 ms
214,332 KB
testcase_05 AC 54 ms
214,588 KB
testcase_06 AC 55 ms
214,460 KB
testcase_07 AC 55 ms
214,332 KB
testcase_08 AC 54 ms
214,456 KB
testcase_09 AC 54 ms
214,460 KB
testcase_10 AC 55 ms
214,460 KB
testcase_11 AC 55 ms
214,588 KB
testcase_12 AC 54 ms
214,584 KB
testcase_13 AC 55 ms
214,588 KB
testcase_14 AC 79 ms
214,460 KB
testcase_15 AC 79 ms
214,460 KB
testcase_16 AC 80 ms
214,588 KB
testcase_17 AC 71 ms
214,332 KB
testcase_18 AC 60 ms
214,328 KB
testcase_19 AC 55 ms
214,460 KB
testcase_20 AC 58 ms
214,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

mint dp1[300][300][300], dp2[300][300][300];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    rep(b, k) rep(a, b) {
        dp1[0][a][b] = 1;
        dp2[0][a][b] = a + b;
    }
    rep(i, n - 2) {
        if (i % 2 == 0) {
            rep(b, k) {
                mint v1 = 0, v2 = 0;
                rep(a, b) v1 += dp1[i][a][b], v2 += dp2[i][a][b];
                rep(c, b) {
                    dp1[i+1][b][c] = v1 - dp1[i][c][b];
                    dp2[i+1][b][c] = v2 - dp2[i][c][b] + (v1 - dp1[i][c][b]) * c;
                }
            }
        } else {
            rep(b, k) {
                mint v1 = 0, v2 = 0;
                for(int a = b + 1; a < k; a++) v1 += dp1[i][a][b], v2 += dp2[i][a][b];
                for(int c = b + 1; c < k; c++) {
                    dp1[i+1][b][c] = v1 - dp1[i][c][b];
                    dp2[i+1][b][c] = v2 - dp2[i][c][b] + (v1 - dp1[i][c][b]) * c;
                }
            }
        }
    }
    mint ans1, ans2;
    rep(i, k) rep(j, k) ans1 += dp1[n - 2][i][j], ans2 += dp2[n - 2][i][j];
    ans2 += ans1 * (k - 1) * n - ans2;
    ans1 *= 2;
    cout << ans1.val() << ' ' << ans2.val() << '\n';
}
0