結果

問題 No.372 It's automatic
ユーザー togatogatogatoga
提出日時 2016-05-13 23:23:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,416 ms / 6,000 ms
コード長 1,292 bytes
コンパイル時間 1,451 ms
コンパイル使用メモリ 159,344 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 16:59:43
合計ジャッジ時間 19,442 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1,398 ms
6,940 KB
testcase_05 AC 1,406 ms
6,944 KB
testcase_06 AC 1,402 ms
6,944 KB
testcase_07 AC 1,409 ms
6,944 KB
testcase_08 AC 1,416 ms
6,940 KB
testcase_09 AC 1,404 ms
6,940 KB
testcase_10 AC 1,402 ms
6,944 KB
testcase_11 AC 1,397 ms
6,944 KB
testcase_12 AC 1,409 ms
6,944 KB
testcase_13 AC 1,396 ms
6,940 KB
testcase_14 AC 1,408 ms
6,944 KB
testcase_15 AC 1,410 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 73 ms
6,944 KB
testcase_22 AC 74 ms
6,940 KB
testcase_23 AC 73 ms
6,940 KB
testcase_24 AC 73 ms
6,940 KB
testcase_25 AC 73 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define mp       make_pair
#define mt	 make_tuple
#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    pair<int,int>      pii;
typedef    pair<long,long>    pll;

const int INF=1<<29;
const double EPS=1e-9;
const int MOD = 1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int MAX_M = 20010;
string S;
int M;
int dp[2][2][MAX_M];
int main(){
  cin >> S;
  cin >> M;
  memset(dp, 0, sizeof(dp));
  dp[0][0][0] = 1;
  
  for (int i = 0; i < S.size(); i++){

    for (int l = 0; l < 2; l++){
      for (int j = 0; j < M; j++){
	if (dp[i % 2][l][j] == 0)continue;
	dp[(i + 1) % 2][l][j] += dp[i % 2][l][j];
	dp[(i + 1) % 2][l][j] %= MOD;
	
	if (l == 0 and (S[i] - '0') == 0){
	  continue;
	}
	int k = (j * 10 + (S[i] - '0')) % M;
	dp[(i + 1) % 2][1][k % M] += dp[i % 2][l][j];
	dp[(i + 1) % 2][1][k % M] %= MOD;

      }
    }

    
    int now = i % 2;

    for (int k = 0; k < 2; k++){
      for (int j = 0; j < M; j++){
	dp[now][k][j] = 0;
      }
    }

  }
  int result = 0;
  result = dp[S.size() % 2][1][0];
  for (const auto &val : S){
    if (val == '0'){
      result++;
      result %= MOD;
    }
  }

  cout << result << endl;
}
0