結果

問題 No.372 It's automatic
ユーザー しらっ亭しらっ亭
提出日時 2016-05-13 23:31:01
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,100 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 158,288 KB
実行使用メモリ 791,260 KB
最終ジャッジ日時 2024-04-15 17:10:50
合計ジャッジ時間 12,118 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// TLE するだろうなぁ...
#include <bits/stdc++.h>
using namespace std;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FORR(x,arr) for(auto&& x:arr)
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
typedef long long ll;
// -------------------------------------

const long long mod = 1000000007;

string S;
int M;
int N;

int dp[10000][20000];

int calc(int p) {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  REP(i, N-p) REP(j, M) {
    int d = S[p+i] - '0';
    (dp[i+1][(j * 10 + d) % M] += dp[i][j]) %= mod;
    (dp[i+1][j] += dp[i][j]) %= mod;
  }
  return dp[N-p][0];
}

void Main() {
  cin >> S >> M;

  N = SZ(S);
  int ans = calc(0);

  REP(i, N) {
    if (S[i] == '0') {
      ans = (ans - calc(i+1) + mod) % mod;
    }
  }
  _P("%d\n", ans);
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }
0