QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#730362#2519. Number with Bachelorsucup-team5226WA 116ms3824kbC++203.5kb2024-11-09 19:53:322024-11-09 19:53:33

Judging History

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

  • [2024-11-09 19:53:33]
  • 评测
  • 测评结果:WA
  • 用时:116ms
  • 内存:3824kb
  • [2024-11-09 19:53:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
using vl = vector<ll>;
using sl = set<ll>;
#define ov4(a, b, c, d, name, ...) name
#define rep3(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep2(i, a, b) rep3(i, a, b, 1)
#define rep1(i, n) rep2(i, 0, n)
#define rep0(n) rep1(aaaaa, n)
#define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define all(v) v.begin(), v.end()
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
void solve() {
    char c;
    ll t;
    cin >> c >> t;
    auto get = [](char c) {
        if ('0' <= c and c <= '9') return c - '0';
        return c - 'a' + 10;
    };
    auto get2 = [&](ll x) {
        if (x < 10) return '0' + x;
        return 'a' + x - 10;
    };
    vc<ll> valsd = {1, 9};
    for (ll i = 9; i >= 1; i--) valsd.push_back(valsd.back() * i);
    auto sumd = valsd;
    rep(i, 1, valsd.size()) sumd[i] += sumd[i - 1];
    vc<ll> valsh = {1, 15};
    for (ll i = 15; i >= 1; i--) valsh.push_back(valsh.back() * i);
    auto sumh = valsh;
    rep(i, 1, valsh.size()) sumh[i] += sumh[i - 1];
    auto h2d = [&](string s, ll type) {
        ll res = 0;
        ll MA = (type == 0 ? 10 : 16);
        for (auto S : s) {
            res *= MA;
            res += get(S);
            if (res > sumh.back()) return res;
        }
        return res;
    };
    auto d2h = [&](ll x, ll type) {
        if (x == 0) return to_string(x);
        ll MA = (type == 0 ? 10 : 16);
        string res;
        while (x) {
            res += get2(x % MA);
            x /= MA;
        }
        reverse(res.begin(), res.end());
        return res;
    };
    auto f = [&](string s, ll type) -> ll {
        ll ns = s.size();
        vvc<ll> dp(ns + 1, vc<ll>(2));
        dp[1][1] = 1;
        dp[1][0] = get(s[0]) - 1;
        set<ll> st;
        st.insert(get(s[0]));
        ll MA = (type == 0 ? 10 : 16);
        rep(i, 2, ns + 1) {
            ll val = get(s[i - 1]);
            dp[i][0] += dp[i - 1][0] * (MA + 1 - i);
            if (!st.count(val)) dp[i][1] = dp[i - 1][1];
            st.insert(val);
            ll r = val;
            rep(j, val) if (st.count(j)) r--;
            dp[i][0] += dp[i - 1][1] * r;
            dp[i][0] += MA - 1;
        }
        return 1 + dp[ns][0] + dp[ns][1];
    };
    ll type = c == 'h';
    if (t == 0) {
        string l, r;
        cin >> l >> r;
        ll val = h2d(r, type);
        string s = d2h(val, type);
        ll res = f(s, type);
        if (l != "0") {
            val = h2d(l, type) - 1;
            s = d2h(val, type);
            res -= f(s, type);
        }
        cout << d2h(res, type) << endl;
        return;
    }
    string i;
    cin >> i;
    ll r = h2d(i, type) + 1;
    if (type == 0) {
        if (r > sumd.back()) {
            cout << "-" << endl;
            return;
        }
    } else {
        if (r > sumh.back()) {
            cout << "-" << endl;
            return;
        }
    }
    ll R = r - 1;
    ll l = 0;
    while (r - l > 1) {
        ll mid = (l + r) / 2;
        ll val = f(d2h(mid, type), type);
        if (val < R)
            l = mid;
        else
            r = mid;
    }
    if (type)
        cout << d2h(r, type) << endl;
    else
        cout << r << endl;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cout << fixed << setprecision(20);
    ll t = 1;
    cin >> t;
    rep(t) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3560kb

input:

6
d 0 10 20
h 0 10 1f
d 1 10
h 1 f
d 1 1000000000
h 1 ffffffffffffffff

output:

10
f
9
e
-
-

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 116ms
memory: 3824kb

input:

50000
h 1 147a
d 0 25 71
d 1 3587
d 0 26922 51887
d 1 711
d 0 3 5
h 0 7bf2defab442a0b1 f299a4cf1d4d9bed
d 0 6961 91018
d 1 4
d 1 876
h 1 12cc5d3370f99120
d 1 161315
h 0 25f 6959
d 0 467 516
d 1 298
h 1 70260cdc2da73281
h 1 928e17d65d764ca2
h 1 c8ec8a7b67605e51
d 1 91697
d 0 4941925161850941148 89850...

output:

147b
43
3588
7710
712
3
5e71ccfae0
24407
3
877
-
161316
44ce
40
299
-
-
-
91698
18446744073709551517
1
29
-
384012
1
1
-
1091
15ac
35185e4113
124b7
40e6
9
3405
-
267ec1c60
3d979ce620
c9b5
2a55
-
0
-
7
d
6
1805
-
130dca9a20
0
5
9149
824908
901
125
0
-
27d7610630
424
66800
7
-
-
1d7
1
0
32b3
9
-
2a1
5...

result:

wrong answer 1st lines differ - expected: '1b36', found: '147b'