QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573521 | #2519. Number with Bachelors | lifan | WA | 0ms | 24120kb | C++14 | 2.1kb | 2024-09-18 19:07:11 | 2024-09-18 19:07:12 |
Judging History
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;
}
ui Get(ui x) {
if (x == -1) 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);
// cerr << Get(r) << '\n';
write(Get(r) - Get(l - 1));
} else {
ui x;
read(x);
if (x < 10) return cout << x - 1 << '\n', void();
ui l = 0, r = -1;
if (Get(r) < x) return cout << '-' << '\n', void();
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;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 24120kb
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 - - - -
result:
wrong answer 3rd lines differ - expected: '9', found: '-'