結果

問題 No.2865 Base 10 Subsets 2
ユーザー kwm_tkwm_t
提出日時 2024-08-30 22:07:53
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,003 bytes
コンパイル時間 3,111 ms
コンパイル使用メモリ 251,260 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-08-30 22:07:58
合計ジャッジ時間 3,583 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
6,940 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
template <class T, class F>
T binarySearch(T ok, T ng, const F &f) {
	while (abs(ok - ng) > 1) {
		T mid = (ok + ng) / 2;
		(f(mid) ? ok : ng) = mid;
	}
	return ok;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long n, k; cin >> n >> k;
	if (0 == n) {
		cout << 0 << endl;
		return 0;
	}
	string sn = to_string(n);
	vector<long long>vec = { 1 };
	rrep(i, sn.size()) vec.push_back(vec.back() *(sn[i] - '0' + 1));
	reverse(all(sn));
	auto g = [&](string s)->string {
		rep(i, s.size()) {
			int j = s.size() - 1 - i;
			if (s[i] > sn[j]) {
				rep2(j, i,s.size()) {
					int k = s.size() - 1 - j;
					s[j] = sn[k];
				}
				break;
			}
		}
		return s;
	};
	auto f = [&](long long x)->bool {
		long long cnt = 0;
		auto xs = to_string(x);
		xs = g(xs);
		//cout << x << " " << xs << endl;
		rep(i, xs.size()) {
			int j = xs.size() - i - 1;
			long long num = min(sn[i] - '0', xs[i] - '0');
			//cout << num << " " << vec[j] << endl;
			num *= vec[j];
			cnt += num;
		}
		cnt++;
		//cout << x << "_" << cnt << endl;
		return cnt >= k;
	};
	rep(i, 150) {
		f(i);
	}
	//return 0;
	auto ans = binarySearch<long long>(n, -1, f);
	cout << ans << endl;
	return 0;
}
0