結果

問題 No.315 世界のなんとか3.5
ユーザー krotonkroton
提出日時 2015-09-20 20:43:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,454 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 54,992 KB
実行使用メモリ 91,760 KB
最終ジャッジ日時 2023-09-26 14:06:29
合計ジャッジ時間 28,101 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
78,380 KB
testcase_01 AC 38 ms
78,592 KB
testcase_02 AC 37 ms
78,360 KB
testcase_03 AC 38 ms
78,368 KB
testcase_04 AC 37 ms
78,372 KB
testcase_05 AC 37 ms
78,512 KB
testcase_06 AC 38 ms
78,504 KB
testcase_07 AC 37 ms
78,336 KB
testcase_08 AC 37 ms
78,380 KB
testcase_09 AC 37 ms
78,360 KB
testcase_10 AC 37 ms
78,380 KB
testcase_11 AC 37 ms
78,364 KB
testcase_12 AC 655 ms
91,048 KB
testcase_13 AC 634 ms
91,064 KB
testcase_14 AC 1,230 ms
90,988 KB
testcase_15 AC 1,248 ms
91,000 KB
testcase_16 AC 1,237 ms
91,012 KB
testcase_17 AC 1,236 ms
90,968 KB
testcase_18 AC 648 ms
91,116 KB
testcase_19 AC 650 ms
91,144 KB
testcase_20 AC 649 ms
91,012 KB
testcase_21 AC 647 ms
90,996 KB
testcase_22 AC 1,239 ms
91,112 KB
testcase_23 AC 1,243 ms
90,992 KB
testcase_24 AC 1,243 ms
90,992 KB
testcase_25 AC 1,238 ms
91,064 KB
testcase_26 AC 1,247 ms
91,120 KB
testcase_27 AC 1,231 ms
91,268 KB
testcase_28 AC 1,168 ms
91,096 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1,133 ms
91,592 KB
testcase_35 AC 1,172 ms
91,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

string dig;
int border;
bool allowEqual;

int dp[100010][3][8][2][2][2];
int solve(int k, int mod3, int mod8, bool has3, bool less, bool suf0){
  if(k >= dig.size()){
    if(!less && !allowEqual){
      return 0;
    }
    int aho = (mod3 == 0) || has3;
    int haji = (mod8 == 0) && suf0;
    return aho && !haji;
  }
  if(dp[k][mod3][mod8][has3][less][suf0] != -1){
    return dp[k][mod3][mod8][has3][less][suf0];
  }
  int res = 0;
  for(int i=0;i<10;i++){
    int d = dig[k] - '0';
    if(less || i <= d){
      bool nsuf0 = suf0;
      int nmod8 = mod8;
      if(k >= border){
        nsuf0 &= i == 0;
      } else {
        nmod8 = (nmod8 * 10 + i) % 8;
      }
      res += solve(k + 1, (mod3 * 10 + i) % 3, nmod8, has3 || (i == 3), less || (i < d), nsuf0);
      if(res >= MOD){
        res -= MOD;
      }
    }
  }
  return dp[k][mod3][mod8][has3][less][suf0] = res;
}

int solve(string s, int p, bool eq){
  dig = s;
  border = dig.size() - p;
  allowEqual = eq;
  memset(dp, -1, sizeof(dp));
  return solve(0, 0, 0, false, false, true);
}

int main(){
  string A, B;
  cin >> A >> B;

  int P;
  cin >> P;

  int p = 0;
  while(P > 0){
    ++p;
    P /= 10;
  }

  int resA = solve(A, p - 1, false);
  int resB = solve(B, p - 1, true);

  int res = resB - resA;
  if(res < 0){
    res += MOD;
  }

  cout << res << endl;
  return 0;
}
0