QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#574450 | #2519. Number with Bachelors | TulipeNoire | WA | 1391ms | 14816kb | C++14 | 2.4kb | 2024-09-18 22:09:32 | 2024-09-18 22:09:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=25,mod=20130427;
using uLL=unsigned long long;
using i128=__int128;
int B;
uLL qk;
int b[N],cnt;
uLL f[N][65536];
bool vis[N][65536];
uLL dfs(int now,int S,int first,int up) {
if (!now) return 1;
if (up&&!first&&vis[now][S]) return f[now][S];
uLL res=0;
for (int i=0;i<B;i++) {
if ((S>>i)&1) continue;
if (first&&!i) continue;
if (!up) {
if (i<b[now]) res+=dfs(now-1,S|(1<<i),0,1);
if (i==b[now]) res+=dfs(now-1,S|(1<<i),0,0);
} else res+=dfs(now-1,S|(1<<i),0,1);
}
if (up&&!first) vis[now][S]=1,f[now][S]=res;
// cout<<now<<' '<<S<<' '<<first<<' '<<up<<' '<<res<<"\n";
return res;
}
inline uLL calc(uLL x) {
cnt=0;
while (x) {
b[++cnt]=x%B,x/=B;
}
uLL res=dfs(cnt,0,1,0);
for (int i=cnt-1;i>=0;i--) res+=dfs(i,0,1,1);
return res;
}
inline bool check(uLL x) {
return calc(x)>=qk;
}
uLL bs(uLL l,uLL r) {
if (l==r) return l;
if (l+1==r) {
if (check(l)) return l;
return r;
}
uLL mid=(((i128)l)+r)/2;
if (check(mid)) return bs(l,mid);
return bs(mid+1,r);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int tac;
cin>>tac;
while (tac--) {
char tp;
int op;
string l,r,x;
cin>>tp>>op;
qk=0;
if (tp=='h') B=16;
else B=10;
if (op) {
cin>>x;
for (auto o:x) {
if (isdigit(o)) qk=qk*B+o-'0';
else qk=qk*B+o-'a'+10;
}
uLL maxn=0xffffffffffffffff;
uLL res=bs(1,maxn);
if (res==maxn) {
cout<<"-\n";
} else {
int bb[N]={},ccnt=0;
while (res) bb[++ccnt]=res%B,res/=B;
for (int i=ccnt;i;i--) {
if (bb[i]>=10) cout<<(char)('a'+bb[i]-10);
else cout<<(char)('0'+bb[i]);
}
cout<<"\n";
}
} else {
cin>>l>>r;
uLL ql=0,qr=0;
for (auto o:l) {
if (isdigit(o)) ql=ql*B+o-'0';
else ql=ql*B+o-'a'+10;
}
for (auto o:r) {
if (isdigit(o)) qr=qr*B+o-'0';
else qr=qr*B+o-'a'+10;
}
if (ql) ql--;
uLL res=calc(qr)-calc(ql);
// cout<<ql<<' '<<qr<<"\n";
if (!res) {
cout<<"0\n";
continue;
}
int bb[N]={},ccnt=0;
// cout<<res<<"\n";
while (res) bb[++ccnt]=res%B,res/=B;
for (int i=ccnt;i;i--) {
if (bb[i]>=10) cout<<(char)('a'+bb[i]-10);
else cout<<(char)('0'+bb[i]);
}
cout<<"\n";
}
}
return 0;
}
/*
6
d 0 10 20
h 0 10 1f
d 1 10
h 1 f
d 1 1000000000
h 1 ffffffffffffffff
1
d 0 10 20
*/
詳細信息
Test #1:
score: 100
Accepted
time: 38ms
memory: 14728kb
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: 1391ms
memory: 14816kb
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 73 1985 89436 400 3 7c19f66e500 273650 3 482 - 52000 4681 154 200 - - - 30000 0 1 47 - 140000 1 1 - 15b4 175f 9235fe84000 124b7 6279 9 1894 - 39be22a900 4ad2ae4f300 146ce 2a55 - 0 - 7 d 6 2041 - c2fbb33300 0 5 98573 270000 500 389 0 - 3264ced9480 2506 1678286 7 - - 1e6 1 0 48b6 9 - 2b0 72027 14...
result:
wrong answer 2nd lines differ - expected: '43', found: '73'