結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | mkawa2 |
提出日時 | 2024-09-24 00:16:49 |
言語 | C++23(gcc13) (gcc 13.2.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,647 bytes |
コンパイル時間 | 7,635 ms |
コンパイル使用メモリ | 101,000 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 06:05:53 |
合計ジャッジ時間 | 33,132 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,812 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 5 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 3 ms
6,944 KB |
testcase_08 | AC | 3 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | WA | - |
testcase_12 | AC | 280 ms
6,940 KB |
testcase_13 | AC | 338 ms
6,944 KB |
testcase_14 | WA | - |
testcase_15 | AC | 593 ms
6,944 KB |
testcase_16 | AC | 685 ms
6,944 KB |
testcase_17 | AC | 711 ms
6,940 KB |
testcase_18 | AC | 394 ms
6,940 KB |
testcase_19 | AC | 355 ms
6,940 KB |
testcase_20 | AC | 370 ms
6,940 KB |
testcase_21 | AC | 334 ms
6,940 KB |
testcase_22 | AC | 743 ms
6,944 KB |
testcase_23 | AC | 725 ms
6,940 KB |
testcase_24 | AC | 734 ms
6,940 KB |
testcase_25 | AC | 744 ms
6,940 KB |
testcase_26 | AC | 704 ms
6,940 KB |
testcase_27 | AC | 753 ms
6,940 KB |
testcase_28 | AC | 704 ms
6,940 KB |
testcase_29 | AC | 1,396 ms
6,940 KB |
testcase_30 | AC | 1,414 ms
6,944 KB |
testcase_31 | AC | 1,382 ms
6,940 KB |
testcase_32 | AC | 1,473 ms
6,940 KB |
testcase_33 | AC | 730 ms
6,944 KB |
testcase_34 | AC | 1,485 ms
6,940 KB |
testcase_35 | AC | 1,520 ms
6,940 KB |
コンパイルメッセージ
main.cpp: In function 'long long int digitdp(std::vector<int>&, bool, int)': main.cpp:49:46: warning: 's' may be used uninitialized [-Wmaybe-uninitialized] 49 | for (int j=i+1;j<aa.size();j++) s+=aa[j]; main.cpp:48:17: note: 's' was declared here 48 | int s; | ^
ソースコード
#include <iostream> #include <vector> using namespace std; const int md = 1e9 + 7; long long digitdp(vector<int>& aa, bool eq, int p) { int k = to_string(p).length(); p = stoi(to_string(p)); long long res = 0; vector<vector<long long>> dp(2, vector<long long>(24, 0)); int jf = 0, jm = 0; for (size_t i = 0; i < aa.size(); ++i) { vector<vector<long long>> ndp(2, vector<long long>(24, 0)); // Transition from less than confirmed for (int f = 0; f < 2; ++f) { for (int m = 0; m < 24; ++m) { long long pre = dp[f][m] % md; if (pre == 0) continue; for (int d = 0; d < 10; ++d) { int nf = f | (d == 3); int nm = (m * 10 + d) % 24; ndp[nf][nm] += pre; } } } // Transition from exactly for (int d = (i == 0); d < aa[i]; ++d) { int nf = jf | (d == 3); int nm = (jm * 10 + d) % 24; ndp[nf][nm] += 1; } // Start from this digit if (i) { for (int d = 1; d < 10; ++d) { ndp[d == 3][d] += 1; } } // Update exactly jf |= (aa[i] == 3); jm = (jm * 10 + aa[i]) % 24; dp = ndp; if (i == aa.size() - k) { int s; for (int j=i+1;j<aa.size();j++) s+=aa[j]; if ((jf || jm % 3 == 0) && jm % 8 == 0 && s) res -= 1; for (int f = 0; f < 2; ++f) { for (int m = 0; m < 24; ++m) { if ((f || m % 3 == 0) && m % 8 == 0) { res -= dp[f][m]; res %= md; } } } } } if (eq) { long long pos = 0; int l = max(0, (int)aa.size() - 5); for (size_t i = l; i < aa.size(); ++i) { pos = (pos * 10 + aa[i]) % p; } if ((jf || jm % 3 == 0) && pos) res += 1; } for (int f = 0; f < 2; ++f) { for (int m = 0; m < 24; ++m) { if (f || m % 3 == 0) { res += dp[f][m]; res %= md; } } } return res; } int main() { string a, b, p; cin >> a >> b >> p; vector<int> aa(a.size()), bb(b.size()); for (size_t i = 0; i < a.size(); ++i) aa[i] = a[i] - '0'; for (size_t i = 0; i < b.size(); ++i) bb[i] = b[i] - '0'; int k = p.size(); long long ans = digitdp(bb, true, stoi(p)) - digitdp(aa, false, stoi(p)); cout << (ans % md + md) % md << endl; return 0; }