結果

問題 No.260 世界のなんとか3
ユーザー Kmcode1Kmcode1
提出日時 2015-07-31 22:42:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,604 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 96,408 KB
実行使用メモリ 23,984 KB
最終ジャッジ日時 2023-08-07 13:56:00
合計ジャッジ時間 2,951 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,612 KB
testcase_01 AC 2 ms
5,568 KB
testcase_02 AC 2 ms
5,468 KB
testcase_03 AC 73 ms
23,984 KB
testcase_04 AC 72 ms
23,852 KB
testcase_05 AC 26 ms
13,012 KB
testcase_06 AC 17 ms
8,320 KB
testcase_07 AC 59 ms
22,876 KB
testcase_08 AC 61 ms
23,052 KB
testcase_09 AC 31 ms
13,212 KB
testcase_10 AC 54 ms
20,516 KB
testcase_11 AC 63 ms
23,220 KB
testcase_12 AC 48 ms
18,216 KB
testcase_13 AC 11 ms
8,220 KB
testcase_14 AC 61 ms
22,932 KB
testcase_15 AC 14 ms
8,160 KB
testcase_16 AC 48 ms
18,388 KB
testcase_17 AC 36 ms
15,588 KB
testcase_18 AC 32 ms
13,316 KB
testcase_19 AC 60 ms
22,948 KB
testcase_20 AC 38 ms
15,732 KB
testcase_21 AC 41 ms
15,828 KB
testcase_22 AC 50 ms
18,384 KB
testcase_23 AC 6 ms
5,860 KB
testcase_24 AC 53 ms
20,768 KB
testcase_25 AC 67 ms
23,884 KB
testcase_26 AC 63 ms
23,952 KB
testcase_27 AC 2 ms
5,472 KB
testcase_28 AC 11 ms
23,848 KB
testcase_29 AC 11 ms
23,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
using namespace std;

#define MAX 10002

long long int dp[MAX][3][2][9][2][2];  //under upper
bool use[MAX][3][2][9][2][2];  //under upper
string a;
string b;
#define MOD 1000000007
inline long long int dfs(int c, int d, int e, int f, int g, int h){
	if (c == a.size()){
		bool ok = (d == 0);
		ok |= e;
		ok &= (bool)(f != 0);
		return ok;
	}
	if (use[c][d][e][f][g][h]){
		return dp[c][d][e][f][g][h];
	}
	use[c][d][e][f][g][h]=true;
	long long int r = 0;
	int wa = a[c] - '0';
	int wb = b[c] - '0';
	for (int i = 0; i < 10; i++){
		if (wa > i&&g==false){
			continue;
		}
		if (i > wb&&h == false){
			continue;
		}
		r += dfs(c + 1, (d*10 + i) % 3, e | (i == 3),(f*10+i)%8,g | (wa<i), h | (wb>i));
		r %= MOD;
	}
	dp[c][d][e][f][g][h] = r;
	return r;
}
int main(){
	cin >> a;
	cin >> b;
	int siz = max(a.size(), b.size());
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	while (a.size() != siz){
		a.push_back('0');
	}
	while (b.size() != siz){
		b.push_back('0');
	}
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	long long int ans = dfs(0, 0, 0, 0, 0, 0);
	printf("%lld\n", ans);
	return 0;
}
0