結果
問題 | No.315 世界のなんとか3.5 |
ユーザー |
|
提出日時 | 2017-03-22 23:24:23 |
言語 | D (dmd 2.109.1) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,168 bytes |
コンパイル時間 | 786 ms |
コンパイル使用メモリ | 113,568 KB |
実行使用メモリ | 17,464 KB |
最終ジャッジ日時 | 2024-06-12 18:28:15 |
合計ジャッジ時間 | 23,902 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 TLE * 6 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;import std.typecons, std.range, std.random, std.math, std.container;import std.numeric, std.bigint, core.bitop;immutable int MOD = 10^^9+7;int solve(ref string N, int P, bool less) {auto M = N.length;auto dp = new int[][][][][](2, 2, 3, 2, 800);// 桁, N未満か, mod3, 3がつくか, mod Pdp[0][0][0][0][0] = 1;foreach (a; 0..M) {int cur = a % 2;int tar = 1 - cur;dp[tar] = new int[][][][](2, 3, 2, 800);foreach (b; 0..2) {int digit = b ? 10 : N[a]-'0'+1;foreach (c; 0..3) {foreach (d; 0..2) {if (M - a < 6) {foreach (e; 0..P) {foreach (f; 0..digit) {dp[tar][b||(f<N[a]-'0')][(c+f)%3][d||(f==3)][(10*e+f)%P] +=dp[cur][b][c][d][e];dp[tar][b||(f<N[a]-'0')][(c+f)%3][d||(f==3)][(10*e+f)%P] %= MOD;}}}else {foreach (f; 0..digit) {dp[tar][b||(f<N[a]-'0')][(c+f)%3][d||(f==3)][0] +=dp[cur][b][c][d][0];dp[tar][b||(f<N[a]-'0')][(c+f)%3][d||(f==3)][0] %= MOD;}}}}}}int ret = 0;foreach (a; 0..2) {if (less && (a == 0)) continue;foreach (b; 0..3) {foreach (c; 0..2) {foreach (d; 1..P) {if (b == 0 || c == 1) {ret += dp[M%2][a][b][c][d];ret %= MOD;}}}}}return ret;}void main() {auto s = readln.split;auto A = s[0];auto B = s[1];auto P = s[2].to!int;auto a = solve(A, P, true);auto b = solve(B, P, false);auto ans = (b - a) % MOD;ans = (ans + MOD) % MOD;ans.writeln;}