結果

問題 No.260 世界のなんとか3
ユーザー tossytossy
提出日時 2017-01-01 20:24:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,444 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 91,516 KB
実行使用メモリ 11,152 KB
最終ジャッジ日時 2023-08-22 09:14:40
合計ジャッジ時間 3,004 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,916 KB
testcase_01 AC 5 ms
10,920 KB
testcase_02 AC 6 ms
10,908 KB
testcase_03 AC 67 ms
10,900 KB
testcase_04 AC 67 ms
10,944 KB
testcase_05 AC 17 ms
10,908 KB
testcase_06 AC 13 ms
10,864 KB
testcase_07 AC 47 ms
10,948 KB
testcase_08 AC 35 ms
10,940 KB
testcase_09 AC 22 ms
10,860 KB
testcase_10 AC 52 ms
11,084 KB
testcase_11 AC 49 ms
10,880 KB
testcase_12 AC 32 ms
10,872 KB
testcase_13 AC 13 ms
11,040 KB
testcase_14 AC 45 ms
10,936 KB
testcase_15 AC 16 ms
10,928 KB
testcase_16 AC 41 ms
10,936 KB
testcase_17 AC 33 ms
10,936 KB
testcase_18 AC 32 ms
10,876 KB
testcase_19 AC 40 ms
10,872 KB
testcase_20 AC 30 ms
11,152 KB
testcase_21 AC 27 ms
11,064 KB
testcase_22 AC 45 ms
10,936 KB
testcase_23 AC 10 ms
10,916 KB
testcase_24 AC 36 ms
10,936 KB
testcase_25 AC 44 ms
11,092 KB
testcase_26 AC 28 ms
10,932 KB
testcase_27 AC 6 ms
10,900 KB
testcase_28 AC 50 ms
10,900 KB
testcase_29 AC 84 ms
10,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define MOD 1000000007
#define long long long

long dp[10005][2][2][3][8];
// [上から何桁][EQ?][3を使った][mod3][mod8]

long solve(string &s, bool eq=true){
  fill(dp[0][0][0][0], dp[10002][0][0][0], 0);
  dp[0][1][0][0][0]=1;
  int n = s.size();

  rep(i,n) rep(j,2) rep(k,3) rep(l,8){
    rep(m,10) (dp[i+1][0][j|(m==3)][(k*10+m)%3][(l*10+m)%8] += dp[i][0][j][k][l]) %= MOD;
    int mx = s[i]-'0';
    rep(m,mx+1) (dp[i+1][m==mx][j|(m==3)][(k*10+m)%3][(l*10+m)%8] += dp[i][1][j][k][l]) %= MOD;
  }

  long ret = 0;
  rep(i,2) if(i==0 || eq){
    rep(j,3)rep(k,8) if(k!=0) ret = (ret+dp[n][i][1][j][k])%MOD; // 3を使った
    rep(k,8) if(k!=0) ret = (ret+dp[n][i][0][0][k])%MOD; // 3を使わずmod3=0
  }
  return ret;
}

int main(){
  string a,b;
  cin>>a>>b;

  long ans = solve(b) - solve(a, false);
  cout << (ans+MOD)%MOD << endl;

  return 0;
}
0