結果

問題 No.2772 Appearing Even Times
ユーザー ypwwypww
提出日時 2024-05-31 23:45:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,588 ms / 4,000 ms
コード長 2,118 bytes
コンパイル時間 2,472 ms
コンパイル使用メモリ 212,380 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-31 23:45:58
合計ジャッジ時間 32,435 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 6 ms
6,944 KB
testcase_03 AC 4 ms
6,944 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2,238 ms
6,940 KB
testcase_09 AC 2,588 ms
6,944 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 2,416 ms
6,940 KB
testcase_13 AC 2,379 ms
6,940 KB
testcase_14 AC 2,389 ms
6,940 KB
testcase_15 AC 2,357 ms
6,944 KB
testcase_16 AC 2,385 ms
6,944 KB
testcase_17 AC 2,391 ms
6,940 KB
testcase_18 AC 2,389 ms
6,940 KB
testcase_19 AC 2,384 ms
6,940 KB
testcase_20 AC 2,358 ms
6,940 KB
testcase_21 AC 2,374 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>

using namespace std;

#define rep(i, a, b) for(int i=a; i<b; i++)
#define rrep(i, a, b) for(int i=a; i>=b; i--)

using mint = atcoder::modint998244353;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    
    // dpの次元を削減しながらメモリ使用量を減らす
    vector<vector<vector<mint>>> dp(1<<10, vector<vector<mint>>(2, vector<mint>(2)));
    dp[0][1][1] = 1;

    rrep(i, n, 1) {
        int now = s[n - i] - '0';
        vector<vector<vector<mint>>> new_dp(1<<10, vector<vector<mint>>(2, vector<mint>(2)));
        
        rep(j, 0, 1<<10) {
            rep(mode, 0, 2) {
                rep(l, 0, 2) {
                    if (mode) {
                        if (l) {
                            rep(k, 0, now + 1) {
                                if (k == 0) new_dp[j][0][1] += dp[j][mode][l];
                                else if (k < now) new_dp[j^(1<<k)][0][0] += dp[j][mode][l];
                                else new_dp[j^(1<<k)][1][0] += dp[j][mode][l];
                            }
                        } else {
                            rep(k, 0, now + 1) {
                                if (k < now) new_dp[j^(1<<k)][0][0] += dp[j][mode][l];
                                else new_dp[j^(1<<k)][1][0] += dp[j][mode][l];
                            }
                        }
                    } else {
                        if (l) {
                            rep(k, 0, 10) {
                                if (k == 0) new_dp[j][0][1] += dp[j][mode][l];
                                else new_dp[j^(1<<k)][0][0] += dp[j][mode][l];
                            }
                        } else {
                            rep(k, 0, 10) {
                                new_dp[j^(1<<k)][0][0] += dp[j][mode][l];
                            }
                        }
                    }
                }
            }
        }
        
        dp.swap(new_dp);  // 新しいdpに更新
    }
    
    mint ans = dp[0][0][0] + dp[0][1][0];
    cout << ans.val() << endl;

    return 0;
}
0