結果

問題 No.260 世界のなんとか3
ユーザー 👑 kmjpkmjp
提出日時 2015-08-01 00:45:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 368 ms / 2,000 ms
コード長 1,508 bytes
コンパイル時間 1,391 ms
コンパイル使用メモリ 161,936 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-25 07:47:39
合計ジャッジ時間 6,269 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
10,880 KB
testcase_01 AC 7 ms
10,880 KB
testcase_02 AC 7 ms
10,752 KB
testcase_03 AC 281 ms
11,008 KB
testcase_04 AC 284 ms
11,008 KB
testcase_05 AC 58 ms
11,008 KB
testcase_06 AC 41 ms
11,008 KB
testcase_07 AC 192 ms
11,008 KB
testcase_08 AC 139 ms
10,880 KB
testcase_09 AC 82 ms
11,008 KB
testcase_10 AC 229 ms
11,008 KB
testcase_11 AC 205 ms
11,008 KB
testcase_12 AC 125 ms
11,008 KB
testcase_13 AC 42 ms
11,008 KB
testcase_14 AC 185 ms
11,008 KB
testcase_15 AC 55 ms
11,008 KB
testcase_16 AC 162 ms
11,008 KB
testcase_17 AC 134 ms
11,008 KB
testcase_18 AC 122 ms
11,008 KB
testcase_19 AC 161 ms
11,008 KB
testcase_20 AC 114 ms
11,008 KB
testcase_21 AC 104 ms
10,880 KB
testcase_22 AC 189 ms
10,880 KB
testcase_23 AC 25 ms
10,880 KB
testcase_24 AC 148 ms
10,880 KB
testcase_25 AC 181 ms
11,008 KB
testcase_26 AC 106 ms
10,880 KB
testcase_27 AC 7 ms
10,880 KB
testcase_28 AC 284 ms
11,008 KB
testcase_29 AC 368 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string A,B;
ll mo=1000000007;
ll dp[10101][2][2][3][8]; // digit, more, inc3, mod3, mod8

ll dodo(string V) {
	ZERO(dp);
	dp[0][0][0][0][0]=1;
	int d,more,i3,m3,m8,x;
	FOR(d,V.size()) {
		V[d]-='0';
		FOR(more,2) FOR(i3,2) FOR(m3,3) FOR(m8,8) FOR(x,10) {
			if(more==0 && x>V[d]) continue;
			(dp[d+1][more || (x<V[d])][i3 || (x==3)][(m3*10+x)%3][(m8*10+x)%8] += dp[d][more][i3][m3][m8])%=mo;
		}
	}
	ll ret=0;
	FOR(more,2) FOR(i3,2) FOR(m3,3) FOR(m8,8) {
		if((m3==0 || i3==1) && m8) ret += dp[V.size()][more][i3][m3][m8];
	}
	return ret%mo;
}

string decdec(string A) {
	reverse(A.begin(),A.end());
	FORR(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;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B;
	A=decdec(A);
	cout<<(dodo(B)-dodo(A)+ mo)%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0