結果

問題 No.372 It's automatic
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2016-05-14 17:57:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,687 ms / 6,000 ms
コード長 801 bytes
コンパイル時間 1,613 ms
コンパイル使用メモリ 164,960 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-19 08:17:38
合計ジャッジ時間 35,155 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2,667 ms
6,940 KB
testcase_05 AC 2,676 ms
6,944 KB
testcase_06 AC 2,658 ms
6,944 KB
testcase_07 AC 2,676 ms
6,940 KB
testcase_08 AC 2,673 ms
6,940 KB
testcase_09 AC 2,665 ms
6,944 KB
testcase_10 AC 2,667 ms
6,948 KB
testcase_11 AC 2,648 ms
6,944 KB
testcase_12 AC 2,687 ms
6,940 KB
testcase_13 AC 2,658 ms
6,944 KB
testcase_14 AC 2,682 ms
6,944 KB
testcase_15 AC 2,683 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 133 ms
6,940 KB
testcase_22 AC 135 ms
6,940 KB
testcase_23 AC 133 ms
6,944 KB
testcase_24 AC 133 ms
6,940 KB
testcase_25 AC 134 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007LL
typedef long long ll;

string S;
int M;

// dp[ditis][mod M][used]
ll dp[2][20101][2];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> S >> M;

	int N = S.length();

	rep(j, 0, M) rep(k, 0, 2) dp[0][j][k] = 0;
	dp[0][0][0] = 1;

	ll zero = 0;
	rep(i1, 0, N)
	{
		int ii1 = i1 + 1;

		int c = S[i1] - '0';
		if (c == 0) zero++;

		rep(i2, 0, M) rep(i3, 0, 2) dp[ii1 % 2][i2][i3] = 0;

		rep(i2, 0, M) rep(i3, 0, 2)
		{
			(dp[ii1 % 2][i2][i3] += dp[i1 % 2][i2][i3]) %= MOD;

			if (i3 || c != 0)
			{
				int ii2 = (i2 * 10 + c) % M;
				int ii3 = 1;

				(dp[ii1 % 2][ii2][ii3] += dp[i1 % 2][i2][i3]) %= MOD;
			}
		}
	}

	cout << (dp[N % 2][0][1] + zero) % MOD << endl;
}
0