結果

問題 No.260 世界のなんとか3
ユーザー pionepione
提出日時 2020-05-25 05:47:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 2,526 bytes
コンパイル時間 1,682 ms
コンパイル使用メモリ 167,092 KB
実行使用メモリ 11,180 KB
最終ジャッジ日時 2024-04-21 03:31:33
合計ジャッジ時間 3,855 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,076 KB
testcase_01 AC 7 ms
11,008 KB
testcase_02 AC 6 ms
10,828 KB
testcase_03 AC 82 ms
10,860 KB
testcase_04 AC 78 ms
11,180 KB
testcase_05 AC 19 ms
10,968 KB
testcase_06 AC 15 ms
11,072 KB
testcase_07 AC 56 ms
10,996 KB
testcase_08 AC 43 ms
11,036 KB
testcase_09 AC 26 ms
11,032 KB
testcase_10 AC 62 ms
11,068 KB
testcase_11 AC 60 ms
11,100 KB
testcase_12 AC 39 ms
11,080 KB
testcase_13 AC 14 ms
11,144 KB
testcase_14 AC 54 ms
10,904 KB
testcase_15 AC 19 ms
11,064 KB
testcase_16 AC 49 ms
11,140 KB
testcase_17 AC 42 ms
11,004 KB
testcase_18 AC 39 ms
11,160 KB
testcase_19 AC 52 ms
11,072 KB
testcase_20 AC 38 ms
11,008 KB
testcase_21 AC 33 ms
11,076 KB
testcase_22 AC 58 ms
11,164 KB
testcase_23 AC 11 ms
11,032 KB
testcase_24 AC 46 ms
11,100 KB
testcase_25 AC 49 ms
10,868 KB
testcase_26 AC 42 ms
11,004 KB
testcase_27 AC 6 ms
11,120 KB
testcase_28 AC 81 ms
10,892 KB
testcase_29 AC 90 ms
11,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using tll = tuple<ll,ll,ll>;
using vtll = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;


ll dp[10005][2][2][3][8]; // pos, isLess, has3, mod3, mod8

ll f(string s){
  ll n=s.size();
  memset(dp,0,sizeof(dp));
  dp[0][0][0][0][0]=1;
  rep(i,n) rep(j,2) rep(k,2) rep(l,3) rep(m,8){
    ll now=s[i]-'0';
    rep(nxt,10){
      if(nxt>now && j==0) continue;
      ll nj=j,nk=k,nl,nm;
      if(nxt<now) nj=1;
      if(nxt==3) nk=1;
      nl=(l*10+nxt)%3;
      nm=(m*10+nxt)%8;
      (dp[i+1][nj][nk][nl][nm]+=dp[i][j][k][l][m])%=MOD;
    }
  }
  ll ans=0;
  rep(j,2) rep(k,2) rep(l,3) rep(m,8){
    if((k==1||l==0)&&m!=0) (ans+=dp[n][j][k][l][m])%=MOD;
  }
  return ans;
}

string decdec(string A) {
	reverse(A.begin(),A.end());
	for(auto &r: A) {
		if(r!='0') {
			r--;
			break;
		}
		r='9';
	}
	if(A.back()=='0') A.resize(A.size()-1);
	reverse(A.begin(),A.end());
	return A;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string a,b; cin>>a>>b;
  a=decdec(a);
  ll ans=(f(b)-f(a)+MOD)%MOD;
  cout<<ans<<endl;
}
0