結果

問題 No.315 世界のなんとか3.5
ユーザー HankHank
提出日時 2017-08-30 10:04:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,436 bytes
コンパイル時間 786 ms
コンパイル使用メモリ 93,800 KB
実行使用メモリ 78,696 KB
最終ジャッジ日時 2023-08-06 11:21:46
合計ジャッジ時間 9,130 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 21 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 22 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 4 ms
4,504 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1,983 ms
78,696 KB
testcase_13 AC 1,986 ms
78,504 KB
testcase_14 TLE -
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 <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
 
#define MOD 1000000007
#define ll long long 
#define ld long double
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
using namespace std;

ll withMod2DP(string s, ll _witha, ll _moda,ll _modb){
  ll n = s.size();
  ll dp[n+1][2][2][_moda][_modb]; // keta,less,forbid, mod  _moda, mod _modb
  rep(i,n+1)rep(j,2)rep(k,2)rep(l,_moda)rep(m,_modb) dp[i][j][k][l][m] = 0;
  
  dp[0][0][0][0][0] = 1;
  rep(keta,n)rep(less,2)rep(ng,2)rep(l,_moda)rep(m,_modb){
    int lim = less? 9 : s[keta]-'0';
    rep(d,lim+1)
      (dp[keta+1][less||d<lim][ng||d==_witha][(l+d)%_moda][(m*10+d)%_modb] += dp[keta][less][ng][l][m])%=MOD;      
  }

  ll result = 0;
  rep(less,2)rep(ng,2)rep(l,_moda)rep(m,_modb){
    //modaで割ってあまりが0, modbで割って、あまりが0じゃない
    if( (ng || l==0) && m!=0)(result += dp[n][less][ng][l][m])%=MOD;
  }
  return result;
  
}

int main(){ 
  cin.tie(0);
  ios::sync_with_stdio(false);

  string A,B,P;
  cin >> A >> B >> P;
  ll p = stoi(P);
  ll n = A.size();
  rep(i,n){
    if(A[n-i-1]=='0')A[n-i-1]='9';
    else{
      A[n-i-1]-=1;
      break;
    }
  }
  
  ll na = withMod2DP(A, 3, 3, p);
  ll nb = withMod2DP(B, 3, 3, p);
  if((nb-na)<0) cout << nb-na + MOD << endl;
  else cout << nb - na << endl;
  return 0;
}
0