QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#329057#1875. NeinjrjyyRE 1ms3812kbC++142.3kb2024-02-16 12:29:002024-02-16 12:29:00

Judging History

你现在查看的是最新测评结果

  • [2024-02-16 12:29:00]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3812kb
  • [2024-02-16 12:29:00]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using i128 = __int128_t;

constexpr i128 inf = 2e18;
i128 add(i128 x, i128 y) {
    return std::min(x + y, inf);
}

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    std::array<i128, 39> pw;
    pw[0] = 1;
    for (int i = 0; i < 38; ++i) {
        pw[i + 1] = pw[i] * 10;
    }

    int k;
    i64 n;
    std::cin >> k >> n;
    ++n;
    const i64 m = pw[k] - 1;

    std::array<std::array<i128, 21 * 8 + 1>, 21 + 1> g{};
    g[0][0] = 1;
    for (int i = 0; i < 21; ++i) {
        for (int j = 0; j <= i * 8; ++j) {
            for (int x = 0; x < 9; ++x) {
                g[i + 1][j + x] = add(g[i + 1][j + x], g[i][j]);
            }
        }
    }
    auto calc = [&](int lim, i64 rem) -> i128 {
        std::array<i128, 20> f{}, nf;
        f[0] = 1;
        for (int i = 0; i < k + 3; ++i) {
            nf.fill(0);
            int div = i >= k ? 0 : (lim + k - 1 - i) / k;
            for (int j = 0; j < 20; ++j) {
                for (int x = 0; x <= div * 8; ++x) {
                    if ((j + x) % 10 != rem % 10) {
                        continue;
                    }
                    nf[(j + x) / 10] = add(nf[(j + x) / 10], f[j] * g[div][x]);
                }
            }
            f = nf;
            rem /= 10;
        }
        return f[0];
    };
    auto get = [&](int lim, i64 rem) -> i128 {
        int div = (lim + k - 1) / k;
        i128 res = 0;
        while (rem <= i128(div) * m) {
            res += calc(lim, rem);
            if (res >= inf) {
                return inf;
            }
            rem += m;
        }
        return res;
    };
    i128 ans = 0;
    for (int i = k + 18; i >= 0; --i) {
        for (int x = 0; x < 10; ++x) {
            assert(x < 9);
            auto t = get(i, (m - ans % m) % m);
            if (n <= t) {
                break;
            }
            n -= t;
            ans += pw[i];
        }
    }
    assert(ans % m == 0);
    ans /= m;

    [&](i128 x) {
        std::string s;
        do {
            s.push_back(x % 10 + '0');
            x /= 10;
        } while (x);
        std::reverse(s.begin(), s.end());
        std::cout << s << "\n";
    }(ans);

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3812kb

input:

1 1

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3540kb

input:

1 8

output:

9

result:

ok answer is '9'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3656kb

input:

1 9

output:

12

result:

ok answer is '12'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3536kb

input:

1 10

output:

13

result:

ok answer is '13'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3788kb

input:

5 1

output:

11112

result:

ok answer is '11112'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3540kb

input:

5 84

output:

11235

result:

ok answer is '11235'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

5 668

output:

12345

result:

ok answer is '12345'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

5 733942

output:

2281488

result:

ok answer is '2281488'

Test #9:

score: -100
Runtime Error

input:

18 528599760553218747

output:


result: