QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#718125 | #2519. Number with Bachelors | yuto1115# | WA | 0ms | 3796kb | C++20 | 2.1kb | 2024-11-06 19:46:18 | 2024-11-06 19:46:22 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <vector>
const int N = 25;
int n, base[2] = {10, 16};
unsigned long long dp[N][N], leqlen[N][N];
int fromchar(char c) {
if (c <= '9' && c >= '0') return c - '0';
else return c - 'a' + 10;
}
char tochar(int c) {
if (c >= 10) return 'a' + c - 10;
return '0' + c;
}
void outhex(long long x) {
std::vector<int> repr;
while (x) {
repr.push_back(x % 16);
x /= 16;
}
for (int i = (int)repr.size() - 1; i >= 0; --i) {
int c = repr[i];
if (c < 10) printf("%d", c);
else printf("%c\n", 'a' + c - 10);
}
}
long long readhex() {
char s[N];
scanf("%s", s);
long long r = 0;
for (int i = 0; s[i]; ++i) {
r *= 16;
r += fromchar(s[i]);
}
return r;
}
long long f(char *s, int b, bool last) {
bool u[N] = {0};
int len = strlen(s), avail = base[b];
long long ans = leqlen[len - 1][avail];
for (int i = 0; s[i]; ++i) {
int c = fromchar(s[i]);
for (int j = 0 + (!i); j < c; ++j) if (!u[j]) ans += dp[len - i - 1][avail - i - 1];
if (u[c]) return ans;
u[c] = true;
}
return ans + last;
}
void solve(long long ind, bool b) {
int len, avail = base[b];
--ind;
for (len = 0; len < N && leqlen[len][avail] <= ind; ++len);
if (len == N) printf("-\n");
else {
ind -= leqlen[len - 1][avail];
bool u[N] = {0};
for (int i = 0; i < len; ++i) {
int j = 0;
if (!i) ++j;
--avail;
for (; dp[len - i - 1][avail] <= ind; ++j) {
if (!u[j]) ind -= dp[len - i - 1][avail];
}
while (u[j]) ++j;
printf("%c", tochar(j));
u[j] = 1;
}
printf("\n");
}
}
int main() {
for (int i = 0; i < N; ++i) {
for (int j = i; j < N; ++j) {
if (!i) dp[i][j] = 1;
else {
dp[i][j] = j * dp[i - 1][j - 1];
leqlen[i][j] = leqlen[i - 1][j] + dp[i - 1][j - 1] * (j - 1) + (i == 1);
}
}
}
scanf("%d", &n);
while (n--) {
int type;
char b;
scanf(" %c%d", &b, &type);
b = b == 'd' ? 0 : 1;
if (type == 0) {
char l[N], r[N];
scanf("%s%s", l, r);
long long ans = f(r, b, 1) - f(l, b, 0);
if (b == 1) outhex(ans);
else printf("%lld\n", ans);
} else {
long long ind;
if (b == 1) ind = readhex();
else scanf("%lld", &ind);
solve(ind, b);
}
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3796kb
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 a f - -
result:
wrong answer 3rd lines differ - expected: '9', found: 'a'