結果

問題 No.315 世界のなんとか3.5
ユーザー tossytossy
提出日時 2017-01-01 21:51:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,109 bytes
コンパイル時間 901 ms
コンパイル使用メモリ 91,156 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 09:23:46
合計ジャッジ時間 27,719 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1,093 ms
4,380 KB
testcase_17 AC 1,095 ms
4,380 KB
testcase_18 AC 554 ms
4,376 KB
testcase_19 AC 556 ms
4,380 KB
testcase_20 AC 553 ms
4,380 KB
testcase_21 AC 553 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 1,091 ms
4,380 KB
testcase_24 AC 1,091 ms
4,376 KB
testcase_25 WA -
testcase_26 AC 1,094 ms
4,380 KB
testcase_27 WA -
testcase_28 AC 1,071 ms
4,380 KB
testcase_29 AC 1,853 ms
4,376 KB
testcase_30 AC 1,850 ms
4,380 KB
testcase_31 WA -
testcase_32 TLE -
testcase_33 AC 1,103 ms
4,376 KB
testcase_34 AC 1,522 ms
4,376 KB
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

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[2][2][2][3][8];
// [-][EQ?][3を使った][mod3][mod8]

// 数値,trueなら8の倍数だけ,falseなら,sとイコールを含めるか
long solve(string &s, bool onlyeight=true, bool eq=true){
  int n = s.size();

  auto prev = dp[0];
  auto crnt = dp[1];
  fill(prev[0][0][0], prev[2][0][0], 0);
  prev[1][0][0][0] = 1;

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

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

int main(){
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  string a,b;
  int p;
  cin>>a>>b>>p;

  if(p==8){
    cout << (solve(b,true,true) - solve(a,true,false) + MOD)%MOD << endl;
    return 0;
  }

  long ans = solve(b,false,true) - solve(a,false,false);
  int r=0;
  if(p==80) r=1;
  else if(p==800) r=2;
  if(p>=80){
    if(a.size()<=r) a="1";
    else a.resize(a.size()-r);
    if(b.size()<=r) b="1";
    else b.resize(b.size()-r);
  }
  ans = ans - (solve(b,true,true) - solve(a,true,false));
  cout << (ans+5LL*MOD)%MOD << endl;

  return 0;
}
0