結果

問題 No.260 世界のなんとか3
ユーザー tancahn2380tancahn2380
提出日時 2017-11-30 21:01:46
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,965 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 88,680 KB
実行使用メモリ 11,496 KB
最終ジャッジ日時 2024-11-27 15:18:16
合計ジャッジ時間 4,060 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
//typedef pair<LL, LL> P;
//typedef pair<P, P> PP;

int dp[101010][2][2][3][8];//keta,less,has3,mod3,mod8
int dp2[101010][2][2][3][8];
string a;
int n;
const int MOD = 1e9 + 7;

int main() {
	cin >> a;
	for (int b = a.size() - 1; b >= 0; b--) {
		if (a[b] != '0') {
			a[b]--;
			break;
		}
		else {
			a[b] = '9';
		}
	}
	n = a.length();
	dp[0][0][0][0][0] = 1;
	REP(i, n)REP(j, 2)REP(k, 2)REP(l, 3)REP(m, 8) {
		int lim = (j ? 9 : a[i] - '0');
		REP(d, lim + 1) {
			(dp[i + 1][j || d < lim][k || d == 3][(l + d) % 3][(10 * m + d) % 8] += dp[i][j][k][l][m]) %= MOD;
		}
	}
	int ans = 0;
	REP(j, 2)REP(k, 2)REP(l, 3)REP(m, 8)if ((k || l == 0) && m != 0)(ans += dp[n][j][k][l][m]) %= MOD;
	string b;
	cin >> b;
	n = b.length();
	dp2[0][0][0][0][0] = 1;
	REP(i, n)REP(j, 2)REP(k, 2)REP(l, 3)REP(m, 8) {
		int lim = (j ? 9 : b[i] - '0');
		REP(d, lim + 1) {
			(dp2[i + 1][j || d < lim][k || d == 3][(l + d) % 3][(10 * m + d) % 8] += dp2[i][j][k][l][m]) %= MOD;
		}
	}
	int ans2 = 0;
	REP(j, 2)REP(k, 2)REP(l, 3)REP(m, 8)if ((k || l == 0) && m != 0)(ans2 += dp2[n][j][k][l][m]) %= MOD;

	cout << ans2 - ans << endl;
}
0