結果
| 問題 | No.372 It's automatic |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-05-16 08:48:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,995 ms / 6,000 ms |
| コード長 | 966 bytes |
| 記録 | |
| コンパイル時間 | 411 ms |
| コンパイル使用メモリ | 59,764 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-06 04:19:14 |
| 合計ジャッジ時間 | 25,960 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int mod = 1000000007;
int dp[2][3][20005];
int main(void) {
string s; int m; cin >> s >> m;
int n = s.size();
dp[0][0][0] = 1;
for(int i=0; i<n; ++i) {
memset(dp[(i+1)&1], 0, sizeof(dp[(i+1)&1]));
for(int md=0; md<m; ++md) {
for(int state=0; state<3; ++state) {
if(dp[i&1][state][md] == 0) { continue; }
int d = s[i] - '0',
nmd = (md * 10 + d) % m;
dp[(i+1)&1][state][md] += dp[i&1][state][md];
dp[(i+1)&1][state][md] %= mod;
if((state == 0 && d) || state == 2) {
dp[(i+1)&1][2][nmd] += dp[i&1][state][md];
dp[(i+1)&1][2][nmd] %= mod;
} else if(state == 0 && !d) {
dp[(i+1)&1][1][nmd] += dp[i&1][state][md];
dp[(i+1)&1][1][nmd] %= mod;
}
}
}
}
int res = (dp[n&1][1][0] + dp[n&1][2][0]) % mod;
printf("%d\n", res);
return 0;
}