結果

問題 No.260 世界のなんとか3
ユーザー legosukelegosuke
提出日時 2018-01-01 20:37:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,096 bytes
コンパイル時間 2,361 ms
コンパイル使用メモリ 146,776 KB
実行使用メモリ 11,204 KB
最終ジャッジ日時 2023-08-24 15:43:12
合計ジャッジ時間 5,114 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,820 KB
testcase_01 AC 5 ms
10,980 KB
testcase_02 AC 5 ms
10,904 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 5 ms
10,888 KB
testcase_28 AC 45 ms
10,928 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;
string a, b;
ll dp[10010][2][2][3][8];
ll lessA = 0;

ll calc(string s) {
  int sz = s.size();
  fill(dp[0][0][0][0], dp[10010][0][0][0], 0);
  dp[0][0][0][0][0] = 1;
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        for (int l = 0; l < 3; l++) {
          for (int m = 0; m < 8; m++) {
            int D = s[i] - '0';
            for (int d = 0; d <= (j ? 9 : D); d++) {
              dp[i + 1][j || (d < D)][k || (d == 3)][(l + d) % 3][(m * 10 + d) % 8] += dp[i][j][k][l][m];
            }
          }
        }
      }
    }
  }

  ll res = 0;
  for (int j = 0; j < 2; j++) {
    if (s == a && j == 0) continue;
    for (int k = 0; k < 2; k++) {
      for (int l = 0; l < 3; l++) {
        for (int m = 0; m < 8; m++) {
          if ((k || !l) && m) {
            (res += dp[sz][j][k][l][m]) %= mod;
          }
        }
      }
    }
  }
  return res;
}

int main() {
  cin >> a >> b;
  cout << calc(b) - calc(a) << endl;

  return 0;
}
0