結果

問題 No.260 世界のなんとか3
ユーザー beetbeet
提出日時 2018-12-05 14:59:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 2,114 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 201,148 KB
実行使用メモリ 12,468 KB
最終ジャッジ日時 2023-09-26 06:55:23
合計ジャッジ時間 4,680 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,932 KB
testcase_01 AC 5 ms
11,064 KB
testcase_02 AC 5 ms
10,984 KB
testcase_03 AC 58 ms
12,236 KB
testcase_04 AC 60 ms
12,264 KB
testcase_05 AC 24 ms
11,392 KB
testcase_06 AC 18 ms
11,276 KB
testcase_07 AC 50 ms
12,088 KB
testcase_08 AC 51 ms
12,056 KB
testcase_09 AC 27 ms
11,512 KB
testcase_10 AC 47 ms
11,904 KB
testcase_11 AC 53 ms
12,112 KB
testcase_12 AC 41 ms
11,948 KB
testcase_13 AC 12 ms
11,104 KB
testcase_14 AC 51 ms
12,300 KB
testcase_15 AC 15 ms
11,224 KB
testcase_16 AC 42 ms
11,808 KB
testcase_17 AC 31 ms
11,584 KB
testcase_18 AC 29 ms
11,516 KB
testcase_19 AC 49 ms
12,028 KB
testcase_20 AC 34 ms
11,660 KB
testcase_21 AC 35 ms
11,764 KB
testcase_22 AC 43 ms
11,976 KB
testcase_23 AC 8 ms
11,052 KB
testcase_24 AC 46 ms
11,924 KB
testcase_25 AC 54 ms
12,220 KB
testcase_26 AC 55 ms
12,204 KB
testcase_27 AC 5 ms
11,064 KB
testcase_28 AC 57 ms
12,468 KB
testcase_29 AC 57 ms
12,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }
  
  Mint inv(){return pow(MOD-2);}
  
  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}
  
  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-(){return v?MOD-v:v;}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

};
//INSERT ABOVE HERE
using M = Mint<int>;
const int MAX = 1e4 + 100;
M dp[2][2][3][8][MAX];
int used[2][2][3][8][MAX];
M dfs(string &s,int i,int t,int a,int x,int y){
  M &res=dp[t][a][x][y][i];
  if(i==0) return res=(a||(x==0))&&(y!=0);
  if(!t&&used[t][a][x][y][i]) return res;
  used[t][a][x][y][i]=1;
  res=M(0);
  for(int k=0;k<=(t?s[i-1]-'0':9);k++)
    res+=dfs(s,i-1,t&&(k==s[i-1]-'0'),a||(k==3),(x*10+k)%3,(y*10+k)%8);
  return res;
}

signed main(){
  string a,b;
  cin>>a>>b;
  reverse(a.begin(),a.end());
  reverse(b.begin(),b.end());
  M ans;
  memset(used,0,sizeof(used));
  ans+=dfs(b,b.size(),1,0,0,0);
  ans-=dfs(a,a.size(),1,0,0,0);
  
  reverse(a.begin(),a.end());
  int flg=0,m3=0,m8=0;
  for(int i=0;i<(int)a.size();i++){
    flg|=a[i]=='3';
    m3=(m3*10+(a[i]-'0'))%3;
    m8=(m8*10+(a[i]-'0'))%8;
  }
  if((flg||(m3==0))&&(m8!=0)) ans+=M(1);
  cout<<ans.v<<endl;
  return 0;
}
0