提出 #23992976


ソースコード 拡げる

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

#define int long long
#define ld long double
#define pb push_back
#define all(v) begin(v), end(v)
#define ff first
#define ss second
const int inf = 4e18;
const int N = 2e5 + 10;

map<array<int, 4>, int> dp;
string s;
int k;

int rec(int pos, bool tight, bool fst, int product) {
	if (pos == s.length()) return product <= k;
	if (dp.count({pos, tight, fst, product})) return dp[ {pos, tight, fst, product}];
	int &ans = dp[ {pos, tight, fst, product}];

	ans = 0;
	int lim = tight ? s[pos] - '0' : 9;
	for (int i = 0 + fst; i <= lim; i++)
		ans += rec(pos + 1, tight and i == lim, 0, product * i);

	return ans;
}

void testCase() {
	int n; cin >> n >> k;
	s = to_string(n);

	int ans = 0;
	for (int i = s.length() - 1; i >= 0; i--)
		ans += rec(i, !i, 1, 1);
	cout << ans;
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int t_c = 1;
	// cin >> t_c;
	while (t_c--) testCase();
}

提出情報

提出日時
問題 E - Digit Products
ユーザ ResentfulPhantom
言語 C++ (GCC 9.2.1)
得点 500
コード長 980 Byte
結果 AC
実行時間 291 ms
メモリ 13396 KiB

コンパイルエラー

./Main.cpp: In function ‘long long int rec(long long int, bool, bool, long long int)’:
./Main.cpp:18:10: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   18 |  if (pos == s.length()) return product <= k;
      |      ~~~~^~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 37
セット名 テストケース
Sample sample_00.txt, sample_01.txt, sample_02.txt
All k_eq_1_00.txt, k_eq_1_01.txt, k_leq_1e3_00.txt, k_leq_1e3_01.txt, k_leq_1e3_02.txt, k_leq_1e3_03.txt, k_leq_1e3_04.txt, large_00.txt, large_01.txt, large_02.txt, large_03.txt, large_04.txt, n_eq_1_00.txt, n_eq_1_01.txt, n_leq_1e7_00.txt, n_leq_1e7_01.txt, n_leq_1e7_02.txt, n_leq_1e7_03.txt, n_leq_1e7_04.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, sample_00.txt, sample_01.txt, sample_02.txt, small_00.txt, small_01.txt, small_02.txt, small_03.txt, small_04.txt, small_05.txt, small_06.txt, small_07.txt, small_08.txt, small_09.txt
ケース名 結果 実行時間 メモリ
k_eq_1_00.txt AC 291 ms 13176 KiB
k_eq_1_01.txt AC 275 ms 13016 KiB
k_leq_1e3_00.txt AC 284 ms 13368 KiB
k_leq_1e3_01.txt AC 209 ms 10972 KiB
k_leq_1e3_02.txt AC 153 ms 9012 KiB
k_leq_1e3_03.txt AC 188 ms 10216 KiB
k_leq_1e3_04.txt AC 283 ms 13324 KiB
large_00.txt AC 285 ms 13252 KiB
large_01.txt AC 287 ms 13256 KiB
large_02.txt AC 284 ms 13396 KiB
large_03.txt AC 284 ms 13204 KiB
large_04.txt AC 285 ms 13260 KiB
n_eq_1_00.txt AC 2 ms 3632 KiB
n_eq_1_01.txt AC 2 ms 3556 KiB
n_leq_1e7_00.txt AC 6 ms 3752 KiB
n_leq_1e7_01.txt AC 8 ms 3676 KiB
n_leq_1e7_02.txt AC 4 ms 3668 KiB
n_leq_1e7_03.txt AC 5 ms 3672 KiB
n_leq_1e7_04.txt AC 9 ms 3688 KiB
random_00.txt AC 260 ms 12428 KiB
random_01.txt AC 278 ms 13220 KiB
random_02.txt AC 229 ms 11600 KiB
random_03.txt AC 283 ms 13292 KiB
random_04.txt AC 257 ms 12548 KiB
sample_00.txt AC 2 ms 3620 KiB
sample_01.txt AC 2 ms 3556 KiB
sample_02.txt AC 287 ms 13392 KiB
small_00.txt AC 6 ms 3704 KiB
small_01.txt AC 2 ms 3652 KiB
small_02.txt AC 2 ms 3628 KiB
small_03.txt AC 3 ms 3580 KiB
small_04.txt AC 3 ms 3632 KiB
small_05.txt AC 3 ms 3628 KiB
small_06.txt AC 2 ms 3552 KiB
small_07.txt AC 2 ms 3584 KiB
small_08.txt AC 2 ms 3764 KiB
small_09.txt AC 2 ms 3580 KiB