QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573555#2519. Number with BachelorslifanWA 268ms26340kbC++142.7kb2024-09-18 19:12:592024-09-18 19:13:00

Judging History

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

  • [2024-09-18 19:13:00]
  • 评测
  • 测评结果:WA
  • 用时:268ms
  • 内存:26340kb
  • [2024-09-18 19:12:59]
  • 提交

answer

// 
#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const int MAXN = (1 << 16) + 1;
ull dp[2][22][MAXN];
int type , a[100];
ull dfs(int pos, int sta, int limit) {
    if (pos == -1) return 1;
    if (dp[(type == 16)][pos][sta] != -1 && !limit) return dp[(type == 16)][pos][sta];
    int up = limit ? a[pos] : (type - 1);
    ull res = 0;
    for (int i = 0; i <= up; i++) {
        if ((sta >> i) & 1) continue;
        if (sta == 0 && i == 0) res += dfs(pos - 1 , sta , limit && i == up);
        else res += dfs(pos - 1 , sta | (1 << i) , limit && i == up);
    }
    if (!limit) dp[(type == 16)][pos][sta] = res;
    return res;
}
ull solve(ull x) {
    int pos = 0;
    while (x) {
        a[pos ++] = x % type;
        x /= type;
    }
    return dfs(pos - 1 , 0 , 1);
}
void input(ull &x) {
    x = 0;
    char s[22];
    cin >> (s + 1);
    int len = strlen(s + 1);
    for (int i = 1 ; i <= len ; i ++) {
        if (s[i] <= '9' && s[i] >= '0') x = x * type + s[i] - '0';
        else x = x * type + s[i] - 'a' + 10;
    }
}
void print(ull x) {
    if (x == 0) {
    	cout << '\n';
        return;
    }
    if (type == 10) cout << x << '\n';
    else {
        vector<int> ans;
        while (x) {
            int p = x % type;
            x /= type;
            ans.push_back(p);
        }
        for (int i = ans.size() - 1; i >= 0; i--) {
            if (ans[i] >= 10) cout << char(ans[i] - 10 + 'a');
            else cout << char(ans[i] + '0');
        }
        cout << '\n';
    }
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr) , cout.tie(nullptr);
    memset(dp , -1 , sizeof(dp));
    int T;
    cin >> T;
    while (T --) {
        char op[10];
        cin >> op;
        if (op[0] == 'd') type = 10;
        else type = 16;
        int flag;
        cin >> flag;
        if (!flag) {
            ull a , b;
            input(a) , input(b);
            ull ans = solve(b);
            if (a > 0) ans -= solve(a - 1);
            print(ans);
        } else {
            ull x;
            input(x);
            if (x < 10) {
            	cout << x - 1 << '\n';
                continue;
            }
            ull l = 0 , r = 0 , ans = 0;
            r --;
            if (solve(r) < x) {
                cout << '-' << '\n';
                continue;
            }
            while (l <= r) {
                ull mid = l + (r - l) / 2;
                if (solve(mid) >= x) r = mid - 1, ans = mid;
                else l = mid + 1;
            }
            print(ans);
        }
    }
}
/*
6
d 0 10 20
h 0 10 1f
d 1 10
h 1 f
d 1 1000000000
h 1 ffffffffffffffff

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 46ms
memory: 26160kb

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: 268ms
memory: 26340kb

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
1356
-
946307
4681
40
387
-
-
-
491850

1
29
-
4605298
1
1
-
15b4
175f
9b944134000
124b7
6279
9
6257
-
39be22a900
5c636b59300
146ce
2a55
-

-
7
d
6
2041
-
1c94afe7300

5
9149
16540973
1389
125

-
3bc31189480
424
66800
7
-
-
1e6
0

48b6
9
-
2b0
5019
14358
3...

result:

wrong answer 20th lines differ - expected: '0', found: ''