結果

問題 No.260 世界のなんとか3
ユーザー ty70ty70
提出日時 2016-10-10 05:20:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,738 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 148,464 KB
実行使用メモリ 11,220 KB
最終ジャッジ日時 2023-08-14 06:02:33
合計ジャッジ時間 4,033 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,032 KB
testcase_01 AC 5 ms
10,876 KB
testcase_02 AC 6 ms
10,916 KB
testcase_03 WA -
testcase_04 WA -
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 WA -
testcase_27 AC 5 ms
10,900 KB
testcase_28 WA -
testcase_29 AC 73 ms
10,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = (ll)1e9 + 7LL;

ll dp[10005][2][2][3][8]; 	// dp[i桁目][N未満であることが確定しているか 0 -> していない 1 -> している][3 の付く数字か 0 -> そうでない 1 -> そう][mod 3 の値][mod 8 の値]

ll solve (string s){
	memset (dp, 0LL, sizeof(dp));

	int n = s.length();
	dp[0][0][0][0][0] = 1LL;
	for (int i = 0; i < n; ++i){
		int D = (int)(s[i] - '0');
		for (int j = 0; j < 2; ++j){
			for (int k = 0; k < 2; ++k){
				for (int l = 0; l < 3; ++l){
					for (int m = 0; m < 8; ++m){
						for (int d = 0; d < (j ? 10 : D + 1); ++d){
							(dp[i + 1][j || d < D][k || d == 3][(10 * l + d) % 3][(10 * m + d) % 8] += dp[i][j][k][l][m]) % mod;
						} // end for
					} // end for
				} // end for
			} // end for
		} // end for
	} // end for

	ll res = 0LL;
	for (int j = 0; j < 2; ++j){
		for (int k = 0;k < 2; ++k){
			for (int l = 0; l < 3; ++l){
				for (int m = 0; m < 8; ++m){
					if ((k == 1 || l == 0) && (m != 0)) (res += dp[n][j][k][l][m]) % mod;
				} // end for
			} // end for
		} // end for
	} // end for

	return res;
}

string minus_one(string s){
	reverse(ALL(s));

	for (int i = 0; i < s.length(); ++i){
		if (s[i] != '0'){
			s[i] = (char)((int)(s[0] - '0') - 1 + '0');
			break;
		}else{
			s[i] = '9';
		} // end if
	} // end for

	while (s.length() > 1 && s[s.length() - 1] == '0') s = s.substr(0, s.length() - 1);

	reverse(ALL(s));

	return s; 
}

int main(){
	string A, B; cin >> A >> B;
	A = minus_one(A);
	ll res = (solve(B) - solve(A) + mod) % mod;
	cout << res << endl;
	
	return 0;
}					
0