結果

問題 No.260 世界のなんとか3
ユーザー pekempeypekempey
提出日時 2017-12-20 23:38:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 1,387 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 73,216 KB
実行使用メモリ 9,328 KB
最終ジャッジ日時 2023-08-22 11:06:06
合計ジャッジ時間 4,379 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,920 KB
testcase_01 AC 5 ms
8,976 KB
testcase_02 AC 5 ms
9,024 KB
testcase_03 AC 144 ms
9,236 KB
testcase_04 AC 144 ms
9,052 KB
testcase_05 AC 31 ms
9,036 KB
testcase_06 AC 23 ms
9,004 KB
testcase_07 AC 99 ms
9,184 KB
testcase_08 AC 70 ms
9,028 KB
testcase_09 AC 41 ms
9,000 KB
testcase_10 AC 112 ms
9,028 KB
testcase_11 AC 105 ms
9,088 KB
testcase_12 AC 65 ms
9,072 KB
testcase_13 AC 22 ms
8,928 KB
testcase_14 AC 95 ms
9,328 KB
testcase_15 AC 29 ms
8,976 KB
testcase_16 AC 84 ms
9,144 KB
testcase_17 AC 67 ms
9,188 KB
testcase_18 AC 65 ms
9,088 KB
testcase_19 AC 83 ms
9,300 KB
testcase_20 AC 60 ms
8,964 KB
testcase_21 AC 54 ms
9,056 KB
testcase_22 AC 95 ms
9,040 KB
testcase_23 AC 14 ms
8,964 KB
testcase_24 AC 75 ms
9,176 KB
testcase_25 AC 70 ms
9,028 KB
testcase_26 AC 79 ms
9,124 KB
testcase_27 AC 5 ms
8,952 KB
testcase_28 AC 153 ms
9,064 KB
testcase_29 AC 134 ms
9,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

const int mod = 1e9 + 7;

// Ordering monoid
int mul(int x, int y) {
  return x == 0 ? y : x;
}

int ordering(int x, int y) {
  if (x < y) return 1;
  if (x > y) return 2;
  return 0;
}

void to(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}

int f(string a, bool le = true) {
  const int n = a.size();
  static int dp[10001][24][2][3]; // pos, mod, has3, eq/lt/gt

  memset(dp, 0, sizeof(dp));
  
  dp[n][0][0][0] = 1;

  vector<int> pow10(n);
  pow10[0] = 1;
  for (int i = 0; i + 1 < n; i++) {
    pow10[i + 1] = 10 * pow10[i] % 24;
  }

  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 24; j++) {
      for (int k = 0; k < 2; k++) {
        for (int l = 0; l < 3; l++) {
          for (int d = 0; d < 10; d++) {
            to(dp[i][(j + pow10[n - 1 - i] * d) % 24][k || d == 3][mul(ordering(d, a[i] - '0'), l)], dp[i + 1][j][k][l]);
          }
        }
      }
    }
  }

  int ans = 0;
  for (int j = 0; j < 24; j++) {
    if (j % 8 == 0) continue;
    for (int k = 0; k < 2; k++) {
      if (k || j % 3 == 0) {
        if (le) {
          to(ans, dp[0][j][k][0]);
        }
        to(ans, dp[0][j][k][1]);
      }
    }
  }
  return ans;
}

int main() {
  string a;
  string b;
  cin >> a >> b;

  cout << (f(b, true) - f(a, false) + mod) % mod << endl;
}
0