結果

問題 No.260 世界のなんとか3
ユーザー motimoti
提出日時 2015-12-09 01:21:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 3,801 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 102,708 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-04-25 07:49:58
合計ジャッジ時間 3,940 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
10,880 KB
testcase_01 AC 8 ms
10,880 KB
testcase_02 AC 8 ms
10,880 KB
testcase_03 AC 160 ms
12,032 KB
testcase_04 AC 161 ms
11,948 KB
testcase_05 AC 38 ms
11,392 KB
testcase_06 AC 27 ms
11,136 KB
testcase_07 AC 112 ms
11,776 KB
testcase_08 AC 80 ms
11,776 KB
testcase_09 AC 49 ms
11,264 KB
testcase_10 AC 125 ms
11,776 KB
testcase_11 AC 116 ms
11,904 KB
testcase_12 AC 72 ms
11,648 KB
testcase_13 AC 27 ms
11,008 KB
testcase_14 AC 112 ms
11,904 KB
testcase_15 AC 33 ms
10,880 KB
testcase_16 AC 92 ms
11,776 KB
testcase_17 AC 73 ms
11,392 KB
testcase_18 AC 76 ms
11,264 KB
testcase_19 AC 96 ms
11,904 KB
testcase_20 AC 68 ms
11,392 KB
testcase_21 AC 60 ms
11,392 KB
testcase_22 AC 109 ms
11,648 KB
testcase_23 AC 17 ms
10,880 KB
testcase_24 AC 87 ms
11,776 KB
testcase_25 AC 88 ms
12,032 KB
testcase_26 AC 84 ms
12,032 KB
testcase_27 AC 8 ms
11,008 KB
testcase_28 AC 155 ms
12,032 KB
testcase_29 AC 163 ms
12,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define minimize(a, x) a = std::min(a, x)
#define maximize(a, x) a = std::max(a, x)

typedef long long ll;
int const inf = 1<<29;

int P;
int nA, nB;

template<class value_type, int MOD>
class ModInt {
private:
  value_type val_;
  static value_type mod_pow(value_type x, value_type n, value_type mo) { value_type ret = 1; while(n > 0) { if(n & 1) { ret = ret * x % mo; } x = x * x % mo; n >>= 1; } return ret; }

public:

  ModInt() { val_ = 0; }
  ModInt(value_type x) { val_ = (x % MOD + MOD) % MOD; }

  ModInt const operator + (ModInt const& rhs) const {
    return std::move(ModInt(val_+rhs.get()));
  }

  ModInt const operator - (ModInt const& rhs) const {
    return std::move(ModInt(val_-rhs.get()));
  }

  ModInt const operator * (ModInt const& rhs) const {
    return std::move(ModInt(val_*rhs.get()));
  }

  ModInt const operator / (ModInt const& rhs) const {
    return std::move(ModInt(val_*mod_pow(rhs.get(), MOD-2, MOD)));  // fermat theorem
  }

  friend ModInt const operator + (value_type lhs, ModInt const& rhs) {
    return std::move(ModInt(lhs+rhs.get()));
  }

  friend ModInt const operator - (value_type lhs, ModInt const& rhs) {
    return std::move(ModInt(lhs-rhs.get()));
  }

  friend ModInt const operator * (value_type lhs, ModInt const& rhs) {
    return std::move(ModInt(lhs*rhs.get()));
  }

  friend ModInt const operator / (value_type lhs, ModInt const& rhs) {
    return std::move(ModInt(lhs*mod_pow(rhs.get(), MOD-2, MOD)));  // fermat theorem
  }

  ModInt operator += (ModInt const& rhs) {
    return *this = ModInt(val_+rhs.get()).get();
  }

  ModInt operator -= (ModInt const& rhs) {
    return *this = ModInt(val_-rhs.get()).get();
  }

  ModInt operator *= (ModInt const& rhs) {
    return *this = ModInt(val_*rhs.get()).get();
  }

  ModInt operator /= (ModInt const& rhs) {
    return *this = ModInt(val_*mod_pow(rhs.get(), MOD-2, MOD)).get();
  }

  bool operator == (ModInt const& rhs) const {
    return val_ == rhs.get();
  }

  value_type const get() const { return val_; }
  value_type &     get() { return val_; }

  friend ostream& operator << (ostream& ost, ModInt const& x) { 
    return ost << x.get();
  }

  friend istream& operator >> (istream& ist, ModInt& x) { 
    string s; ist >> s;
    int size = s.size();
    x.get() = 0;
    rep(i, size) {
      x.get() *= 10;
      x.get() += s[i]-'0';
      x.get() %= MOD;
    }
    return ist;
  }
};

typedef ModInt<long long, 1000000007> mint;

mint dp[10010][2][24][2];
int ssize;

string S;
bool isA;

mint func(int index = 0, bool giri = true, int mod24 = 0, bool used3 = false) {
  if(index >= ssize) {
    if(giri && isA) { return 0; }
    return ((mod24 % 3 == 0) || used3) && (mod24 % 8);
  }

  auto& ret = dp[index][giri][mod24][used3];

  if(ret.get() + 1) { return ret; }

  ret = 0;

  int digit = S[index] - '0';
  int mx = giri ? digit + 1 : 10;
  rep(i, mx) {
    ret += func(index + 1, giri && (i == digit), (mod24 * 10 + i) % 24, used3 || (i == 3));
  }

  return ret;
}

int main() {
  string A, B; cin >> A >> B;
  S = B; ssize = S.size(); isA = false; minus(dp);
  mint ans = func();
  S = A; ssize = S.size(); isA = true; minus(dp);
  ans -= func();
  cout << ans << endl;
}
0