結果

問題 No.260 世界のなんとか3
ユーザー a_kawashiroa_kawashiro
提出日時 2017-12-26 22:10:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,597 bytes
コンパイル時間 1,039 ms
コンパイル使用メモリ 112,988 KB
実行使用メモリ 11,220 KB
最終ジャッジ日時 2023-08-22 22:03:38
合計ジャッジ時間 4,373 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
11,104 KB
testcase_01 AC 50 ms
10,960 KB
testcase_02 AC 51 ms
11,028 KB
testcase_03 WA -
testcase_04 AC 70 ms
11,048 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
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 WA -
testcase_26 AC 51 ms
10,972 KB
testcase_27 AC 50 ms
11,000 KB
testcase_28 AC 51 ms
11,212 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

static const LL MOD = 1000000000+7;
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+MOD)%MOD;	}
LL POW(LL a, LL x) {
  LL res = 1;
  while(x > 0) {
  if(x & 1) res = res * a % MOD;
  a = a * a % MOD;
  x >>= 1;
  }
  return res;
}
LL DIV(LL x,LL y){
    return MUL(x,POW(y,MOD-2));
}
LL COMB(LL n, LL r) {
  LL res = 1;
  LL R = min(r,n-r);
  LL RR = R;
  for(LL i = n; i > n - R; i--) {
    res = res * (i % MOD)  % MOD;
    res = res * POW(RR,MOD-2) % MOD;
    RR--;
  }
  return res;
}

const int LEN = 10000+1;
string A,B;
LL DP[LEN+1][2][3][2][8];

int main(void){
    LL nA=0,nB=0;
    cin>>A>>B;
    A=string(LEN-SZ(A),'0')+A;
    B=string(LEN-SZ(B),'0')+B;
    memset(DP,0,sizeof(DP));
    DP[0][0][0][0][0]=1;
    REP(i1,LEN)REP(i2,2)REP(i3,3)REP(i4,2)REP(i5,8){
        REP(j,(i2==0?A[i1]-'0'+1:10)){
            LL &a=DP[i1+1][i2 || j<A[i1]-'0'][(i3+j)%3][i4 || j==3][(i5 * 10 + j) % 8];
            a += DP[i1][i2][i3][i4][i5];
            a %= MOD;
        }
    }
    REP(i3,3)REP(i4,2)REP(i5,8)
        if((i3==0 || i4) && i5!=0)
            nA = ADD(nA, DP[LEN][1][i3][i4][i5]);

    memset(DP,0,sizeof(DP));
    DP[0][0][0][0][0]=1;
    REP(i1,LEN)REP(i2,2)REP(i3,3)REP(i4,2)REP(i5,8){
        REP(j,(i2==0?B[i1]-'0'+1:10)){
            LL &a=DP[i1+1][i2 || j<B[i1]-'0'][(i3+j)%3][i4 || j==3][(i5 * 10 + j) % 8];
            a += DP[i1][i2][i3][i4][i5];
            a %= MOD;
        }
    }
    REP(i3,3)REP(i4,2)REP(i5,8)
        if((i3==0 || i4) && i5!=0)
            nB = ADD(nB, DP[LEN][1][i3][i4][i5]);
    printf("%lld\n",SUB(nB,nA));
    return 0;
}
0