結果

問題 No.260 世界のなんとか3
ユーザー nominomi
提出日時 2019-02-16 16:31:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 2,824 bytes
コンパイル時間 1,573 ms
コンパイル使用メモリ 170,708 KB
実行使用メモリ 21,928 KB
最終ジャッジ日時 2023-10-23 19:42:13
合計ジャッジ時間 4,250 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
20,316 KB
testcase_01 AC 7 ms
20,312 KB
testcase_02 AC 7 ms
20,316 KB
testcase_03 AC 73 ms
21,908 KB
testcase_04 AC 76 ms
21,908 KB
testcase_05 AC 31 ms
20,908 KB
testcase_06 AC 23 ms
20,696 KB
testcase_07 AC 65 ms
21,680 KB
testcase_08 AC 65 ms
21,716 KB
testcase_09 AC 35 ms
21,008 KB
testcase_10 AC 60 ms
21,540 KB
testcase_11 AC 69 ms
21,780 KB
testcase_12 AC 54 ms
21,432 KB
testcase_13 AC 15 ms
20,524 KB
testcase_14 AC 64 ms
21,692 KB
testcase_15 AC 19 ms
20,604 KB
testcase_16 AC 53 ms
21,420 KB
testcase_17 AC 42 ms
21,132 KB
testcase_18 AC 38 ms
21,036 KB
testcase_19 AC 66 ms
21,692 KB
testcase_20 AC 43 ms
21,172 KB
testcase_21 AC 46 ms
21,264 KB
testcase_22 AC 55 ms
21,460 KB
testcase_23 AC 11 ms
20,412 KB
testcase_24 AC 59 ms
21,580 KB
testcase_25 AC 74 ms
21,924 KB
testcase_26 AC 72 ms
21,928 KB
testcase_27 AC 7 ms
20,260 KB
testcase_28 AC 9 ms
21,912 KB
testcase_29 AC 9 ms
21,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

// ------------------------------------------------------------------------------------------

string A, B;
int dp[11111][2][2][2][3][8];
int a[111];

int rec(int digit, int over, int smaller, int three, int mod3, int mod8) {
  if (digit >= B.size()) {
    return (three || mod3 == 0) && (mod8 != 0);
  }

  if (dp[digit][over][smaller][three][mod3][mod8] != -1) {
    return dp[digit][over][smaller][three][mod3][mod8];
  }

  int ue = (smaller ? 9 : B[digit] - '0');
  int shita = (over ? 0 : A[digit] - '0');

  int ret = 0;
  for (int num = shita; num <= ue; num++) {
    int t = rec(digit+1, over || (num > shita), smaller || (num < ue), three || (num == 3), (mod3+num)%3, (10*mod8+num)%8);
    Add(ret, t);
  }

  return dp[digit][over][smaller][three][mod3][mod8] = ret;
}

signed main() {
  cin >> A >> B;
  int diff = B.size() - A.size();
  string zero = "";
  rep (i, diff) {
    zero += "0";
  }
  A = zero + A;

  rep (i, 11111) rep (j, 2) rep (k, 2) rep (l, 2) rep (m, 3) rep (n, 8) dp[i][j][k][l][m][n] = -1;

  int ans = rec(0, 0, 0, 0, 0, 0);
  cout << ans << endl;

  return 0;
}
0