結果

問題 No.260 世界のなんとか3
ユーザー TomoyaTomoya
提出日時 2019-02-05 23:23:32
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,870 bytes
コンパイル時間 780 ms
コンパイル使用メモリ 79,000 KB
実行使用メモリ 63,708 KB
最終ジャッジ日時 2023-08-30 23:59:09
合計ジャッジ時間 4,003 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
63,652 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 113 ms
63,420 KB
testcase_04 AC 116 ms
63,420 KB
testcase_05 WA -
testcase_06 AC 38 ms
63,512 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 82 ms
63,388 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 84 ms
63,416 KB
testcase_26 AC 54 ms
63,684 KB
testcase_27 AC 26 ms
63,428 KB
testcase_28 AC 85 ms
63,412 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

ll nl, nm;


//i桁目, smaller, 3がつく, mod 3, mod 8
ll dp[80001][2][2][3][8];

ll calc(string s){
  memset(dp, 0, sizeof(dp));
  ll n = s.size();
  dp[0][0][0][0][0] = 1;
  REP(i, n) {
    ll x = s[i]-'0';
    REP(j, 2){
      REP(k, 2){
	REP(l, 3){
	  REP(m, 8){
	    ll lim = (j ? 9 : x);	    
	    REP(d, lim+1) (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 ans = 0LL;
  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;
}

int
main(void){  
  cin.tie(0);
  ios::sync_with_stdio(false);

  string a, b;
  cin >> a >> b;

  cout << (MOD + calc(b) - calc(a)) % MOD << endl;
  
  return 0;
}
0