結果

問題 No.372 It's automatic
ユーザー parukiparuki
提出日時 2016-05-13 23:53:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 983 ms / 6,000 ms
コード長 2,701 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 166,364 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-01 08:33:36
合計ジャッジ時間 14,501 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 973 ms
4,380 KB
testcase_05 AC 976 ms
4,380 KB
testcase_06 AC 972 ms
4,376 KB
testcase_07 AC 977 ms
4,376 KB
testcase_08 AC 983 ms
4,376 KB
testcase_09 AC 978 ms
4,376 KB
testcase_10 AC 977 ms
4,376 KB
testcase_11 AC 971 ms
4,380 KB
testcase_12 AC 979 ms
4,380 KB
testcase_13 AC 971 ms
4,380 KB
testcase_14 AC 979 ms
4,376 KB
testcase_15 AC 981 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 47 ms
4,376 KB
testcase_22 AC 47 ms
4,376 KB
testcase_23 AC 47 ms
4,376 KB
testcase_24 AC 47 ms
4,376 KB
testcase_25 AC 46 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0