結果

問題 No.260 世界のなんとか3
ユーザー Kmcode1Kmcode1
提出日時 2015-07-31 22:42:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 1,604 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 96,936 KB
実行使用メモリ 24,040 KB
最終ジャッジ日時 2024-04-25 07:39:32
合計ジャッジ時間 3,062 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 82 ms
24,040 KB
testcase_04 AC 83 ms
23,936 KB
testcase_05 AC 31 ms
11,008 KB
testcase_06 AC 20 ms
8,448 KB
testcase_07 AC 71 ms
20,992 KB
testcase_08 AC 66 ms
21,248 KB
testcase_09 AC 34 ms
12,288 KB
testcase_10 AC 64 ms
19,328 KB
testcase_11 AC 74 ms
22,272 KB
testcase_12 AC 56 ms
17,792 KB
testcase_13 AC 12 ms
6,400 KB
testcase_14 AC 68 ms
20,992 KB
testcase_15 AC 17 ms
7,168 KB
testcase_16 AC 56 ms
17,664 KB
testcase_17 AC 44 ms
14,080 KB
testcase_18 AC 38 ms
12,672 KB
testcase_19 AC 67 ms
21,120 KB
testcase_20 AC 44 ms
14,592 KB
testcase_21 AC 47 ms
15,728 KB
testcase_22 AC 58 ms
18,048 KB
testcase_23 AC 7 ms
5,376 KB
testcase_24 AC 61 ms
19,456 KB
testcase_25 AC 74 ms
24,004 KB
testcase_26 AC 74 ms
23,944 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 9 ms
23,832 KB
testcase_29 AC 12 ms
23,876 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