結果

問題 No.260 世界のなんとか3
ユーザー aim_cpoaim_cpo
提出日時 2017-09-11 01:41:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,152 bytes
コンパイル時間 984 ms
コンパイル使用メモリ 94,968 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-25 03:15:51
合計ジャッジ時間 4,021 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_04 AC 162 ms
11,008 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 43 ms
6,656 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 69 ms
8,704 KB
testcase_13 WA -
testcase_14 AC 103 ms
9,984 KB
testcase_15 AC 28 ms
5,376 KB
testcase_16 AC 94 ms
8,832 KB
testcase_17 WA -
testcase_18 AC 67 ms
6,912 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 77 ms
9,344 KB
testcase_25 AC 100 ms
10,880 KB
testcase_26 AC 62 ms
11,136 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 158 ms
11,008 KB
testcase_29 AC 191 ms
10,880 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<3;j++){
      for(int k=1;k<8;k++){
        (res+=dp[n][i][1][j][k])%=MOD;
      }
    }
  }
  for(int i=0;i<2;i++){
    for(int j=1;j<8;j++){
      (res+=dp[n][i][0][0][j])%=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[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-ansa<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}
0