結果

問題 No.260 世界のなんとか3
ユーザー nominomi
提出日時 2019-02-16 17:12:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,747 bytes
コンパイル時間 1,748 ms
コンパイル使用メモリ 172,636 KB
実行使用メモリ 18,752 KB
最終ジャッジ日時 2023-10-23 20:58:47
合計ジャッジ時間 5,395 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 127 ms
18,740 KB
testcase_04 AC 128 ms
18,740 KB
testcase_05 AC 60 ms
9,212 KB
testcase_06 AC 39 ms
7,236 KB
testcase_07 AC 122 ms
16,496 KB
testcase_08 AC 140 ms
16,736 KB
testcase_09 AC 69 ms
10,128 KB
testcase_10 AC 101 ms
15,244 KB
testcase_11 AC 132 ms
17,440 KB
testcase_12 AC 108 ms
14,168 KB
testcase_13 AC 20 ms
5,692 KB
testcase_14 AC 124 ms
16,612 KB
testcase_15 AC 26 ms
6,456 KB
testcase_16 AC 98 ms
14,092 KB
testcase_17 AC 70 ms
11,408 KB
testcase_18 AC 60 ms
10,468 KB
testcase_19 AC 131 ms
16,592 KB
testcase_20 AC 79 ms
11,760 KB
testcase_21 AC 93 ms
12,572 KB
testcase_22 AC 97 ms
14,468 KB
testcase_23 AC 10 ms
4,640 KB
testcase_24 AC 120 ms
15,504 KB
testcase_25 AC 202 ms
18,752 KB
testcase_26 AC 122 ms
18,752 KB
testcase_27 AC 1 ms
4,372 KB
testcase_28 AC 122 ms
18,740 KB
testcase_29 AC 121 ms
18,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))

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];

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

  // DPテーブルを初期化
  dp[0][0][0][0][0][0] = 1;
  // DP
  for (int digit = 0; digit < B.size(); digit++) {
    for (int over : {0, 1}) {
      for (int less : {0, 1}) {
        for (int three : {0, 1}) {
          for (int mod3 = 0; mod3 < 3; mod3++) {
            for (int mod8 = 0; mod8 < 8; mod8++) {
              int ue = (less ? 9 : B[digit] - '0');
              int shita = (over ? 0 : A[digit] - '0');
              for (int num = shita; num <= ue; num++) {
                Add(dp[digit+1][over || (num > shita)][less || (num < ue)][three || (num == 3)][(mod3+num)%3][(10*mod8+num)%8],
                dp[digit][over][less][three][mod3][mod8]);
              }
            }
          }
        }
      }
    }
  }

  // 総和を求める
  int ans = 0;
  for (int over : {0, 1}) {
    for (int less : {0, 1}) {
      for (int three : {0, 1}) {
        for (int mod3 = 0; mod3 < 3; mod3++) {
          for (int mod8 = 0; mod8 < 8; mod8++) {
            if ((three || mod3 == 0) && (mod8 != 0)) {
              Add(ans, dp[B.size()][over][less][three][mod3][mod8]);
            }
          }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}
0