QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573492#2519. Number with BachelorslifanWA 190ms24284kbC++142.1kb2024-09-18 19:00:362024-09-18 19:00:37

Judging History

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

  • [2024-09-18 19:00:37]
  • 评测
  • 测评结果:WA
  • 用时:190ms
  • 内存:24284kb
  • [2024-09-18 19:00:36]
  • 提交

answer

// 
#include <bits/stdc++.h>
#define int long long
typedef unsigned int ui;
using namespace std;
constexpr int Mod = 1e9 + 7;

int B, a[60], cnt, ct, rk[2521], dp[2][20][1 << 16];

int dfs(int p, bool lim, int s) {
    if (!p) return 1;
    if (!lim && ~dp[B == 10][p][s]) return dp[B == 10][p][s];
    int rs(0), up(lim ? a[p] : B - 1);
    for (int i = 0; i <= up; i++) if (!(s >> i & 1)) rs += dfs(p - 1, lim && i == up, !s && !i ? 0 : (s | 1 << i));
    if (!lim) dp[B == 10][p][s] = rs;
    return rs;
}
int Get(ui x) {
    if (!x) return 0;
    cnt = 0;
    while (x) a[++cnt] = x % B, x /= B;
    return dfs(cnt, 1, 0);
}
void read(ui &x) {
    if (B == 10) cin >> x;
    else {
        x = 0;
        string s;
        cin >> s;
        for (char c : s) {
            if (c >= '0' && c <= '9') x = x * B + (c ^ 48);
            else x = x * B + c - 'a' + 10;
        }
    }
}
void write(ui x) {
    if (!x) cout << "0\n";
    if (B == 10) cout << x << '\n';
    else {
        vector<int> pc;
        while (x) pc.push_back(x % B), x /= B;
        for (auto it = pc.rbegin(); it != pc.rend(); it++) {
            if (*it >= 10) cout << (char)(*it - 10 + 'a');
            else cout << *it;
        }
        cout << '\n';
    }
}
void solve() {
    char c;
    int ty;
    cin >> c >> ty;
    if (c == 'd') B = 10;
    else B = 16;
    if (ty == 0) {
        ui l, r;
        read(l), read(r);
        write(Get(r) - Get(l - 1));
    } else {
        ui x;
        read(x);
        if (x < 10) cout << x - 1 << '\n';
        ui l = 0, r = -1;
        if (Get(r) < x) cout << '-' << '\n';
        else {
            while (l < r) {
                int mid(l + r >> 1);
                if (Get(mid) >= x) r = mid;
                else l = mid + 1;
            }
            write(l);
        }
    }
}

signed main() {
#ifdef LARRIX
    freopen("sample.in", "r", stdin);
    freopen("sample.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    memset(dp, -1, sizeof dp);
    int T; cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 37ms
memory: 24284kb

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: 190ms
memory: 24072kb

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:

1b36
43
6587
7710
953
3
8daab378500
26054
3
3
1356
-
946307
4681
40
387
-
-
-
491850
0
0
1
29
-
4605298
1
1
1
1
-
15b4
175f
9b944134000
124b7
6279
9
6257
-
39be22a900
5c636b59300
146ce
2a55
-
0
0
-
7
7
d
6
6
2041
-
1c94afe7300
0
0
5
5
9149
16540973
1389
125
0
0
-
3bc31189480
424
66800
7
7
-
-
1e6
0
...

result:

wrong answer 10th lines differ - expected: '1356', found: '3'