結果

問題 No.260 世界のなんとか3
ユーザー akusyounin2412akusyounin2412
提出日時 2018-07-19 19:05:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 2,708 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 125,380 KB
実行使用メモリ 19,924 KB
最終ジャッジ日時 2023-08-25 20:59:04
合計ジャッジ時間 7,118 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,828 KB
testcase_01 AC 4 ms
11,600 KB
testcase_02 AC 4 ms
11,572 KB
testcase_03 AC 329 ms
19,804 KB
testcase_04 AC 326 ms
19,748 KB
testcase_05 AC 66 ms
15,692 KB
testcase_06 AC 45 ms
13,336 KB
testcase_07 AC 221 ms
19,736 KB
testcase_08 AC 157 ms
19,832 KB
testcase_09 AC 89 ms
15,616 KB
testcase_10 AC 253 ms
17,768 KB
testcase_11 AC 237 ms
19,764 KB
testcase_12 AC 142 ms
17,668 KB
testcase_13 AC 43 ms
12,696 KB
testcase_14 AC 215 ms
19,820 KB
testcase_15 AC 60 ms
13,104 KB
testcase_16 AC 190 ms
17,728 KB
testcase_17 AC 148 ms
15,708 KB
testcase_18 AC 139 ms
15,632 KB
testcase_19 AC 186 ms
19,808 KB
testcase_20 AC 133 ms
15,628 KB
testcase_21 AC 118 ms
17,740 KB
testcase_22 AC 211 ms
17,708 KB
testcase_23 AC 23 ms
12,200 KB
testcase_24 AC 165 ms
17,680 KB
testcase_25 AC 212 ms
19,804 KB
testcase_26 AC 120 ms
19,788 KB
testcase_27 AC 3 ms
11,524 KB
testcase_28 AC 324 ms
19,752 KB
testcase_29 AC 425 ms
19,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000+7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum[2000000], ans, d[200000], a[2000000], b[2000000],rnd[200000];
string str[2],ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<LL>vec[100000],hashs[100000];
vector<Pll>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
LL dp[20000][2][2][3][8];
LL func(string x) {
	rep(i, x.size()+1)rep(j, 2)rep(n, 2)rep(k, 3)rep(l, 8) {
		dp[i][j][n][k][l] = 0;
	}
	dp[0][0][0][0][0] = 1;
	rep(i, x.size()) {
		rep(j, 2) {
			rep(m, 2)
				rep(l, 3) {
				rep(n, 8) {
					int lim = (j ? 9 : x[i] - '0');
					rep(k, lim + 1) {
						dp[i + 1][j || k < lim][m || k == 3][(l + k) % 3][(10 * n + k) % 8] += dp[i][j][m][l][n];
						dp[i + 1][j || k < lim][m || k == 3][(l + k) % 3][(10 * n + k) % 8] %= MOD;
					}
				}
			}
		}
	}
	ans = 0;
	rep(i, 2)rep(j, 3)rep(k, 8)rep(l, 2) {
		if ((j == 0 || l == 1) && k != 0)
			ans += dp[x.size()][i][l][j][k];
		ans %= MOD;
	}
	return ans;
}
int main() {
	cin >> str[0] >> str[1];
	rep(i, str[0].size()) {
		if (str[0][str[0].size() - 1 - i]=='0') {
			str[0][str[0].size() - 1 - i] += 9;
		}
		else {
			str[0][str[0].size() - 1 - i]--;
			break;
		}
	}
	cout << (func(str[1]) - func(str[0]) +MOD)%MOD<< endl;
	return 0;
}
0