結果
問題 | No.1417 100の倍数かつ正整数(2) |
ユーザー |
![]() |
提出日時 | 2021-02-22 02:02:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 3,000 ms |
コード長 | 6,668 bytes |
コンパイル時間 | 2,278 ms |
コンパイル使用メモリ | 206,296 KB |
最終ジャッジ日時 | 2025-01-19 03:18:52 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
·#include "bits/stdc++.h"using namespace std;using ll=long long; using dd=double;using vll=vector< ll>; using vdd=vector< dd>;using vvll=vector< vll>; using vvdd=vector<vdd>;using vvvll=vector< vvll>; using vvvdd=vector<vvdd>;using vvvvll=vector<vvvll>;using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using qll=tuple<ll,ll,ll,ll>;using vpll=vector< pll>; using vtll=vector< tll>; using vqll=vector< qll>;using vvpll=vector<vpll>; using vvtll=vector<vtll>; using vvqll=vector<vqll>;constexpr ll INF = 1LL << 60;struct Fast{ Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(numeric_limits<double>::max_digits10); } } fast;#define REPS(i, S, E) for (ll i = (S); i <= (E); i++)#define REP(i, N) REPS(i, 0, (N)-1)#define DEPS(i, S, E) for (ll i = (E); i >= (S); i--)#define DEP(i, N) DEPS(i, 0, (N)-1)#define EXPAND( x ) x//VS用おまじない#define overload3(_1,_2,_3,name,...) name#define overload4(_1,_2,_3,_4,name,...) name#define overload5(_1,_2,_3,_4,_5,name,...) name#define rep3(i, S, E) for (ll i = (S); i <= (E); i++)#define rep4(i, S, E, t) for (ll i = (S); i <= (E); i+=(t))#define rep(...) EXPAND(overload4(__VA_ARGS__,rep4,rep3,_,_)(__VA_ARGS__))#define dep3(i, E, S) for (ll i = (E); i >= (S); i--)#define dep4(i, E, S, t) for (ll i = (E); i >= (S); i-=(t))#define dep(...) EXPAND(overload4(__VA_ARGS__, dep4, dep3,_,_)(__VA_ARGS__))#define each2(e,v) for (auto && e:v)#define each3(a,b,v) for (auto &&[a,b]:v)#define each4(a,b,c,v) for (auto &&[a,b,c]:v)#define each5(a,b,c,d,v) for (auto &&[a,b,c,d]:v)#define each(...) EXPAND(overload5(__VA_ARGS__,each5,each4,each3,each2,_)(__VA_ARGS__))#define ALL1(v) (v).begin(), (v).end()#define ALL2(v,E) (v).begin(), (v).begin()+((E)+1)#define ALL3(v,S,E) (v).begin()+(S), (v).begin()+((E)+1)#define ALL(...) EXPAND(overload3(__VA_ARGS__, ALL3, ALL2, ALL1)(__VA_ARGS__))#define RALL1(v) (v).rbegin(), (v).rend()#define RALL2(v,E) (v).rbegin(), (v).rbegin()+((E)+1)#define RALL3(v,S,E) (v).rbegin()+(S), (v).rbegin()+((E)+1)#define RALL(...) EXPAND(overload3(__VA_ARGS__, RALL3, RALL2, RALL1)(__VA_ARGS__))template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }template<class T> inline typename T::value_type maxe(T &v,ll S,ll E){ return *max_element(ALL(v,S,E)); }template<class T> inline typename T::value_type maxe(T &v){ return *max_element(ALL(v)); }template<class T> inline typename T::value_type mine(T &v,ll S,ll E){ return *min_element(ALL(v,S,E)); }template<class T> inline typename T::value_type mine(T &v){ return *min_element(ALL(v)); }template<class T> inline typename T::value_type sum(T &v,ll S,ll E){return accumulate(ALL(v,S,E),T::value_type());}template<class T> inline typename T::value_type sum(T &v){return sum(v,0,v.end()-v.begin()-1);}template<class T> inline ll sz(T &v){ return (ll)v.size(); }inline ll CEIL(ll a,ll b){ return (a<0) ? -(-a/b) : (a+b-1)/b; } //負もOKinline ll FLOOR(ll a,ll b){ return -CEIL(-a,b); } //負もOKtemplate<ll MOD> struct mll_{ll val;mll_(ll v = 0): val(v % MOD){ if (val < 0) val += MOD; }mll_ operator - () const { return -val; }mll_ operator + (const mll_ &b) const { return val + b.val; }mll_ operator - (const mll_ &b) const { return val - b.val; }mll_ operator * (const mll_ &b) const { return val * b.val; }mll_ operator / (const mll_ &b) const { return mll_(*this) /= b; }mll_ operator + (ll b) const { return *this + mll_(b); }mll_ operator - (ll b) const { return *this - mll_(b); }mll_ operator * (ll b) const { return *this * mll_(b); }friend mll_ operator + (ll a,const mll_ &b) { return b + a; }friend mll_ operator - (ll a,const mll_ &b) { return -b + a; }friend mll_ operator * (ll a,const mll_ &b) { return b * a; }friend mll_ operator / (ll a,const mll_ &b) { return mll_(a)/b; }mll_ &operator += (const mll_ &b) { val=(val+b.val)%MOD; return *this; }mll_ &operator -= (const mll_ &b) { val=(val+MOD-b.val)%MOD; return *this; }mll_ &operator *= (const mll_ &b) { val=(val*b.val)%MOD; return *this; }mll_ &operator /= (const mll_ &b) {ll c=b.val,d=MOD,u=1,v=0;while (d){ll t = c / d;c -= t * d; swap(c,d);u -= t * v; swap(u,v);}val = val * u % MOD;if (val < 0) val += MOD;return *this;}mll_ &operator += (ll b) { return *this += mll_(b); }mll_ &operator -= (ll b) { return *this -= mll_(b); }mll_ &operator *= (ll b) { return *this *= mll_(b); }mll_ &operator /= (ll b) { return *this /= mll_(b); }bool operator == (const mll_ &b) const { return val == b.val; }bool operator != (const mll_ &b) const { return val != b.val; }bool operator == (ll b) const { return *this == mll_(b); }bool operator != (ll b) const { return *this != mll_(b); }friend bool operator == (ll a,const mll_ &b) { return mll_(a) == b.val; }friend bool operator != (ll a,const mll_ &b) { return mll_(a) != b.val; }friend ostream &operator << (ostream &os,const mll_ &a) { return os << a.val; }friend istream &operator >> (istream &is,mll_ &a) { return is >> a.val; }static mll_ Combination(ll a,ll b){chmin(b,a-b);if (b<0) return mll_(0);mll_ c = 1;rep(i,0,b-1) c *= a-i;rep(i,0,b-1) c /= i+1;return c;}};using mll = mll_<1000000007LL>;//using mll = mll_<998244353LL>;using vmll = std::vector<mll>;using vvmll = std::vector<vmll>;using vvvmll = std::vector<vvmll>;using vvvvmll = std::vector<vvvmll>;void solve(){string n;cin >> n;ll M=(ll)n.size();ll S=2,X=3,Y=3;vvvvmll dp_(M+1,vvvmll(S,vvmll(X,vmll(Y))));auto dp = [&](ll i,ll s,ll x,ll y)->mll&{static mll dmy=0;return dp_[i+1][s][min(x,X-1)][min(y,Y-1)];};dp(-1,1,0,0)=1;vll nm2{0,0,1,0,2,0,1,0,3,0};vll nm5{0,0,0,0,0,1,0,0,0,0};for (ll i=-1; i<=M-2; i++){for (ll s=0; s<S; s++){for (ll x=0; x<X; x++){for (ll y=0; y<Y; y++){ll nn=(ll)(n[i+1]-'0');for (ll p=1; p<=(s==1?nn:9); p++){dp(i+1, s==1&&nn==p, x+nm2[p], y+nm5[p]) += dp(i,s,x,y);}}}}//上からi+1桁目から始まるものif (i>=0){for (ll p=1; p<=9; p++){dp(i+1,0,nm2[p],nm5[p]) += 1;}}}cout << dp(M-1,1,2,2)+dp(M-1,0,2,2) << '\n';return;}int main(){#if 1solve();#elsell t; cin >> t;rep(i, 0, t-1){solve();}#endifreturn 0;}