結果

問題 No.315 世界のなんとか3.5
ユーザー shobonvipshobonvip
提出日時 2022-08-07 19:55:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,848 bytes
コンパイル時間 4,237 ms
コンパイル使用メモリ 265,608 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 14:36:20
合計ジャッジ時間 17,977 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 150 ms
4,348 KB
testcase_13 AC 153 ms
4,348 KB
testcase_14 AC 302 ms
4,348 KB
testcase_15 AC 300 ms
4,348 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 1,399 ms
4,348 KB
testcase_19 AC 1,407 ms
4,348 KB
testcase_20 TLE -
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>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)

typedef modint1000000007 mint;
typedef long long ll;

mint solve(string x, bool mode, int p){
  int size = x.size();
  int tp = 3*p;
  vector<mint> dpy(tp);
  vector<mint> dpn(tp);
  bool nowisy = false;
  int nowtp = 0;
  for (int num=0; num<size; num++){
    vector<mint> ndpy(tp);
    vector<mint> ndpn(tp);
    
    //継続
    for (int i=0; i<10; i++){
      if (i==3){
        for (int j=0; j<tp; j++){
          ndpy[(i+10*j)%tp] += dpy[j] + dpn[j];
        }
      }else{
        for (int j=0; j<tp; j++){
          ndpy[(i+10*j)%tp] += dpy[j];
          ndpn[(i+10*j)%tp] += dpn[j];
        }
      }
    }

    //新規
    if (num > 0){
      for (int i=1; i<10; i++){
        if (i==3) ndpy[i] += 1;
        else ndpn[i] += 1;
      }
    }

    int targ = x[num] - '0';

    //解放
    if (nowisy){
      for (int i=(num<1); i<targ; i++){
        ndpy[(i+10*nowtp)%tp] += 1;
      }
    }else{
      for (int i=(num<1); i<targ; i++){
        if (i==3) ndpy[(i+10*nowtp)%tp] += 1;
        else ndpn[(i+10*nowtp)%tp] += 1;
      }
    }

    for (int i=0; i<tp; i++){
      dpn[i] = ndpn[i];
      dpy[i] = ndpy[i];
    }

    if (targ == 3) nowisy = true;
    
    nowtp = (10*nowtp+targ) % tp;
  }

  if (mode){
    if (nowisy) dpy[nowtp] += 1;
    else dpn[nowtp] += 1;
  }

  mint ans = 0;
  for (int i=0; i<tp; i++){
    if (i%p != 0){
      ans += dpy[i];
      if (i%3 == 0) ans += dpn[i];
    }
  }

  return ans;
}

int main(){
  string a, b;
  int p;
  cin >> a >> b >> p;
  mint ans = solve(b,true,p) - solve(a,false,p);
  cout << ans.val() << endl;
}
0