結果

問題 No.315 世界のなんとか3.5
ユーザー is_eri23is_eri23
提出日時 2015-12-08 17:00:57
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 4,323 bytes
コンパイル時間 1,462 ms
コンパイル使用メモリ 160,260 KB
実行使用メモリ 257,024 KB
最終ジャッジ日時 2024-09-14 20:17:03
合計ジャッジ時間 38,553 ms
ジャッジサーバーID
(参考情報)
judge4 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
228,368 KB
testcase_01 AC 148 ms
228,352 KB
testcase_02 AC 201 ms
228,240 KB
testcase_03 AC 108 ms
228,352 KB
testcase_04 AC 92 ms
228,352 KB
testcase_05 AC 93 ms
228,308 KB
testcase_06 AC 89 ms
228,324 KB
testcase_07 AC 90 ms
228,312 KB
testcase_08 AC 91 ms
228,368 KB
testcase_09 AC 90 ms
228,384 KB
testcase_10 AC 91 ms
228,300 KB
testcase_11 AC 92 ms
228,088 KB
testcase_12 AC 679 ms
242,692 KB
testcase_13 AC 686 ms
242,664 KB
testcase_14 AC 1,278 ms
242,648 KB
testcase_15 AC 1,273 ms
242,600 KB
testcase_16 AC 1,259 ms
242,616 KB
testcase_17 AC 1,256 ms
242,616 KB
testcase_18 AC 686 ms
242,728 KB
testcase_19 AC 689 ms
242,560 KB
testcase_20 AC 708 ms
242,580 KB
testcase_21 AC 715 ms
242,640 KB
testcase_22 AC 1,307 ms
242,620 KB
testcase_23 AC 1,318 ms
242,608 KB
testcase_24 AC 1,264 ms
242,744 KB
testcase_25 AC 1,303 ms
242,620 KB
testcase_26 AC 1,259 ms
242,696 KB
testcase_27 AC 1,266 ms
242,620 KB
testcase_28 AC 1,292 ms
242,668 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 MLE -
testcase_34 TLE -
testcase_35 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define mem(x,n) memset(x,n,sizeof(x))
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T,class U> std::ostream& operator<<(std::ostream &os, std::pair<T,U> &p){ os << "(" << p.first <<", " << p.second <<")";return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
using ll = long long;

int memo[200010][8][3][2][2][3];//now, mod8, mod3, in3, under, last2(00,01,10,11) 8->0->0
string S;
string A,B;
int P;
int dp_go(int now, int mod8, int mod3, bool in3, bool under, int last2){
  if (now == sz(S)) {
    if (mod3 == 0 || in3) {
      if (P == 8) {
        return !(mod8 == 0);
      }else if (P == 80) {
        return !(last2 >= 1);
      }else if (P == 800) {
        return !(last2 >= 2);
      }
    }
    return 0;
  }

  if (memo[now][mod8][mod3][in3][under][last2] >= 0) {
    return memo[now][mod8][mod3][in3][under][last2];
  }

  ll ret = 0;
  if (under) {
    for (int i = 0; i <= 9; i++) {
      int tmp = last2;
      if (P == 800 && sz(S) - now == 2) {
        if (mod8 == 0 && i == 0) {
          last2 += 1;
        }
      }else if (sz(S) - now == 1) {
        if (mod8 == 0 && i == 0) {
          last2 += 1;
        }
      }
      if (i != 3) {
        ret += dp_go(now+1, (mod8*10 + i) % 8, (mod3 * 10 + i) % 3, in3, true, last2);
      }else{
        ret += dp_go(now+1, (mod8*10 + i) % 8, (mod3 * 10 + i) % 3, true, true, last2);
      }
      ret %= MOD;
      if (sz(S) - now <= 2) {
        last2 = tmp;
      }
    }
  }else{
    int up = S[now] - '0';
    for (int i = 0; i <= up; i++) {
      int tmp = last2;
      if (P == 800 && sz(S) - now == 2) {
        if (mod8 == 0 && i == 0) {
          last2 += 1;
        }
      }else if (sz(S) - now == 1) {
        if (mod8 == 0 && i == 0) {
          last2 += 1;
        }
      }
      if (i != 3) {
        ret += dp_go(now+1, (mod8*10 + i) % 8, (mod3 * 10 + i) % 3, in3, i < up, last2);
      }else{
        ret += dp_go(now+1, (mod8*10 + i) % 8, (mod3 * 10 + i) % 3, true, i < up, last2);
      }
      ret %= MOD;
      if (sz(S) - now <= 2) {
        last2 = tmp;
      }
    }
  }
  return memo[now][mod8][mod3][in3][under][last2] = (int) ret;
}

void dec(string &a);
int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  mem(memo,-1);
  cin >> A >> B >> P;
  dec(A);
  S = B;
  ll ansB = dp_go(0,0,0,false,false,0);
  mem(memo,-1);
  S = A;
  ll ansA = dp_go(0,0,0,false,false,0);
  //DEBUG2(ansB,ansA);
  cout << (((ansB - ansA) % MOD) + MOD) % MOD << endl;
  return 0;
}
void dec(string &a){
  for (int i = sz(a)-1; i >= 0; i--) {
    if (a[i] == '0') {
      a[i] = '9';
    }else{
      a[i] -= 1;
      break;
    }
  }
}
0