結果

問題 No.260 世界のなんとか3
ユーザー aim_cpoaim_cpo
提出日時 2017-09-11 12:20:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 2,162 bytes
コンパイル時間 901 ms
コンパイル使用メモリ 93,344 KB
実行使用メモリ 11,096 KB
最終ジャッジ日時 2023-08-07 12:53:54
合計ジャッジ時間 4,537 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 157 ms
10,952 KB
testcase_04 AC 156 ms
10,936 KB
testcase_05 AC 32 ms
6,176 KB
testcase_06 AC 22 ms
5,160 KB
testcase_07 AC 108 ms
9,788 KB
testcase_08 AC 77 ms
9,892 KB
testcase_09 AC 42 ms
6,724 KB
testcase_10 AC 120 ms
9,208 KB
testcase_11 AC 113 ms
10,264 KB
testcase_12 AC 70 ms
8,632 KB
testcase_13 AC 21 ms
4,444 KB
testcase_14 AC 103 ms
9,840 KB
testcase_15 AC 28 ms
4,756 KB
testcase_16 AC 90 ms
8,592 KB
testcase_17 AC 71 ms
7,316 KB
testcase_18 AC 69 ms
6,788 KB
testcase_19 AC 91 ms
10,128 KB
testcase_20 AC 64 ms
7,560 KB
testcase_21 AC 57 ms
7,948 KB
testcase_22 AC 102 ms
8,780 KB
testcase_23 AC 11 ms
4,376 KB
testcase_24 AC 80 ms
9,356 KB
testcase_25 AC 104 ms
10,924 KB
testcase_26 AC 62 ms
10,976 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 156 ms
10,980 KB
testcase_29 AC 199 ms
11,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
//fill((int*)d, (int*)(d + lengthof(d)), -1);
using namespace std;

string a,b;
const ll MOD=(ll)1e9+7;
ll dp[10010][2][2][3][8];

inline ll solve(string s){
  int n=(int)s.length();
  dp[0][0][0][0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<2;k++){
        for(int l=0;l<3;l++){
          for(int m=0;m<8;m++){
            int lim=j?9:s[i]-'0';
            for(int d=0;d<lim+1;d++){
              (dp[i+1][j || d<lim][k || d==3][(l*10+d)%3][(m*10+d)%8]+=dp[i][j][k][l][m])%=MOD;
            }
          }
        }
      }
    }
  }
  ll res=0;
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<3;k++){
        for(int l=0;l<8;l++){
          if((j || k==0) && l!=0)
          (res+=dp[n][i][j][k][l])%=MOD;
        }
      }
    }
  }
  return res;
}

inline string min1(string s){
  for(int i=s.length()-1;i>=0;i--){
    if(s[i]-'0'-1<0){
      s[i]='9';
    }else{
      s[i]-=1;
      break;
    }
  }
  for(int i=0;i<(int)s.length();i++){
    if(s=="0")break;
    if(s[i]=='0')s=s.substr(1,s.length()-1);
    else break;
  }
  return s;
}
            
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>a>>b;
  ll ans=solve(b);
  for(int i=0;i<(int)a.length()+5;i++){
    for(int j=0;j<2;j++)for(int k=0;k<2;k++)for(int l=0;l<3;l++)for(int m=0;m<8;m++)dp[i][j][k][l][m]=0;
  }
  //cout<<ans<<"\n";
  string aa=min1(a);
  //cout<<aa<<endl;
  ll ansa=solve(aa);
  //cout<<ansa<<"\n";
  cout<<(ans+MOD-ansa)%MOD<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}
0