結果

問題 No.372 It's automatic
ユーザー uafr_csuafr_cs
提出日時 2016-05-13 23:57:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,864 ms / 6,000 ms
コード長 948 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 26,412 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-28 08:16:39
合計ジャッジ時間 36,527 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2,832 ms
4,380 KB
testcase_05 AC 2,861 ms
4,376 KB
testcase_06 AC 2,840 ms
4,380 KB
testcase_07 AC 2,854 ms
4,380 KB
testcase_08 AC 2,859 ms
4,380 KB
testcase_09 AC 2,850 ms
4,380 KB
testcase_10 AC 2,850 ms
4,380 KB
testcase_11 AC 2,827 ms
4,376 KB
testcase_12 AC 2,861 ms
4,380 KB
testcase_13 AC 2,829 ms
4,376 KB
testcase_14 AC 2,864 ms
4,376 KB
testcase_15 AC 2,864 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 144 ms
4,380 KB
testcase_22 AC 146 ms
4,384 KB
testcase_23 AC 144 ms
4,376 KB
testcase_24 AC 144 ms
4,376 KB
testcase_25 AC 144 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>

#define MOD 1000000007L

#define S_MAX 10000
#define M_MAX 20000

char S[S_MAX + 1];

long long int mods[M_MAX + 1];
long long int next[M_MAX + 1];

int main(int argc, char* argv[]){
	long long int M = 0;

	std::scanf("%s", S);
	std::scanf("%d", &M);

	long long int zero_count = 0;
	mods[0] = 1;
	
	for(int pos = 0; S[pos] != '\0'; pos++){
		const int cur_num = S[pos] - '0';

		for(int i = 0; i <= M; i++){
			next[i] = 0;
		}

		if(cur_num == 0){ zero_count++; }
		
		for(long long int mod = (cur_num != 0 ? 0 : 1); mod <= M; mod++){
			if(mods[mod] == 0){ continue; }

			const long long int next_mod = (mod * 10 + cur_num) % M;
			if(next_mod != 0){
				next[next_mod] += mods[mod];
				next[next_mod] %= MOD;
			}else{
				next[M] += mods[mod];
				next[M] %= MOD;
			}
		}

		for(int i = 0; i <= M; i++){
			mods[i] += next[i];
			mods[i] %= MOD;
		}
	}

	std::printf("%lld\n", (mods[M] + zero_count) % MOD);
	return 0;
}
0