結果

問題 No.260 世界のなんとか3
ユーザー nenuonnenuon
提出日時 2017-07-22 16:40:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,342 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 92,572 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-17 15:55:22
合計ジャッジ時間 4,011 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 152 ms
11,008 KB
testcase_04 AC 156 ms
11,008 KB
testcase_05 AC 31 ms
6,272 KB
testcase_06 AC 21 ms
5,376 KB
testcase_07 AC 107 ms
9,856 KB
testcase_08 AC 74 ms
9,856 KB
testcase_09 AC 43 ms
6,784 KB
testcase_10 AC 118 ms
9,344 KB
testcase_11 AC 114 ms
10,496 KB
testcase_12 AC 70 ms
8,832 KB
testcase_13 AC 20 ms
5,376 KB
testcase_14 AC 101 ms
9,984 KB
testcase_15 AC 27 ms
5,376 KB
testcase_16 AC 90 ms
8,832 KB
testcase_17 AC 71 ms
7,424 KB
testcase_18 AC 67 ms
7,168 KB
testcase_19 AC 87 ms
10,240 KB
testcase_20 AC 62 ms
7,552 KB
testcase_21 AC 54 ms
8,064 KB
testcase_22 AC 99 ms
8,832 KB
testcase_23 AC 11 ms
5,376 KB
testcase_24 AC 78 ms
9,344 KB
testcase_25 AC 99 ms
11,136 KB
testcase_26 AC 59 ms
11,008 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 115 ms
11,136 KB
testcase_29 AC 202 ms
11,136 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