結果

問題 No.372 It's automatic
ユーザー uafr_csuafr_cs
提出日時 2016-05-13 23:57:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,832 ms / 6,000 ms
コード長 948 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 24,576 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 17:30:36
合計ジャッジ時間 35,988 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2,790 ms
5,376 KB
testcase_05 AC 2,826 ms
5,376 KB
testcase_06 AC 2,816 ms
5,376 KB
testcase_07 AC 2,832 ms
5,376 KB
testcase_08 AC 2,762 ms
5,376 KB
testcase_09 AC 2,781 ms
5,376 KB
testcase_10 AC 2,816 ms
5,376 KB
testcase_11 AC 2,789 ms
5,376 KB
testcase_12 AC 2,787 ms
5,376 KB
testcase_13 AC 2,825 ms
5,376 KB
testcase_14 AC 2,779 ms
5,376 KB
testcase_15 AC 2,801 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 0 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 0 ms
5,376 KB
testcase_20 AC 0 ms
5,376 KB
testcase_21 AC 138 ms
5,376 KB
testcase_22 AC 138 ms
5,376 KB
testcase_23 AC 142 ms
5,376 KB
testcase_24 AC 141 ms
5,376 KB
testcase_25 AC 142 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:17:22: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
   17 |         std::scanf("%d", &M);
      |                     ~^   ~~
      |                      |   |
      |                      |   long long int*
      |                      int*
      |                     %lld
main.cpp:16:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         std::scanf("%s", S);
      |         ~~~~~~~~~~^~~~~~~~~
main.cpp:17:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |         std::scanf("%d", &M);
      |         ~~~~~~~~~~^~~~~~~~~~

ソースコード

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