結果
| 問題 |
No.372 It's automatic
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-05-13 23:53:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 987 ms / 6,000 ms |
| コード長 | 2,701 bytes |
| コンパイル時間 | 1,677 ms |
| コンパイル使用メモリ | 168,092 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 00:38:29 |
| 合計ジャッジ時間 | 14,352 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define rt return
#define FOR(i,j,k) for(int i=j; i<(int)k;++i)
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<long long MOD>
class ModInt{
public:
ModInt():value(0){}
ModInt(long long val):value(val<0?MOD+val%MOD:val%MOD){ }
ModInt& operator+=(ModInt that){
value = value+that.value;
if(value>=MOD)value-=MOD;
return *this;
}
ModInt& operator-=(ModInt that){
value -= that.value;
if(value<0)value+=MOD;
return *this;
}
ModInt& operator*=(ModInt that){
value = value * that.value % MOD;
return *this;
}
ModInt &operator/=(ModInt that){
return *this *= that.inverse();
}
ModInt operator+(ModInt that) const{
return ModInt(*this)+=that;
}
ModInt operator-(ModInt that) const{
return ModInt(*this)-=that;
}
ModInt operator*(ModInt that) const{
return ModInt(*this)*=that;
}
ModInt operator/(ModInt that) const {
return ModInt(*this) /= that;
}
ModInt operator^(long long k) const{
ModInt n = *this, res = 1;
while(k){
if(k & 1)res *= n;
n *= n;
k >>= 1;
}
return res;
}
ModInt inverse() const {
long long a = value, b = MOD, u = 1, v = 0;
while(b) {
long long t = a / b;
a -= t * b; std::swap(a, b);
u -= t * v; std::swap(u, v);
}
return ModInt(u);
}
long long toll() const{ return value; }
int toi() const{ return (int)value; }
private:
long long value;
};
typedef ModInt<1000000007ll> mint;
mint dp[2][20000];
string S;
int M;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
while(cin >> S >> M){
mint ans = count(all(S), '0');
each(c, S)c -= '0';
rep(i, M)dp[0][i] = 0;
// reverse(all(S));
rep(i, sz(S)){
int cur = i & 1, nex = 1 - cur;
rep(j, M)dp[nex][j] = 0;
rep(j, M){
dp[nex][j] += dp[cur][j];
int nj = (j * 10 + S[i]) % M;
dp[nex][nj] += dp[cur][j];
}
if(S[i]!=0)dp[nex][S[i] % M] += 1;
}
ans += dp[sz(S) & 1][0];
cout << ans.toi() << endl;
}
}