結果

問題 No.1953 8
ユーザー ruthenruthen
提出日時 2022-05-20 23:13:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,370 bytes
コンパイル時間 2,343 ms
コンパイル使用メモリ 211,096 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 14:06:03
合計ジャッジ時間 6,039 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

const int c[10] = {1, 0, 0, 0, 1, 0, 1, 0, 2, 1};

ll f(ll x) {
    string s = to_string(x);
    int N = s.size();
    V<V<V<ll>>> dpc(N + 1, V<V<ll>>(2, V<ll>(2, 0)));
    V<V<V<ll>>> dps(N + 1, V<V<ll>>(2, V<ll>(2, 0)));
    dpc[0][0][0] = 1;
    rep(i, N) {
        rep(j, 2) {
            rep(k, 2) {
                for (int d = 0; d <= (j ? 9 : s[i] - '0'); d++) {
                    dpc[i + 1][j | (d < s[i] - '0')][k | (d != 0)] += dpc[i][j][k];
                    dps[i + 1][j | (d < s[i] - '0')][k | (d != 0)] += dps[i][j][k] + dpc[i][j][k] * ((k | (d != 0)) ? c[d] : 0);
                }
            }
        }
    }
    ll ans = dps[N][1][0] + dps[N][1][1] + dps[N][0][1];
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll K;
    cin >> K;
    // f(n) >= K となる最小のn
    ll ok = 99193752409910750LL, ng = 0;
    while (ok - ng > 1) {
        ll n = (ok + ng) / 2;
        if (f(n) >= K) {
            ok = n;
        } else {
            ng = n;
        }
    }
    if (f(ok) == K) {
        cout << ok << '\n';
    } else {
        cout << -1 << '\n';
    }
    return 0;
}
0