結果
| 問題 | No.372 It's automatic |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-01 13:30:22 |
| 言語 | C++17(gcc12) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 338 ms / 6,000 ms |
| コード長 | 1,422 bytes |
| 記録 | |
| コンパイル時間 | 847 ms |
| コンパイル使用メモリ | 110,392 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-08 21:45:35 |
| 合計ジャッジ時間 | 5,426 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <cstring>
static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
os << "{";
for (int i = 0; i < v.size(); ++i) {
if(i) os << ", ";
os << v[i];
}
return os << "}";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
return os << "{" << p.first << ", " << p.second << "}";
}
int dp[2][20000];
int main() {
string s;
int n, m;
cin >> s >> m;
n = s.size();
fill_n(*dp, 40000, 0);
dp[0][0] = 1;
int a = 0;
int x = 10%m;
for (int i = 0; i < n; ++i) {
int now = i&1, nxt = now^1;
memcpy(dp[nxt], dp[now], sizeof(dp[now]));
int to = (s[i]-'0')%m;
if(s[i] == '0') {
dp[nxt][0] = (dp[nxt][0] == 0 ? MOD-1 : dp[nxt][0]-1);
a++;
}
for (int j = 0; j < m; ++j, to += x) {
while (to >= m) to -= m;
dp[nxt][to] += dp[now][j];
if(dp[nxt][to] >= MOD) dp[nxt][to] -= MOD;
}
}
cout << (dp[n&1][0]+a+MOD-1)%MOD << "\n";
return 0;
}