QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#717989 | #2519. Number with Bachelors | yuto1115# | WA | 20ms | 3724kb | C++20 | 1.9kb | 2024-11-06 19:27:11 | 2024-11-06 19:27:12 |
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];
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) {
long long ans = 0;
bool u[N] = {0};
int len = strlen(s), avail = base[b];
for (int i = 0; s[i]; ++i) {
int c = fromchar(s[i]);
for (int j = 0; j < c; ++j) if (!u[j]) ans += dp[len - i - 1][avail - i - 1 + (!i && !j)];
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 && dp[len][avail] <= ind; ++len);
if (len == N) printf("-\n");
else {
for (int i = 0; i < len; ++i) {
int j = 0;
for (; dp[len - i - 1][avail] <= ind; ++j) ind -= dp[len - i - 1][avail];
printf("%c", tochar(j));
}
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];
}
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
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: 20ms
memory: 3724kb
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:
17c9 43 4776 7710 780 3 8d a a b 37850025838 3 1165 - 1020034 466340 327 - - - 301276 0 129 - 2241270 1 1 - 139f 17419b 944134000124b 760039 4573 - 39b e 22a 9005c 636b 5930012523 2a 55- 0 - 7 d 6 1b93 - 1c 94a f e 73000 5 9149 11214556 1189 125 0 - 3b c 31189480424 66800 7 - - 1e 5 0 3c11 9- 2a f 5...
result:
wrong answer 1st lines differ - expected: '1b36', found: '17c9'