結果

問題 No.2865 Base 10 Subsets 2
ユーザー Tatsu_mrTatsu_mr
提出日時 2024-08-30 22:08:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,249 bytes
コンパイル時間 2,428 ms
コンパイル使用メモリ 210,016 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-08-30 22:08:58
合計ジャッジ時間 3,252 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using lint = long long;

int main() {
    lint n, k;
    cin >> n >> k;
    if (k == 1) {
        cout << 0 << endl;
        return 0;
    }
    string s = to_string(n);
    int sz = s.size();
    auto f = [&](lint x) -> string {
        string res = to_string(x);
        string add = "";
        for (int i = 0; i < sz - (int)res.size(); i++) {
            add += '0';
        }
        res = add + res;
        return res;
    };
    lint l = 0, r = n;
    while (r - l > 1) {
        lint mid = (l + r) / 2;
        string t = f(mid);
        vector<vector<lint>> dp(sz + 1, vector<lint>(2));
        dp[0][0] = 1;
        for (int i = 0; i < sz; i++) {
            for (int j = 0; j < 2; j++) {
                for (int k = 0; k <= s[i] - '0'; k++) {
                    if (j == 0 && t[i] - '0' < k) {
                        continue;
                    }
                    int ni = i + 1;
                    int nj = j | (k < t[i] - '0');
                    dp[ni][nj] += dp[i][j];
                }
            }
        }
        lint cnt = dp[sz][0] + dp[sz][1];
        if (k <= cnt) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r << endl;
}
0