結果

問題 No.260 世界のなんとか3
ユーザー tossytossy
提出日時 2017-01-01 19:36:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,687 bytes
コンパイル時間 811 ms
コンパイル使用メモリ 90,164 KB
実行使用メモリ 11,220 KB
最終ジャッジ日時 2023-08-22 09:13:36
合計ジャッジ時間 3,625 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,048 KB
testcase_01 AC 6 ms
10,844 KB
testcase_02 AC 6 ms
10,852 KB
testcase_03 WA -
testcase_04 AC 64 ms
11,056 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 21 ms
10,868 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 31 ms
11,008 KB
testcase_13 WA -
testcase_14 AC 44 ms
10,888 KB
testcase_15 AC 16 ms
10,864 KB
testcase_16 AC 38 ms
10,880 KB
testcase_17 WA -
testcase_18 AC 31 ms
11,084 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 34 ms
10,872 KB
testcase_25 AC 43 ms
10,952 KB
testcase_26 AC 26 ms
11,080 KB
testcase_27 AC 6 ms
10,904 KB
testcase_28 WA -
testcase_29 AC 81 ms
10,944 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){
  fill(dp[0][0][0][0], dp[10001][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){
    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;
}

bool count(string &s){
  int n = s.size();
  int acc=0;
  rep(i,n) acc = (acc*10+s[i]-'0')%8;
  if(acc%8==0) return false;

  bool ok=false;
  rep(i,n) if(s[i]=='3')ok=true;
  acc=0;
  rep(i,n) acc = (acc*10+s[i]-'0')%3;
  if(acc%3==0) ok=true;
  return ok;
}

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

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

  return 0;
}
0