結果

問題 No.260 世界のなんとか3
ユーザー hirokazu1020hirokazu1020
提出日時 2015-08-01 01:34:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,600 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 83,680 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-04-25 07:47:49
合計ジャッジ時間 2,192 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,040 KB
testcase_01 AC 4 ms
7,040 KB
testcase_02 AC 4 ms
7,040 KB
testcase_03 AC 49 ms
7,040 KB
testcase_04 AC 57 ms
7,040 KB
testcase_05 AC 14 ms
7,040 KB
testcase_06 AC 11 ms
7,040 KB
testcase_07 AC 37 ms
7,168 KB
testcase_08 AC 26 ms
7,168 KB
testcase_09 AC 17 ms
7,040 KB
testcase_10 AC 41 ms
7,168 KB
testcase_11 AC 38 ms
7,040 KB
testcase_12 AC 25 ms
7,168 KB
testcase_13 AC 10 ms
7,040 KB
testcase_14 AC 36 ms
7,168 KB
testcase_15 AC 12 ms
7,040 KB
testcase_16 AC 32 ms
7,040 KB
testcase_17 AC 25 ms
7,168 KB
testcase_18 AC 24 ms
7,168 KB
testcase_19 AC 30 ms
7,168 KB
testcase_20 AC 23 ms
7,040 KB
testcase_21 AC 21 ms
7,296 KB
testcase_22 AC 34 ms
7,168 KB
testcase_23 AC 7 ms
6,912 KB
testcase_24 AC 27 ms
7,168 KB
testcase_25 AC 35 ms
7,168 KB
testcase_26 AC 20 ms
7,168 KB
testcase_27 AC 4 ms
6,912 KB
testcase_28 AC 35 ms
7,168 KB
testcase_29 AC 66 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())


#define MOD 1000000007


int pow_mod(long long x,long long y,int mod){
	int res=1;
	while(y){
		if(y&1)res=(res*x)%mod;
		y>>=1;
		x=(x*x)%mod;
	}
	return res;
}


pair<int,int> dp[10000+2][2][24];

int calc(string &s,bool eq){
	memset(dp,0,sizeof(dp));
	dp[0][0][0].second=1;
	rep(i,s.size()){
		int p=pow_mod(10,s.size()-i-1,24);
		rep(j,2)rep(k,24){
			pair<int,int> v=dp[i][j][k];
			rep(d,10){
				if(j==0&&s[i]-'0'<d)break;
				if(d==3){
					(dp[i+1][j||d<s[i]-'0'][(k+p*d)%24].first += (v.first+v.second)%MOD)%=MOD;
				}else{
					(dp[i+1][j||d<s[i]-'0'][(k+p*d)%24].first += v.first)%=MOD;
					(dp[i+1][j||d<s[i]-'0'][(k+p*d)%24].second += v.second)%=MOD;
				}
			}
		}
	}
	int ret=0;
	if(eq){
		rep(j,2){
			rep(k,24){
				if(k%8!=0)(ret+=dp[s.size()][j][k].first)%=MOD;
				if(k%3==0 && k%8!=0)(ret+=dp[s.size()][j][k].second)%=MOD;
				
			}
		}
	}else{
		rep(k,24){
			if(k%8!=0)(ret+=dp[s.size()][1][k].first)%=MOD;
			if(k%3==0 && k%8!=0)(ret+=dp[s.size()][1][k].second)%=MOD;
				
		}
	}
	return ret;
}

int main(){
	string a,b;
	cin>>a>>b;
	cout<<(calc(b,true)-calc(a,false)+MOD)%MOD<<endl;
	return 0;
}
0