結果
問題 | No.2649 [Cherry 6th Tune C] Anthem Flower |
ユーザー |
![]() |
提出日時 | 2024-02-23 22:35:24 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,271 ms / 2,000 ms |
コード長 | 1,388 bytes |
コンパイル時間 | 2,667 ms |
コンパイル使用メモリ | 255,840 KB |
実行使用メモリ | 27,092 KB |
最終ジャッジ日時 | 2024-09-29 07:35:49 |
合計ジャッジ時間 | 12,941 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#include <bits/stdc++.h>struct P {int count = 0;int 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 % mod;int p10 = 1 % mod;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;if (dp[i + 1][greater].count >= mod) dp[i + 1][greater].count -= mod;int diff = (long long)p10 * digit * dp[i][j].count % mod;diff += dp[i][j].value;if (diff >= mod) diff -= mod;dp[i + 1][greater].value += diff;if (dp[i + 1][greater].value >= mod) dp[i + 1][greater].value -= mod;}}p10 = (long long)p10 * 10 % 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();}