結果

問題 No.372 It's automatic
ユーザー yuppe19 😺yuppe19 😺
提出日時 2016-05-16 08:48:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,010 ms / 6,000 ms
コード長 966 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 58,200 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 22:19:35
合計ジャッジ時間 26,513 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1,995 ms
5,376 KB
testcase_05 AC 2,002 ms
5,376 KB
testcase_06 AC 2,006 ms
5,376 KB
testcase_07 AC 2,007 ms
5,376 KB
testcase_08 AC 2,003 ms
5,376 KB
testcase_09 AC 1,999 ms
5,376 KB
testcase_10 AC 2,001 ms
5,376 KB
testcase_11 AC 1,986 ms
5,376 KB
testcase_12 AC 2,010 ms
5,376 KB
testcase_13 AC 1,985 ms
5,376 KB
testcase_14 AC 2,002 ms
5,376 KB
testcase_15 AC 2,009 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 189 ms
5,376 KB
testcase_22 AC 188 ms
5,376 KB
testcase_23 AC 188 ms
5,376 KB
testcase_24 AC 186 ms
5,376 KB
testcase_25 AC 188 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

const int mod = 1000000007;

int dp[2][3][20005];

int main(void) {
  string s; int m; cin >> s >> m;
  int n = s.size();
  dp[0][0][0] = 1;
  for(int i=0; i<n; ++i) {
    memset(dp[(i+1)&1], 0, sizeof(dp[(i+1)&1]));
    for(int md=0; md<m; ++md) {
      for(int state=0; state<3; ++state) {
        if(dp[i&1][state][md] == 0) { continue; }
        int d   = s[i] - '0',
            nmd = (md * 10 + d) % m;
        dp[(i+1)&1][state][md] += dp[i&1][state][md];
        dp[(i+1)&1][state][md] %= mod;
        if((state == 0 && d) || state == 2) {
          dp[(i+1)&1][2][nmd] += dp[i&1][state][md];
          dp[(i+1)&1][2][nmd] %= mod;
        } else if(state == 0 && !d) {
          dp[(i+1)&1][1][nmd] += dp[i&1][state][md];
          dp[(i+1)&1][1][nmd] %= mod;
        }
      }
    }
  }
  int res = (dp[n&1][1][0] + dp[n&1][2][0]) % mod;
  printf("%d\n", res);
  return 0;
}
0