結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー snow39
提出日時 2021-03-05 21:43:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 3,000 ms
コード長 1,274 bytes
コンパイル時間 974 ms
コンパイル使用メモリ 104,708 KB
最終ジャッジ日時 2025-01-19 10:48:37
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

const int MAX=1e5;
ll dp[MAX+10][3][3][2];

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;
  cin>>S;
  int N=S.size();

  dp[0][0][0][0]=1;
  for(int i=0;i<N;i++){
    rep(j,3) rep(k,3) rep(m,2){
      ll value=dp[i][j][k][m];
      if(value==0) continue;

      int lim=9;
      if(m==0) lim=S[i]-'0';
      for(int d=1;d<=lim;d++){
        int nj=j,nk=k,nm=m;
        if(d==2||d==6) nj=min(2,j+1);
        if(d==4||d==8) nj=2;
        if(d==5) nk=min(2,k+1);
        if(m==0&&d<lim) nm=1;
        add(dp[i+1][nj][nk][nm],value);
      }
    }
    if(i+1<N) add(dp[i+1][0][0][1],1);
  }

  ll ans=0;
  rep(m,2) add(ans,dp[N][2][2][m]);
  cout<<ans<<endl;

  return 0;
}
0