結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | pekempey |
提出日時 | 2015-12-08 00:39:01 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 477 ms / 2,000 ms |
コード長 | 2,236 bytes |
コンパイル時間 | 2,455 ms |
コンパイル使用メモリ | 163,352 KB |
実行使用メモリ | 23,528 KB |
最終ジャッジ日時 | 2024-09-14 18:46:50 |
合計ジャッジ時間 | 8,680 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 9 ms
5,376 KB |
testcase_03 | AC | 3 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 | 2 ms
5,376 KB |
testcase_08 | AC | 11 ms
22,860 KB |
testcase_09 | AC | 9 ms
22,984 KB |
testcase_10 | AC | 9 ms
22,856 KB |
testcase_11 | AC | 10 ms
22,856 KB |
testcase_12 | AC | 100 ms
23,200 KB |
testcase_13 | AC | 98 ms
22,916 KB |
testcase_14 | AC | 185 ms
23,076 KB |
testcase_15 | AC | 186 ms
23,068 KB |
testcase_16 | AC | 189 ms
23,068 KB |
testcase_17 | AC | 189 ms
23,296 KB |
testcase_18 | AC | 101 ms
23,072 KB |
testcase_19 | AC | 100 ms
23,168 KB |
testcase_20 | AC | 110 ms
23,140 KB |
testcase_21 | AC | 111 ms
23,080 KB |
testcase_22 | AC | 198 ms
23,188 KB |
testcase_23 | AC | 198 ms
23,200 KB |
testcase_24 | AC | 188 ms
23,088 KB |
testcase_25 | AC | 198 ms
23,056 KB |
testcase_26 | AC | 188 ms
23,200 KB |
testcase_27 | AC | 188 ms
23,200 KB |
testcase_28 | AC | 193 ms
23,196 KB |
testcase_29 | AC | 324 ms
23,288 KB |
testcase_30 | AC | 316 ms
23,368 KB |
testcase_31 | AC | 314 ms
23,524 KB |
testcase_32 | AC | 374 ms
23,328 KB |
testcase_33 | AC | 201 ms
23,132 KB |
testcase_34 | AC | 378 ms
23,528 KB |
testcase_35 | AC | 477 ms
23,424 KB |
ソースコード
#include <bits/stdc++.h> #define GET_MACRO(a, b, c, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define rep2(i, a) rep3 (i, 0, a) #define rep3(i, a, b) for (int i = (a); i < (b); i++) #define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__) #define repr2(i, a) repr3 (i, 0, a) #define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--) template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } using namespace std; typedef long long ll; const ll mod = 1e9 + 7; ll dp[202020][2][3][2]; // pos, less, mod 3, three ll dp2[8][2][3][2][800]; // pos, less, mod 3, three, mod P template<class T> T parse(string s) { istringstream iss(s); T res; iss >> res; return res; } ll f(string N, int P) { if (N.length() < 7) { int n = parse<int>(N); int res = 0; rep (i, n + 1) { bool three = i % 3 == 0; bool eight = i % P == 0; int t = i; while (t > 0) { if (t % 10 == 3) three = true; t /= 10; } if (three && !eight) res++; } return res; } memset(dp, 0, sizeof(dp)); memset(dp2, 0, sizeof(dp2)); int s = N.length(); dp[0][0][0][0] = 1; rep (i, s - 7) rep (j, 2) rep (k, 3) rep (l, 2) { int ub = 9; if (!j) ub = N[i] - '0'; rep (m, ub + 1) { (dp[i + 1][j || m < ub][(k + m) % 3][l || m == 3] += dp[i][j][k][l]) %= mod; } } s -= 7; rep (j, 2) rep (k, 3) rep (l, 2) { dp2[0][j][k][l][0] = dp[s][j][k][l]; } rep (i, 7) rep (j, 2) rep (k, 3) rep (l, 2) rep (m, P) { int ub = 9; if (!j) ub = N[s + i] - '0'; rep (x, ub + 1) { (dp2[i + 1][j || x < ub][(k + x) % 3][l || x == 3][(m * 10 + x) % P] += dp2[i][j][k][l][m]) %= mod; } } ll res = 0; rep (j, 2) rep (k, 3) rep (l, 2) rep (m, P) { if ((k == 0 || l) && m != 0) { (res += dp2[7][j][k][l][m]) %= mod; } } return res; } int main() { string A, B; int P; cin >> A >> B >> P; int borrow = 1; repr (i, A.length()) { int d = A[i] - '0'; d -= borrow; if (d >= 0) borrow = 0; else d += 10; A[i] = d + '0'; } ll ans = f(B, P); ans -= f(A, P); ans %= mod; ans += mod; ans %= mod; cout << ans << endl; return 0; }