結果
問題 | No.260 世界のなんとか3 |
ユーザー | ty70 |
提出日時 | 2016-10-10 05:39:10 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,770 bytes |
コンパイル時間 | 2,858 ms |
コンパイル使用メモリ | 148,588 KB |
実行使用メモリ | 11,192 KB |
最終ジャッジ日時 | 2023-08-14 06:03:23 |
合計ジャッジ時間 | 4,880 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
11,136 KB |
testcase_01 | AC | 6 ms
10,924 KB |
testcase_02 | AC | 6 ms
10,808 KB |
testcase_03 | AC | 148 ms
10,896 KB |
testcase_04 | AC | 149 ms
10,920 KB |
testcase_05 | AC | 33 ms
10,896 KB |
testcase_06 | AC | 24 ms
10,820 KB |
testcase_07 | AC | 103 ms
10,900 KB |
testcase_08 | AC | 73 ms
10,836 KB |
testcase_09 | AC | 43 ms
10,940 KB |
testcase_10 | AC | 115 ms
11,124 KB |
testcase_11 | AC | 107 ms
10,920 KB |
testcase_12 | AC | 67 ms
10,824 KB |
testcase_13 | AC | 23 ms
11,008 KB |
testcase_14 | AC | 98 ms
10,904 KB |
testcase_15 | AC | 30 ms
10,900 KB |
testcase_16 | AC | 87 ms
10,960 KB |
testcase_17 | AC | 70 ms
10,872 KB |
testcase_18 | AC | 68 ms
10,928 KB |
testcase_19 | AC | 86 ms
10,904 KB |
testcase_20 | WA | - |
testcase_21 | AC | 55 ms
11,108 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 98 ms
10,952 KB |
testcase_26 | AC | 57 ms
10,920 KB |
testcase_27 | AC | 5 ms
10,876 KB |
testcase_28 | WA | - |
testcase_29 | AC | 190 ms
11,060 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair<int, int> P; const ll mod = (ll)1e9 + 7LL; ll dp[10004][2][2][3][8]; // dp[i桁目][N未満であることが確定しているか 0 -> していない 1 -> している][3 の付く数字か 0 -> そうでない 1 -> そう][mod 3 の値][mod 8 の値] ll solve (string s){ memset (dp, 0LL, sizeof(dp)); int n = s.length(); dp[0][0][0][0][0] = 1LL; for (int i = 0; i < n; ++i){ int D = (int)(s[i] - '0'); for (int j = 0; j < 2; ++j){ for (int k = 0; k < 2; ++k){ for (int l = 0; l < 3; ++l){ for (int m = 0; m < 8; ++m){ for (int d = 0; d < (j ? 10 : D + 1); ++d){ ll & ans = dp[i + 1][j || d < D][k || (d == 3)][(10 * l + d) % 3][(10 * m + d) % 8]; ans = (ans + dp[i][j][k][l][m]) % mod; } // end for } // end for } // end for } // end for } // end for } // end for ll res = 0LL; for (int j = 0; j < 2; ++j){ for (int k = 0;k < 2; ++k){ for (int l = 0; l < 3; ++l){ for (int m = 0; m < 8; ++m){ if ((k == 1 || l == 0) && (m != 0)) res = (res + dp[n][j][k][l][m]) % mod; } // end for } // end for } // end for } // end for return res; } string minus_one(string s){ reverse(ALL(s)); for (int i = 0; i < s.length(); ++i){ if (s[i] != '0'){ s[i] = (char)((int)(s[0] - '0') - 1 + '0'); break; }else{ s[i] = '9'; } // end if } // end for if (s.length() > 1 && s[s.length() - 1] == '0') s = s.substr(0, s.length() - 1); reverse(ALL(s)); return s; } int main(){ string A, B; cin >> A >> B; A = minus_one(A); ll res = (solve(B) - solve(A) + mod) % mod; cout << res << endl; return 0; }