結果
問題 |
No.372 It's automatic
|
ユーザー |
![]() |
提出日時 | 2016-05-13 23:57:42 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2,829 ms / 6,000 ms |
コード長 | 948 bytes |
コンパイル時間 | 144 ms |
コンパイル使用メモリ | 24,576 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-05 18:42:31 |
合計ジャッジ時間 | 35,182 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
コンパイルメッセージ
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); | ~~~~~~~~~~^~~~~~~~~~
ソースコード
#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; }