結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー logxlogx
提出日時 2021-03-05 22:50:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 3,000 ms
コード長 8,854 bytes
コンパイル時間 2,454 ms
コンパイル使用メモリ 208,132 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-04-16 10:38:04
合計ジャッジ時間 3,698 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 7 ms
5,376 KB
testcase_34 AC 12 ms
7,040 KB
testcase_35 AC 12 ms
7,296 KB
testcase_36 AC 12 ms
7,296 KB
testcase_37 AC 13 ms
7,168 KB
testcase_38 AC 11 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;

/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = s; i < (int)(n); ++i)
#define Clear(a) a = decltype(a)()
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
#define bit(i,j) (((i)>>(j))&1)

/*---------type/const---------*/
typedef long long ll;
typedef unsigned long long ull;
typedef string::const_iterator state; //構文解析
const ll big=1000000007;
//const ll big=998244353;
const double PI=acos(-1);
const double EPS=1e-8;//適宜変える
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-1;}
    constexpr operator ll(){return -ll(1e18)-1;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+1;}
    constexpr operator ll(){return ll(1e18)+1;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug用関数---------*/
#ifdef LOGX
#define dbg(x) cout << #x << ':',prt(x);
template<typename T> inline void prt(T a_);
template<typename T> inline void _prt(T a_);
template<typename A,typename B> inline void _prt(map<A,B> a_);
template<typename A,typename B> inline void _prt(unordered_map<A,B> a_);
template<typename T> inline void _prt(set<T> a_);
template<typename T> inline void _prt(unordered_set<T> a_);
template<typename A,typename B> inline void _prt(pair<A,B> a_);
template<typename T> inline void _prt(vector<T> &a_);
template<typename T> inline void _prt(vector<vector<T>> &a_);
//_prtでは改行しない.
inline void _prt(bool a_){if(a_)cout<<1;else cout<<0;}
inline void _prt(int a_){if(a_>=(int)inf)cout << "inf";else if(a_<=-(int)inf)cout << "-inf";else cout << a_;}
inline void _prt(long long a_){if(a_>=(ll)inf)cout << "INF";else if(a_<=-(ll)inf)cout << "-INF";else cout << a_;}
#ifdef ATCODER_MODINT_HPP
template<int MOD>inline void _prt(static_modint<MOD> x){cout << x.val();}
template<int MOD>inline void _prt(dynamic_modint<MOD> x){cout << x.val();}
#endif
template<typename T> inline void _prt(T a_){cout << a_;}
template<typename A,typename B>
inline void _prt(map<A,B> a_){cout<<'{';auto it=a_.begin();while(it!=a_.end()){_prt((*it).first);cout<<':';_prt((*(it++)).second);cout<<(it==a_.end() ? "":",");}cout<<'}';}
template<typename A,typename B>
inline void _prt(unordered_map<A,B> a_){cout<<'{';auto it=a_.begin();while(it!=a_.end()){_prt((*it).first);cout<<':';_prt((*(it++)).second);cout<<(it==a_.end() ? "":",");}cout<<'}';}
template<typename T>
inline void _prt(set<T> a_){cout<<'{';auto it=a_.begin();while(it!=a_.end()){_prt(*it++);cout<<(it==a_.end() ? "":",");}cout<<'}';}
template<typename T>
inline void _prt(unordered_set<T> a_){cout<<'{';auto it=a_.begin();while(it!=a_.end()){_prt(*it++);cout<<(it==a_.end() ? "":",");}cout<<'}';}
template<typename A,typename B>
inline void _prt(pair<A,B> a_){cout << '(';_prt(a_.first);cout << ',';_prt(a_.second);cout << ')';}
template<typename T>
inline void _prt(vector<T> &a_){cout<<'{';for(int i=0;i<(int)a_.size();i++){_prt(a_[i]);if(i+1<(int)a_.size())cout<<',';}cout<<'}';}
template<typename T>
inline void _prt(vector<vector<T>> &a_){cout<<"{\n";for(int i=0;i<(int)a_.size();i++){_prt(a_[i]);if(i+1<(int)a_.size())cout<<",\n";else cout<<"\n}";}}
template<typename T> inline void prt(T a_){_prt(a_);cout<<'\n';}
#else
#define dbg(x) ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T,typename U> T max(const T x,const U y){if(x>y)return x;else return y;}
template<typename T,typename U> T min(const T x,const U y){if(x<y)return x;else return y;}
template<typename T> T max(const vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
template<typename T,typename U>
T expm(T x,U y,const ll mod=big){
    T res=1;
    while(y){
        if(y&1)(res*=x)%=mod;
        (x*=x)%=mod;
        y>>=1;
    }
    return res;
}
template<typename T,typename U>
T exp(T x,U y){
    T res=1;
    while(y){
        if(y&1)res*=x;
        x*=x;
        y>>=1;
    }
    return res;
}

/*
実行時modint:
template<int &mod>
struct Fp{};
int main(){
    static int mod;cin >> mod;
    using mint = Fp<mod>;
}
*/
template<int mod>
struct Fp{
    long long x;
    constexpr Fp(const long long _x=0)noexcept:x((_x%mod+mod)%mod){}
    constexpr Fp operator-()const noexcept{
        return x ? mod-x:0;
    }
    friend constexpr Fp<mod>& operator+=(Fp<mod> &l,const Fp<mod> r)noexcept{
        l.x+=r.x;
        if(l.x>=mod)l.x-=mod;
        return l;
    }
    friend constexpr Fp<mod>& operator-=(Fp<mod> &l,const Fp<mod> r)noexcept{
        l.x-=r.x;
        if(l.x<0)l.x+=mod;
        return l;
    }
    //modが十分小さい場合
    friend constexpr Fp<mod>& operator*=(Fp<mod> &l,const Fp<mod> r)noexcept{
        l.x=l.x*r.x %mod;
        return l;
    }
    //modが巨大な場合
    /*
    friend constexpr Fp<mod> prod(Fp<mod> l,long long r)noexcept{
        if(r==0)return 0;
        Fp<mod> res=prod(l+=l,r>>1);
        if(r&1)res+=l;
        return res;
    }
    friend constexpr Fp<mod>& operator*=(Fp<mod> &l,const Fp<mod> r)noexcept{
        return l=prod(l,r.x);
    }
    */
    
    friend constexpr Fp<mod>& operator/=(Fp<mod> &l,const Fp<mod> r)noexcept{
        long long a=r.x,b=mod,u=1,v=0;
        while(b){
            ll t=a/b;
            a-=t*b;swap(a,b);
            u-=t*v;swap(u,v);
        }
        l.x=l.x*u%mod;
        if(l.x<0)l.x+=mod;
        return l;
    }
    friend constexpr Fp<mod> operator+(Fp<mod> l,const Fp<mod> r){
        return l+=r;
    }
    friend constexpr Fp<mod> operator-(Fp<mod> l,const Fp<mod> r){
        return l-=r;
    }
    friend constexpr Fp<mod> operator*(Fp<mod> l,const Fp<mod> r){
        return l*=r;
    }
    friend constexpr Fp<mod> operator/(Fp <mod> l,const Fp<mod> r){
        return l/=r;
    }
    #ifdef LOGX
    friend constexpr bool operator==(const Fp<mod> l,const Fp<mod> r){
        return l.x==r.x;
    }
    friend constexpr bool operator!=(const Fp<mod> l,const Fp<mod> r){
        return l.x!=r.x;
    }
    #endif
    friend constexpr ostream& operator<<(ostream &os,const Fp<mod> &r)noexcept{
        return os << r.x;
    }
    friend constexpr istream& operator>>(istream &is,Fp<mod> &r)noexcept{
        ll t=0;is >> t;
        r.x=(Fp<mod>(t)).x;
        return is;
    }
};


using mint = Fp<big>;////////////////////////////


template<typename T,typename U>
mint com(const T a,const U b){
    if(a<b || b<0 || a<0)return 0;
    mint res=1;
    for(int i=0;i<b;i++){
        res*=mint(a-i)/(i+1);
    }
    return res;
}

vector<mint> fac,facinv;
void init(const int n_){
    fac.resize(n_,1);
    facinv.resize(n_,1);
    fac[0]=facinv[0]=1;
    for(int i=1;i<n_;i++){
        fac[i]=fac[i-1]*i;
        facinv[i]=facinv[i-1]/i;
    }
    return;
}
template<typename T,typename U>
mint coms(T a,U b){
    if(a<b || b<0 || a<0)return 0;
    return fac[a]*facinv[b]*facinv[a-b];
}

pair<int,int> val(int x){
    if(x==0)return {2,2};
    int t=0;
    while(x%2==0){
        x/=2;
        t++;
    }
    int f=0;
    while(x%5==0){
        x/=5;
        f++;
    }
    return {min(t,2),min(f,2)};
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout.precision(10);
    /*--------------------------------*/
    
    string s;cin >> s;
    vector ans(s.size(),vector(3,vector<mint>(3)));//ちょうど.
    auto ans2=ans;//小さい.
    rep2(i,1,s[0]-'0'){
        auto [x,y]=val(i);
        ans2[0][x][y]+=1;
    }

    auto [x,y]=val(s[0]-'0');
    ans[0][x][y]=1;

    rep(i,s.size()-1){
        //0からの遷移.
        rep2(j,1,10){
            auto[x,y]=val(j);
            ans2[i+1][x][y]+=1;
        }
        //0以外からの遷移.
        //ansから.
        rep2(j,1,s[i+1]-'0'){
            auto[x,y]=val(j);
            rep(k,3)rep(l,3){
                ans2[i+1][min(k+x,2)][min(l+y,2)]+=ans[i][k][l];
            }
        }
        if(s[i+1]!='0'){
            int j=s[i+1]-'0';
            auto[x,y]=val(j);
            rep(k,3)rep(l,3){
                ans[i+1][min(k+x,2)][min(l+y,2)]+=ans[i][k][l];
            }
        }
        //ans2から.
        rep2(j,1,10){
            auto[x,y]=val(j);
            rep(k,3)rep(l,3){
                ans2[i+1][min(k+x,2)][min(l+y,2)]+=ans2[i][k][l];
            }
        }
    }
    dbg(ans);
    dbg(ans2);
    cout << ans.back().back().back()+ans2.back().back().back() << newl;
}
0