結果
問題 | No.260 世界のなんとか3 |
ユーザー |
![]() |
提出日時 | 2019-02-16 17:12:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 202 ms / 2,000 ms |
コード長 | 1,747 bytes |
コンパイル時間 | 1,768 ms |
コンパイル使用メモリ | 171,876 KB |
実行使用メモリ | 18,688 KB |
最終ジャッジ日時 | 2024-09-22 14:33:36 |
合計ジャッジ時間 | 5,449 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int (i) = (0); (i) < (n); ++(i)) template<class T> void Add(T &a, const T &b, const T &mod=1000000007) { int val = ((a % mod) + (b % mod)) % mod; if (val < 0) { val += mod; } a = val; } // ------------------------------------------------------------------------------------------ string A, B; int dp[11111][2][2][2][3][8]; signed main() { cin >> A >> B; int diff = B.size() - A.size(); string zero = ""; rep (i, diff) { zero += "0"; } A = zero + A; // DPテーブルを初期化 dp[0][0][0][0][0][0] = 1; // DP for (int digit = 0; digit < B.size(); digit++) { for (int over : {0, 1}) { for (int less : {0, 1}) { for (int three : {0, 1}) { for (int mod3 = 0; mod3 < 3; mod3++) { for (int mod8 = 0; mod8 < 8; mod8++) { int ue = (less ? 9 : B[digit] - '0'); int shita = (over ? 0 : A[digit] - '0'); for (int num = shita; num <= ue; num++) { Add(dp[digit+1][over || (num > shita)][less || (num < ue)][three || (num == 3)][(mod3+num)%3][(10*mod8+num)%8], dp[digit][over][less][three][mod3][mod8]); } } } } } } } // 総和を求める int ans = 0; for (int over : {0, 1}) { for (int less : {0, 1}) { for (int three : {0, 1}) { for (int mod3 = 0; mod3 < 3; mod3++) { for (int mod8 = 0; mod8 < 8; mod8++) { if ((three || mod3 == 0) && (mod8 != 0)) { Add(ans, dp[B.size()][over][less][three][mod3][mod8]); } } } } } } cout << ans << endl; return 0; }