結果

問題 No.315 世界のなんとか3.5
ユーザー motimoti
提出日時 2015-12-14 18:59:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,998 bytes
コンパイル時間 1,843 ms
コンパイル使用メモリ 104,476 KB
実行使用メモリ 195,388 KB
最終ジャッジ日時 2023-10-13 16:40:41
合計ジャッジ時間 13,727 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
59,620 KB
testcase_01 AC 24 ms
59,760 KB
testcase_02 AC 23 ms
59,868 KB
testcase_03 AC 23 ms
59,692 KB
testcase_04 AC 23 ms
59,640 KB
testcase_05 AC 23 ms
59,768 KB
testcase_06 AC 23 ms
59,828 KB
testcase_07 AC 22 ms
59,660 KB
testcase_08 AC 23 ms
59,608 KB
testcase_09 AC 23 ms
59,616 KB
testcase_10 AC 25 ms
59,692 KB
testcase_11 AC 22 ms
59,644 KB
testcase_12 AC 150 ms
92,684 KB
testcase_13 AC 146 ms
92,612 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 163 ms
93,548 KB
testcase_19 AC 160 ms
93,364 KB
testcase_20 AC 978 ms
162,392 KB
testcase_21 AC 945 ms
162,460 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 1,093 ms
195,388 KB
testcase_34 AC 660 ms
160,524 KB
testcase_35 AC 675 ms
160,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define minimize(a, x) a = std::min(a, x)
#define maximize(a, x) a = std::max(a, x)

typedef long long ll;
int const inf = 1<<29;

int P;
int nA, nB;

int const MOD = 1e9+7;

vector<ll> dp[200010][2][3][2];
int ssize;

string S;
bool isA;

int func(int index = 0, bool giri = true, int mod3 = 0, bool used3 = false, int modP = 0) {
  if(index >= ssize) {
    if(giri && isA) { return 0; }
    return ((mod3 == 0) || used3) && modP;
  }

  if(ssize - index > P+1) { if(dp[index][giri][mod3][used3].empty()) dp[index][giri][mod3][used3].resize(1, -1); }
  else { if(dp[index][giri][mod3][used3].empty()) dp[index][giri][mod3][used3].resize(P+1, -1); }

  auto& ret = dp[index][giri][mod3][used3][modP];

  if(ret + 1) { return ret; }

  ret = 0;

  int digit = S[index] - '0';
  int mx = giri ? digit + 1 : 10;
  rep(i, mx) {
    ret += func(index + 1, giri && (i == digit), (mod3 * 10 + i) % 3, used3 || (i == 3), ssize - index - 1 > P+1 ? 0 : ((modP * 10 + i) % P));
    if(ret >= MOD) ret -= MOD;
  }

  return ret;
}

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

  S = B; ssize = S.size(); isA = false;
  rep(i, 10010) rep(j, 2) rep(k, 3) rep(l, 2) dp[i][j][k][l].clear();
  int ans = func();

  rep(i, 10010) rep(j, 2) rep(k, 3) rep(l, 2) dp[i][j][k][l].clear();
  S = A; ssize = S.size(); isA = true;
  ans -= func();

  ans += MOD; if(ans >= MOD) ans -= MOD;
  cout << ans << endl;

  return 0;
}
0