結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | anta |
提出日時 | 2015-12-08 00:23:55 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 258 ms / 2,000 ms |
コード長 | 3,225 bytes |
コンパイル時間 | 985 ms |
コンパイル使用メモリ | 86,436 KB |
実行使用メモリ | 29,568 KB |
最終ジャッジ日時 | 2024-09-14 18:39:54 |
合計ジャッジ時間 | 5,621 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 7 ms
5,376 KB |
testcase_03 | AC | 4 ms
5,376 KB |
testcase_04 | AC | 4 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 18 ms
5,376 KB |
testcase_09 | AC | 18 ms
5,376 KB |
testcase_10 | AC | 13 ms
5,376 KB |
testcase_11 | AC | 18 ms
5,376 KB |
testcase_12 | AC | 84 ms
16,228 KB |
testcase_13 | AC | 83 ms
16,360 KB |
testcase_14 | AC | 138 ms
16,384 KB |
testcase_15 | AC | 136 ms
16,384 KB |
testcase_16 | AC | 137 ms
16,384 KB |
testcase_17 | AC | 139 ms
16,384 KB |
testcase_18 | AC | 82 ms
16,340 KB |
testcase_19 | AC | 81 ms
16,256 KB |
testcase_20 | AC | 81 ms
16,384 KB |
testcase_21 | AC | 82 ms
16,256 KB |
testcase_22 | AC | 137 ms
16,384 KB |
testcase_23 | AC | 137 ms
16,512 KB |
testcase_24 | AC | 136 ms
16,384 KB |
testcase_25 | AC | 134 ms
16,384 KB |
testcase_26 | AC | 135 ms
16,384 KB |
testcase_27 | AC | 138 ms
16,256 KB |
testcase_28 | AC | 124 ms
16,256 KB |
testcase_29 | AC | 234 ms
29,568 KB |
testcase_30 | AC | 242 ms
29,440 KB |
testcase_31 | AC | 242 ms
29,476 KB |
testcase_32 | AC | 258 ms
29,440 KB |
testcase_33 | AC | 145 ms
29,192 KB |
testcase_34 | AC | 222 ms
29,476 KB |
testcase_35 | AC | 243 ms
29,440 KB |
ソースコード
#include <string> #include <vector> #include <algorithm> #include <numeric> #include <set> #include <map> #include <queue> #include <iostream> #include <sstream> #include <cstdio> #include <cmath> #include <ctime> #include <cstring> #include <cctype> #include <cassert> #include <limits> #include <functional> #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) #if defined(_MSC_VER) || __cplusplus > 199711L #define aut(r,v) auto r = (v) #else #define aut(r,v) __typeof(v) r = (v) #endif #define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it) #define all(o) (o).begin(), (o).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset(m,v,sizeof(m)) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll; template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; } template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; } template<int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) {} ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; } ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } }; typedef ModInt<1000000007> mint; vector<int> digits; int P; vector<mint> memo; bool eqOK; mint rec(int i, int m, bool three, bool lt) { mint &r = memo[((i + 1) * 3 + m) * 4 + three * 2 + lt]; if(r.x != -1) return r; if(i <= 4) { r = mint(); int p = 1; int es = 0; rep(j, i + 1) { es += p * digits[j]; p *= 10; } rep(ds, p) if(lt || ds <= es) { bool nlt = lt || ds < es; int nm = (m * p + ds) % 3; bool nthree = three; int t = ds; rep(j, i+1) { nthree |= t % 10 == 3; t /= 10; } bool ok = true; ok &= nlt || eqOK; ok &= nm == 0 || nthree; ok &= ds % P != 0; if(ok) r += 1; } return r; } r = mint(); int e = digits[i]; rep(d, 10) if(lt || d <= e) r += rec(i-1, (m * 10 + d) % 3, three || d == 3, lt || d < e); return r; } mint solve(const char *A) { int len = strlen(A); digits.resize(len); rep(i, len) digits[i] = A[len - 1 - i] - '0'; mint r; mint undef; undef.x = -1; memo.assign((len+1) * 3 * 4, undef); return rec(len - 1, 0, false, false); } int main() { char *A = new char[200002], *B = new char[200002]; while(~scanf("%s%s%d", A, B, &P)) { mint ans; eqOK = true; ans += solve(B); eqOK = false; ans -= solve(A); printf("%d\n", ans.get()); } return 0; }