QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573499 | #2519. Number with Bachelors | ddxrS | TL | 71ms | 29348kb | C++23 | 1.6kb | 2024-09-18 19:01:54 | 2024-09-18 19:02:03 |
Judging History
answer
//进制转换好题啊
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int a[25], B, cnt;
ll f[2][25][1 << 16];
__int128 l, r;
ll dfs(int pos, int tmp, bool limit, bool flg) {
if(pos == -1) return 1;
if(!limit && ~f[flg][pos][tmp]) return f[flg][pos][tmp];
ll up = limit ? a[pos] : B - 1, res = 0;
for(int i = 0; i <= up; i++) if(!(flg | (i > 0)) || !(tmp & (1 << i))) res += dfs(pos - 1, (flg | (i > 0)) ? (tmp | (1 << i)) : tmp, limit & (i == up), flg | (i > 0));
if(!limit) f[flg][pos][tmp] = res;
return res;
}
ll init(ll x) {
cnt = 0;
while(x) a[cnt++] = x % B, x /= B;
return dfs(cnt - 1, 0, 1, 0);
}
__int128 read() {
__int128 qpow = 1, sum = 0;
string s;
cin>>s;
for(int i = s.length() - 1; ~i; i--) {
int p = (('0' <= s[i] && s[i] <= '9') ? s[i] - '0' : (s[i] - 'a' + 10));
sum += p * qpow;
qpow *= B;
}
return sum;
}
void print(ll x) {
if(x == 0) return puts("0"), void();
cnt = 0; while(x) a[cnt++] = x % B, x /= B;
for(int i = cnt - 1; ~i; i--) {
if(a[i] <= 9) printf("%d", a[i]);
else putchar(char(a[i] - 10 + 'a'));
}
puts("");
}
void solve() {
memset(f, -1, sizeof f);
char opt;
cin>>opt;
if(opt == 'd') B = 10; else B = 16;
cin>>opt;
if(opt == '0') {
l = read(), r = read();
print(init(r) - init(l - 1));
} else if(opt == '1') {
l = read();
__int128 L = 0, R = 9223372036854775807ll, mid, ans = -1;
while(L <= R) {
mid = L + R >> 1;
if(init(mid) >= l) ans = mid, R = mid - 1;
else L = mid + 1;
}
if(ans == -1) puts("-");
else print(ans);
}
}
int main() {
int t; cin>>t;
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 71ms
memory: 29348kb
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
Time Limit Exceeded
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 -2-6-10-8-5-8-1-3-9-4-15-5 26054 3 1356 - 946307 4681 40 387 - - - 491850 0 1 29 - 4605298 1 1 - 15b4 175f -1-14-15-4-5-8-9-14-15-1-15-5 124b7 6279 9 6257 - 39be22a900 -2-5-8-10-12-7-15-5-1-6-15-5 146ce 2a55 - 0 - 7 d 6 2041 - 0 0 5 9149 16540973 1389 125 -8-8-7-7-6-9-1 - -2-...