結果

問題 No.260 世界のなんとか3
ユーザー nenuonnenuon
提出日時 2017-07-22 16:40:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,342 bytes
コンパイル時間 907 ms
コンパイル使用メモリ 85,460 KB
実行使用メモリ 11,864 KB
最終ジャッジ日時 2023-07-30 14:48:48
合計ジャッジ時間 4,160 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 151 ms
11,748 KB
testcase_04 AC 150 ms
11,588 KB
testcase_05 AC 31 ms
7,492 KB
testcase_06 AC 21 ms
5,136 KB
testcase_07 AC 102 ms
11,580 KB
testcase_08 AC 73 ms
11,864 KB
testcase_09 AC 41 ms
7,620 KB
testcase_10 AC 116 ms
9,788 KB
testcase_11 AC 109 ms
11,620 KB
testcase_12 AC 66 ms
9,496 KB
testcase_13 AC 19 ms
4,664 KB
testcase_14 AC 99 ms
11,628 KB
testcase_15 AC 26 ms
4,780 KB
testcase_16 AC 87 ms
9,812 KB
testcase_17 AC 70 ms
7,448 KB
testcase_18 AC 66 ms
7,512 KB
testcase_19 AC 87 ms
11,820 KB
testcase_20 AC 60 ms
7,508 KB
testcase_21 AC 55 ms
9,512 KB
testcase_22 AC 99 ms
9,604 KB
testcase_23 AC 10 ms
4,380 KB
testcase_24 AC 76 ms
9,556 KB
testcase_25 AC 98 ms
11,672 KB
testcase_26 AC 55 ms
11,672 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 108 ms
11,620 KB
testcase_29 AC 191 ms
11,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
const int mod = 1e9 + 7;
ll dp[100005][2][2][3][8]; // 調べた桁数、小さくなることが確定しているか、3がつくか、mod3、mod8
ll calc(string s, bool less) {
  int len = s.length();
  FOR(i,0,len+1) FOR(j,0,2) FOR(k,0,2) FOR(l,0,3) FOR(m,0,8) {
    dp[i][j][k][l][m] = 0;
  }
  dp[0][0][0][0][0] = 1;
  FOR(i,0,len) FOR(j,0,2) FOR(k,0,2) FOR(l,0,3) FOR(m,0,8) {
    int lim = j ? 9 : s[i] - '0';
    FOR(d,0,lim+1) {
      (dp[i+1][j||d<lim][k||d==3][(l+d)%3][(m*10+d)%8] += dp[i][j][k][l][m]) %= mod;
    }
  }
  ll ret = 0;
  if(!less){
    FOR(j,0,2) FOR(k,0,2) FOR(l,0,3) FOR(m,0,8) {
      if((k||l==0) && m!=0) {
        (ret += dp[len][j][k][l][m]) %= mod;
      }
    }
  } else {
    FOR(k,0,2) FOR(l,0,3) FOR(m,0,8) {
      if((k||l==0) && m!=0) {
        (ret += dp[len][1][k][l][m]) %= mod;
      }
    }
  }
  return ret;
}

int main()
{
  string A, B;
  cin >> A >> B;
  ll b = calc(B,0);
  ll a = calc(A,1);
  cout << (b - a + mod) % mod << endl;
  return 0;
}
0