結果
問題 | No.260 世界のなんとか3 |
ユーザー |
![]() |
提出日時 | 2015-11-03 14:24:31 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 93 ms / 2,000 ms |
コード長 | 1,028 bytes |
コンパイル時間 | 1,403 ms |
コンパイル使用メモリ | 159,352 KB |
実行使用メモリ | 8,576 KB |
最終ジャッジ日時 | 2024-11-07 18:08:52 |
合計ジャッジ時間 | 3,656 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int dp[10001][2][2][3][8]; int rec(const string& S, int idx, bool free, bool Aho, int three, int eight) { if(idx == S.size()) { return((Aho | (three == 0)) & (eight != 0)); } else if(~dp[idx][free][Aho][three][eight]) { return(dp[idx][free][Aho][three][eight]); } else { int ret = 0; for(int i = max< int >(9 * free, S[idx]); i >= 0; i--) { (ret += rec(S, idx + 1, free|(i != S[idx]), Aho|(i == 3), (three * 10 + i) % 3, (eight * 10 + i) % 8)) %= MOD; } return(dp[idx][free][Aho][three][eight] = ret); } } const int getDP(string S) { for(int i = 0; i < S.size(); i++) S[i] -= '0'; memset(dp, -1, sizeof(dp)); return(rec(S, 0, false, false, 0, 0)); } void Decrement(string& S, int idx) { if(S[idx] == '0') Decrement(S, idx - 1), S[idx] = '9'; else S[idx]--; } int main() { string A, B; cin >> A >> B; Decrement(A, A.size() - 1); cout << (getDP(B) - getDP(A) + MOD) % MOD << endl; }