結果

問題 No.2649 [Cherry 6th Tune C] Anthem Flower
ユーザー nono00nono00
提出日時 2024-02-23 22:27:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,213 bytes
コンパイル時間 4,420 ms
コンパイル使用メモリ 257,060 KB
実行使用メモリ 13,352 KB
最終ジャッジ日時 2024-02-23 22:27:49
合計ジャッジ時間 16,632 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,352 KB
testcase_01 AC 1,916 ms
6,548 KB
testcase_02 AC 1,938 ms
6,676 KB
testcase_03 AC 1,914 ms
6,676 KB
testcase_04 AC 1,928 ms
6,676 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

struct P {
    long long count = 0;
    long long value = 0;
};

void solve() {
    std::string s;
    int mod;
    std::cin >> s >> mod;
    std::vector<int> a;
    for (auto c: s) a.push_back(c - '0');
    std::ranges::reverse(a);
    int n = a.size();

    std::vector dp(n + 1, std::vector<P>(2));
    dp[0][0].value = 0;
    dp[0][0].count = 1;
    long long p10 = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2; j++) {
            for (int digit = 0; digit < 10; digit++) {
                int greater = 1;
                if (digit < a[i]) greater = 0;
                if (j == 0 && digit == a[i]) greater = 0;
                dp[i + 1][greater].count += dp[i][j].count;
                dp[i + 1][greater].count %= mod;
                dp[i + 1][greater].value += (p10 * digit % mod * dp[i][j].count % mod) + dp[i][j].value;
                dp[i + 1][greater].value %= mod;
            }
        }
        p10 *= 10;
        p10 %= mod;
    }
    std::cout << dp.back()[0].value << '\n';
}

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(16);
    int t = 1;
    std::cin >> t;
    while (t--) solve();
}
0