結果

問題 No.260 世界のなんとか3
ユーザー kurome____kurome____
提出日時 2016-03-01 23:44:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 346 ms / 2,000 ms
コード長 1,480 bytes
コンパイル時間 1,145 ms
コンパイル使用メモリ 160,240 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-25 07:51:16
合計ジャッジ時間 5,780 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
11,136 KB
testcase_01 AC 7 ms
11,008 KB
testcase_02 AC 8 ms
11,008 KB
testcase_03 AC 263 ms
11,008 KB
testcase_04 AC 285 ms
11,136 KB
testcase_05 AC 56 ms
11,136 KB
testcase_06 AC 39 ms
11,008 KB
testcase_07 AC 187 ms
11,136 KB
testcase_08 AC 131 ms
11,136 KB
testcase_09 AC 76 ms
11,008 KB
testcase_10 AC 205 ms
11,008 KB
testcase_11 AC 200 ms
11,136 KB
testcase_12 AC 119 ms
11,136 KB
testcase_13 AC 40 ms
11,008 KB
testcase_14 AC 183 ms
11,136 KB
testcase_15 AC 54 ms
11,008 KB
testcase_16 AC 157 ms
11,008 KB
testcase_17 AC 126 ms
11,136 KB
testcase_18 AC 123 ms
11,136 KB
testcase_19 AC 156 ms
11,136 KB
testcase_20 AC 112 ms
11,136 KB
testcase_21 AC 99 ms
11,136 KB
testcase_22 AC 176 ms
11,008 KB
testcase_23 AC 24 ms
11,136 KB
testcase_24 AC 139 ms
11,008 KB
testcase_25 AC 184 ms
11,136 KB
testcase_26 AC 97 ms
11,008 KB
testcase_27 AC 7 ms
11,008 KB
testcase_28 AC 191 ms
11,008 KB
testcase_29 AC 346 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define RFOR(i,e,s) for(int (i)=(e)-1;(i)>=(int)(s);(i)--)
#define RREP(i,e) RFOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;
typedef priority_queue<int> PQI;
typedef priority_queue<PII> PQII;

const double EPS = 1e-10;
const int N = 10000;
const int modi = 1e9;
ll mod = (ll)modi + 7;
ll dp[N+5][2][3][2][8];

ll calc(string x, int less) {
  int n = (int)x.size();
  memset(dp, 0, sizeof(dp));
  dp[0][0][0][0][0] = 1;
  REP(i,n) REP(j,2) REP(k,3) REP(l,2) REP(m,8) {
    int lim = j ? 9 : x[i]-'0';
    REP(d,lim+1)
      dp[i+1][j || d<lim][(k*10+d)%3][l || d==3][(m*10+d)%8]
        = (dp[i+1][j || d<lim][(k*10+d)%3][l || d==3][(m*10+d)%8] + dp[i][j][k][l][m]) % mod;
  }

  ll res = 0;
  REP(j,2) REP(k,3) REP(l,2) REP(m,8) {
    if (less && !j) continue; 
    if ((!k || l) && m) res = (res + dp[n][j][k][l][m]) % mod;
  }

  return res;
}

int main() {
  string a, b;
  cin >> a >> b;
//cout << "a.size, b.size = " << a.size() << ", " << b.size() << endl;
//cout << "calc(b,0) = " << calc(b,0) << endl;
//cout << "calc(a,0) = " << calc(a,1) << endl;
//cout << "res? = " << ((calc(b,0) + mod) - calc(a,1))%mod << endl;
//  printf("%lld\n", calc(b,0)-calc(a,1));
  printf("%lld\n", (calc(b,0)+mod-calc(a,1))%mod);
  return 0;
}
0