結果

問題 No.1513 simple 門松列 problem
ユーザー poyo_starpoyo_star
提出日時 2021-05-21 22:33:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,507 ms / 3,000 ms
コード長 1,983 bytes
コンパイル時間 2,167 ms
コンパイル使用メモリ 199,560 KB
実行使用メモリ 128,548 KB
最終ジャッジ日時 2024-04-18 16:04:49
合計ジャッジ時間 10,062 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1,507 ms
128,548 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1,459 ms
126,688 KB
testcase_15 AC 1,463 ms
127,308 KB
testcase_16 AC 1,480 ms
127,868 KB
testcase_17 AC 836 ms
81,308 KB
testcase_18 AC 296 ms
29,724 KB
testcase_19 AC 6 ms
5,376 KB
testcase_20 AC 106 ms
19,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    long n, k, mod = 998244353, ans = 0, bns = 0;
    cin >> n >> k;
    for(int q = 0; q < 2; q++){
        long a[n][k][k] = {}, b[n][k][k] = {};
        for(int i = 0; i < k; i++){
            if(q){
                for(int j = i + 1; j < k; j++){
                    a[1][i][j] = 1;
                    b[1][i][j] = j;
                }
            }
            else{
                for(int j = 0; j < i; j++){
                    a[1][i][j] = 1;
                    b[1][i][j] = j;
                }
            }
        }
        for(int i = 2; i < n; i++){
            for(int j = 0; j < k; j++){
                if((i + q) % 2){
                    for(int l = 0; l < j; l++){
                        for(int m = l + 1; m < k; m++){
                            if(j != m){
                                a[i][j][l] += a[i - 1][l][m];
                                b[i][j][l] += b[i - 1][l][m] + a[i - 1][l][m] * l;
                            }
                        }
                        a[i][j][l] %= mod;
                        b[i][j][l] %= mod;
                    }
                }
                else{
                    for(int l = j + 1; l < k; l++){
                        for(int m = 0; m < l; m++){
                            if(j != m){
                                a[i][j][l] += a[i - 1][l][m];
                                b[i][j][l] += b[i - 1][l][m] + a[i - 1][l][m] * l;
                            }
                        }
                        a[i][j][l] %= mod;
                        b[i][j][l] %= mod;
                    }
                }
            }
        }
        for(int i = 0; i < k; i++){
            for(int j = 0; j < k; j++){
                ans += a[n - 1][i][j];
                bns += b[n - 1][i][j] +  + a[n - 1][i][j] * i;
            }
            ans %= mod;
            bns %= mod;
        }
    }
    cout << ans << " " << bns << endl;
}
0