結果
| 問題 |
No.372 It's automatic
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-05-14 16:32:11 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 883 bytes |
| コンパイル時間 | 759 ms |
| コンパイル使用メモリ | 66,844 KB |
| 実行使用メモリ | 814,336 KB |
| 最終ジャッジ日時 | 2024-10-06 02:38:51 |
| 合計ジャッジ時間 | 2,293 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | WA * 1 MLE * 1 -- * 21 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
const int MOD = 1e9 + 7;
void show(vector<vector<long long>> &vv) {
for (auto v : vv) {
for (auto e : v) {
printf("%3lld ", e);
}
cout << endl;
}
}
int main() {
int m;
string s;
cin >> s >> m;
int n = s.size();
vector<vector<long long>> dp(n + 1, vector<long long>(m, 0));
vector<long long> dp1(m, 0), dp2(m, 0);
int n_zero = 0;
for (int i = 0; i < n; i++) {
int num = s[i] - '0';
if (num == 0) {
n_zero++;
} else {
dp[i + 1][num % m] += 1;
}
for (int j = 0; j < m; j++) {
dp[i + 1][(dp[i][j] * 10 + num) % m] += dp[i][j];
dp[i + 1][dp[i][j] * 10 % m] += dp[i][j];
}
}
// show(dp);
// printf("zero %d\n", n_zero);
long long ans = (dp[n][0] + n_zero) % MOD;
cout << ans << endl;
return 0;
}