結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,900 KB
testcase_01 AC 5 ms
10,912 KB
testcase_02 AC 5 ms
10,904 KB
testcase_03 AC 131 ms
10,888 KB
testcase_04 AC 135 ms
10,952 KB
testcase_05 AC 30 ms
10,916 KB
testcase_06 AC 20 ms
11,128 KB
testcase_07 AC 92 ms
10,880 KB
testcase_08 AC 69 ms
10,924 KB
testcase_09 AC 39 ms
10,856 KB
testcase_10 AC 105 ms
10,864 KB
testcase_11 AC 100 ms
11,152 KB
testcase_12 AC 64 ms
10,932 KB
testcase_13 AC 19 ms
10,904 KB
testcase_14 AC 88 ms
11,212 KB
testcase_15 AC 26 ms
10,924 KB
testcase_16 AC 79 ms
10,920 KB
testcase_17 AC 61 ms
10,872 KB
testcase_18 AC 59 ms
10,916 KB
testcase_19 AC 76 ms
10,880 KB
testcase_20 AC 55 ms
10,988 KB
testcase_21 AC 51 ms
10,872 KB
testcase_22 AC 88 ms
10,868 KB
testcase_23 AC 12 ms
10,856 KB
testcase_24 AC 70 ms
10,876 KB
testcase_25 AC 88 ms
10,932 KB
testcase_26 WA -
testcase_27 AC 4 ms
10,916 KB
testcase_28 WA -
testcase_29 AC 166 ms
10,940 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