結果

問題 No.260 世界のなんとか3
ユーザー E31415926E31415926
提出日時 2017-02-21 22:07:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,906 bytes
コンパイル時間 1,556 ms
コンパイル使用メモリ 169,632 KB
実行使用メモリ 11,192 KB
最終ジャッジ日時 2023-08-28 23:45:10
合計ジャッジ時間 4,456 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,112 KB
testcase_01 AC 4 ms
10,904 KB
testcase_02 AC 5 ms
11,168 KB
testcase_03 AC 137 ms
10,936 KB
testcase_04 AC 133 ms
11,004 KB
testcase_05 WA -
testcase_06 AC 20 ms
11,132 KB
testcase_07 AC 89 ms
11,004 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 97 ms
10,888 KB
testcase_12 WA -
testcase_13 AC 20 ms
10,852 KB
testcase_14 AC 90 ms
10,876 KB
testcase_15 AC 28 ms
10,872 KB
testcase_16 WA -
testcase_17 AC 64 ms
10,980 KB
testcase_18 AC 59 ms
10,920 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 52 ms
10,980 KB
testcase_22 AC 90 ms
10,880 KB
testcase_23 WA -
testcase_24 AC 69 ms
10,880 KB
testcase_25 AC 89 ms
10,968 KB
testcase_26 WA -
testcase_27 AC 5 ms
10,848 KB
testcase_28 WA -
testcase_29 AC 166 ms
10,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define INF (1ll<<60)
typedef pair<int, int> pii;
#define FI first
#define SE second
#define all(s) s.begin(),s.end()
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)

string A;
string B;
const int mod = 1000000007;
int dp[10001][2][2][3][8]; //桁,未満確定(0未定1確定),3つく(0つかない1つく),mod3,mod8

signed main() {
	cin >> A >> B;
	dp[0][0][0][0][0] = 1;
	rep(i,B.length())
	{
		rep(j,2)
		{
			rep(k,2)
			{
				rep(l,3)
				{
					rep(m,8)
					{
						int lim = j ? 9ll : B[i] - '0';
						rep(d,lim+1)
						{
							(dp[i + 1][j || d < lim][k || d == 3][(l + d) % 3][(m
									* 10 + d) % 8] += dp[i][j][k][l][m]) %= mod;
						}
					}
				}
			}
		}
	}
	int ansB = 0;
	rep(j,2)
	{
		rep(l,3)
		{
			rep(m,7)
			{
				ansB += dp[B.length()][j][1][l][m + 1] % mod;
			}
		}
	}
	rep(j,2)
	{
		rep(m,7)
		{
			ansB += dp[B.length()][j][0][0][m + 1] % mod;
		}
	}
	memset(dp, 0, sizeof(dp));
	dp[0][0][0][0][0] = 1;
	rep(i,A.length())
	{
		rep(j,2)
		{
			rep(k,2)
			{
				rep(l,3)
				{
					rep(m,8)
					{
						int lim = j ? 9ll : A[i] - '0';
						rep(d,lim+1)
						{
							(dp[i + 1][j || d < lim][k || d == 3][(l + d) % 3][(m
									* 10 + d) % 8] += dp[i][j][k][l][m]) %= mod;
						}
					}
				}
			}
		}
	}
	int ansA = 0;
	rep(j,2)
	{
		rep(l,3)
		{
			rep(m,7)
			{
				ansA += dp[A.length()][j][1][l][m + 1] % mod;
			}
		}
	}
	rep(j,2)
	{
		rep(m,7)
		{
			ansA += dp[A.length()][j][0][0][m + 1] % mod;
		}
	}
	int ans = ((ansB + mod) - ansA) % mod;
	int mod3 = 0, mod8 = 0;
	bool a = false;
	rep(i,A.length())
	{
		if (A[i] == '3') {
			a = true;
		}
		mod3 += A[i] - '0';
		mod3 %= 3;
		mod8 *= 10;
		mod8 += A[i] - '0';
		mod8 %= 8;
	}
	if (a || mod3 == 0) {
		if (mod8 != 0) {
			cout << (ans + 1) % mod << endl;
			return 0;
		}
	}
	cout << ans << endl;
}
0