結果

問題 No.315 世界のなんとか3.5
ユーザー oevloevl
提出日時 2019-03-19 03:09:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 966 bytes
コンパイル時間 1,882 ms
コンパイル使用メモリ 168,692 KB
実行使用メモリ 814,644 KB
最終ジャッジ日時 2023-09-27 11:17:38
合計ジャッジ時間 5,111 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
153,276 KB
testcase_01 MLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
const ll mod = 1e9 + 7;
template<class T> void add(T &a, T b) {a = (a + b) % mod;}

ll solve(string S, int P){
  ll dp[200005][2][3][2][P];
  rep(i, 200005) rep(j, 2) rep(k, 3) rep(l, 2) rep(m, P) dp[i][j][k][l][m] = 0;
  dp[0][0][0][0][0] = 1;
  rep(i, S.size()) rep(j, 2) rep(k, 3) rep(l, 2) rep(m, P) {
    int x = j ? 9 : S[i] - '0';
    rep(d, x + 1) {
      add(dp[i + 1][j || d < x][(k + d) % 3][l || d == 3][(10 * m + d) % P], dp[i][j][k][l][m]);
    }
  }
  ll ans = 0;
  rep(j, 2) rep(k, 3) rep(l, 2) rep(m, P){
    if((k == 0 || l) && (m != 0)) add(ans, dp[S.size()][j][k][l][m]);
  }
  return ans;
}

int main(){
  string A, B;
  int P;
  cin >> A >> B >> P;
  int a = A[A.size() - 1] - '0';
  A = A.substr(0, A.size() - 1);
  A += ('0' + a - 1);
  ll ans = solve(B, P);
  add(ans, -solve(A, P) + mod);
  cout << ans << endl;
  return 0;
}
0