結果

問題 No.372 It's automatic
ユーザー ei1333333ei1333333
提出日時 2016-05-13 22:41:26
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 613 bytes
コンパイル時間 1,379 ms
コンパイル使用メモリ 166,748 KB
実行使用メモリ 13,752 KB
最終ジャッジ日時 2024-04-15 16:37:10
合計ジャッジ時間 8,887 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,752 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 TLE -
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 #

#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;



string S;
int M;
map< pair< int, int >, int > dp;

inline int rec(int idx, int value)
{
  if(dp.find({idx, value}) != dp.end()) return(dp[{idx, value}]);
  if(idx == S.size()) return(value == 0);
  return(dp[{idx, value}] = rec(idx + 1, (value * 10 + S[idx]) % M) + rec(idx + 1, value) % mod);
}

int main()
{
  
  cin >> S;
  for(int i = 0; i < S.size(); i++) S[i] -= '0';
  cin >> M;
  int ret = 0;
  for(int i = 0; i < S.size(); i++) {
    if(S[i] == 0) ++ret;
    else (ret += rec(i + 1, S[i] % M)) %= mod;
  }
  cout << ret << endl;
}
0