結果

問題 No.260 世界のなんとか3
ユーザー HankHank
提出日時 2017-08-29 23:59:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 341 ms / 2,000 ms
コード長 1,408 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 95,284 KB
実行使用メモリ 11,168 KB
最終ジャッジ日時 2024-04-24 03:03:30
合計ジャッジ時間 5,411 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 261 ms
11,004 KB
testcase_04 AC 276 ms
10,848 KB
testcase_05 AC 55 ms
6,944 KB
testcase_06 AC 37 ms
6,940 KB
testcase_07 AC 183 ms
9,956 KB
testcase_08 AC 127 ms
9,964 KB
testcase_09 AC 75 ms
6,944 KB
testcase_10 AC 204 ms
9,216 KB
testcase_11 AC 193 ms
10,192 KB
testcase_12 AC 116 ms
8,776 KB
testcase_13 AC 33 ms
6,940 KB
testcase_14 AC 168 ms
9,976 KB
testcase_15 AC 46 ms
6,940 KB
testcase_16 AC 151 ms
8,608 KB
testcase_17 AC 117 ms
7,296 KB
testcase_18 AC 113 ms
6,996 KB
testcase_19 AC 150 ms
9,924 KB
testcase_20 AC 106 ms
7,424 KB
testcase_21 AC 99 ms
7,872 KB
testcase_22 AC 175 ms
8,708 KB
testcase_23 AC 17 ms
6,940 KB
testcase_24 AC 131 ms
9,260 KB
testcase_25 AC 178 ms
11,072 KB
testcase_26 AC 96 ms
11,168 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 266 ms
11,064 KB
testcase_29 AC 341 ms
10,908 KB
権限があれば一括ダウンロードができます

ソースコード

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)%8] += 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;
  cin >> A >> B;

  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, 8);
  ll nb = withMod2DP(B, 3, 3, 8);
  if((nb-na)<0) cout << nb-na + MOD << endl;
  else cout << nb - na << endl;
  return 0;
}
0