結果

問題 No.315 世界のなんとか3.5
ユーザー koyumeishikoyumeishi
提出日時 2015-09-21 23:47:16
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,573 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 54,704 KB
実行使用メモリ 179,328 KB
最終ジャッジ日時 2023-09-26 14:18:01
合計ジャッジ時間 36,843 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
153,444 KB
testcase_01 AC 62 ms
153,568 KB
testcase_02 AC 100 ms
153,400 KB
testcase_03 AC 62 ms
153,404 KB
testcase_04 AC 62 ms
153,352 KB
testcase_05 AC 62 ms
153,568 KB
testcase_06 AC 62 ms
153,500 KB
testcase_07 AC 62 ms
153,440 KB
testcase_08 AC 63 ms
153,392 KB
testcase_09 AC 62 ms
153,332 KB
testcase_10 AC 62 ms
153,400 KB
testcase_11 AC 62 ms
153,348 KB
testcase_12 AC 717 ms
165,932 KB
testcase_13 AC 675 ms
166,068 KB
testcase_14 AC 1,273 ms
166,068 KB
testcase_15 AC 1,280 ms
166,064 KB
testcase_16 AC 1,276 ms
166,016 KB
testcase_17 AC 1,273 ms
166,132 KB
testcase_18 AC 679 ms
166,032 KB
testcase_19 AC 678 ms
166,200 KB
testcase_20 AC 679 ms
165,992 KB
testcase_21 AC 680 ms
166,000 KB
testcase_22 AC 1,271 ms
166,256 KB
testcase_23 AC 1,303 ms
166,028 KB
testcase_24 AC 1,280 ms
166,172 KB
testcase_25 AC 1,280 ms
166,220 KB
testcase_26 AC 1,278 ms
166,140 KB
testcase_27 AC 1,273 ms
166,044 KB
testcase_28 AC 1,219 ms
166,116 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 AC 1,300 ms
178,876 KB
testcase_34 TLE -
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

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[200010][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