結果

問題 No.315 世界のなんとか3.5
ユーザー rickythetarickytheta
提出日時 2015-12-08 10:18:39
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,459 bytes
コンパイル時間 1,891 ms
コンパイル使用メモリ 157,072 KB
実行使用メモリ 8,872 KB
最終ジャッジ日時 2023-10-12 21:32:26
合計ジャッジ時間 5,381 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,700 KB
testcase_01 AC 6 ms
4,428 KB
testcase_02 AC 8 ms
4,536 KB
testcase_03 AC 7 ms
4,416 KB
testcase_04 AC 7 ms
4,724 KB
testcase_05 AC 8 ms
4,540 KB
testcase_06 AC 8 ms
4,540 KB
testcase_07 AC 7 ms
4,556 KB
testcase_08 AC 9 ms
4,428 KB
testcase_09 AC 8 ms
4,536 KB
testcase_10 AC 8 ms
4,464 KB
testcase_11 AC 9 ms
4,556 KB
testcase_12 TLE -
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;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vvvvl> vvvvvl;
typedef vector<vvvvvl> vvvvvvl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

ll calc(string s,int p){
  ll n = s.size();

  vvvvl dp(2,           // pos
      vvvl(2400,        // mod2400
       vvl(2,           // found 3 flag
        vl(2,0))));     // less flag
  int now = 0;
  int nxt = 1;
  dp[0][0][0][0] = 1;
  REP(pos,n){
    int d = s[pos]-'0';
    REP(md,2400){
      REP(t,10){
        ll nmd = (md*10+t)%2400;
        if(t==3){
          // necessarily aho
          dp[nxt][nmd][1][1] += dp[now][md][1][1] + dp[now][md][0][1];
          if(t < d) dp[nxt][nmd][1][1] += dp[now][md][1][0] + dp[now][md][0][0];
          else if(t == d) dp[nxt][nmd][1][0] += dp[now][md][1][0] + dp[now][md][0][0];
        }else{
          // not sure aho
          dp[nxt][nmd][1][1] += dp[now][md][1][1];
          dp[nxt][nmd][0][1] += dp[now][md][0][1];
          if(t < d){
            dp[nxt][nmd][1][1] += dp[now][md][1][0];
            dp[nxt][nmd][0][1] += dp[now][md][0][0];
          }else if(t==d){
            dp[nxt][nmd][1][0] += dp[now][md][1][0];
            dp[nxt][nmd][0][0] += dp[now][md][0][0];
          }
        }
        dp[nxt][nmd][0][0] %= MOD;
        dp[nxt][nmd][0][1] %= MOD;
        dp[nxt][nmd][1][0] %= MOD;
        dp[nxt][nmd][1][1] %= MOD;
      }
      dp[now][md][0][0]=dp[now][md][0][1]=dp[now][md][1][0]=dp[now][md][1][1]=0;
    }
    now = 1-now;
    nxt = 1-nxt;
  }
  ll result = 0;
  REP(is3,2)REP(less,2)REP(md,2400){
    if(md%p==0)continue;
    if(is3==1 || md%3==0)result = (result+dp[now][md][is3][less])%MOD;
  }
  return result;
}

int main(){
  string a,b;
  int p;
  cin>>a>>b>>p;
  ll iter = a.size()-1;
  while(iter>=0){
    if(a[iter]!='0'){
      a[iter]--;
      break;
    }
    a[iter]='9';
    iter--;
  }
  ll result = calc(b,p)-calc(a,p);
  result = FIX(result);
  cout << result << endl;
  return 0;
}
0