結果

問題 No.260 世界のなんとか3
ユーザー nenuonnenuon
提出日時 2017-07-22 16:38:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,328 bytes
コンパイル時間 902 ms
コンパイル使用メモリ 85,200 KB
実行使用メモリ 11,900 KB
最終ジャッジ日時 2023-07-30 14:47:47
合計ジャッジ時間 4,678 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 150 ms
11,520 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 40 ms
7,400 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 66 ms
9,556 KB
testcase_13 WA -
testcase_14 AC 99 ms
11,704 KB
testcase_15 AC 27 ms
4,832 KB
testcase_16 AC 87 ms
9,572 KB
testcase_17 WA -
testcase_18 AC 66 ms
7,456 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 77 ms
9,564 KB
testcase_25 AC 99 ms
11,556 KB
testcase_26 AC 57 ms
11,564 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 108 ms
11,704 KB
testcase_29 AC 190 ms
11,628 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 << endl;
  return 0;
}
0