結果

問題 No.260 世界のなんとか3
ユーザー ふっぴーふっぴー
提出日時 2018-02-21 00:32:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 2,896 bytes
コンパイル時間 1,878 ms
コンパイル使用メモリ 181,492 KB
実行使用メモリ 33,508 KB
最終ジャッジ日時 2023-10-11 16:16:16
合計ジャッジ時間 5,547 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 171 ms
33,088 KB
testcase_04 AC 171 ms
33,180 KB
testcase_05 AC 36 ms
14,080 KB
testcase_06 AC 24 ms
10,428 KB
testcase_07 AC 128 ms
28,616 KB
testcase_08 AC 88 ms
29,116 KB
testcase_09 AC 47 ms
16,064 KB
testcase_10 AC 131 ms
26,396 KB
testcase_11 AC 136 ms
30,672 KB
testcase_12 AC 78 ms
24,048 KB
testcase_13 AC 20 ms
7,404 KB
testcase_14 AC 122 ms
29,000 KB
testcase_15 AC 29 ms
8,892 KB
testcase_16 AC 108 ms
24,040 KB
testcase_17 AC 84 ms
18,560 KB
testcase_18 AC 81 ms
16,564 KB
testcase_19 AC 101 ms
28,856 KB
testcase_20 AC 70 ms
19,084 KB
testcase_21 AC 64 ms
20,816 KB
testcase_22 AC 112 ms
24,880 KB
testcase_23 AC 11 ms
5,244 KB
testcase_24 AC 91 ms
26,580 KB
testcase_25 AC 103 ms
33,160 KB
testcase_26 AC 88 ms
33,508 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 172 ms
33,236 KB
testcase_29 AC 187 ms
33,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

struct Modint {
	ll n;
	static const ll Mod = 1000000007;
	Modint(int n = 0) : n(n) {}
};

Modint operator+(Modint a, Modint b) { return Modint((a.n += b.n) >= mod ? a.n - a.Mod : a.n); }
Modint operator-(Modint a, Modint b) { return Modint((a.n -= b.n) < 0 ? a.n + a.Mod : a.n); }
Modint operator*(Modint a, Modint b) { return Modint(1LL * a.n * b.n % a.Mod); }
Modint &operator+=(Modint &a, Modint b) { return a = a + b; }
Modint &operator-=(Modint &a, Modint b) { return a = a - b; }
Modint &operator*=(Modint &a, Modint b) { return a = a * b; }

#define vm vector<Modint>
#define vvm vector<vm>
#define vvvm vector<vvm>
#define vvvvm vector<vvvm>
#define vvvvvm vector<vvvvm>

int main() {
	vector<string> a(2);
	cin >> a[0] >> a[1];
	int i, j;
	for (i = a[0].size() - 1; i >= 0; i--) {
		if (a[0][i] != '0') {
			a[0][i] -= 1;
			break;
		}
		else {
			a[0][i] = '9';
		}
	}
	if (a[0][0] == '0') {
		a[0].erase(a[0].begin());
	}
	vector<Modint> ans(2);
	rep(q, 2) {
		string s = a[q];
		int n = s.size();
		vvvvvm dp(n + 1, vvvvm(3, vvvm(2, vvm(8, vm(2, 0)))));
		dp[0][0][0][0][1] = Modint(1);
		rep(keta, n) {
			rep(dev3, 3) {
				rep(is3, 2) {
					rep(dev8, 8) {
						rep(giri, 2) {
							int up = 9;
							if (giri) {
								up = s[keta] - '0';
							}
							int down = 0;
							for (int add = down; add <= up; add++) {
								int ndev3 = (dev3 * 10 + add) % 3;
								int ndev8 = (dev8 * 10 + add) % 8;
								int nis3 = is3;
								if (add == 3) {
									nis3 = 1;
								}
								int nketa = keta + 1;
								int ngiri = 0;
								if (giri && (add == up)) {
									ngiri = 1;
								}

								dp[nketa][ndev3][nis3][ndev8][ngiri] += dp[keta][dev3][is3][dev8][giri];

							}
						}
					}
				}
			}
		}
		rep(dev3, 3) {
			rep(is3, 2) {
				rep(dev8, 8) {
					rep(giri, 2) {
						if ((dev3 == 0 || is3) && dev8) {
							ans[q] += dp[n][dev3][is3][dev8][giri];
						}
					}
				}
			}
		}
		
		
	}
	cout << (ans[1] - ans[0]).n << endl;
}
0