QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573544 | #2519. Number with Bachelors | pzjQWQ | WA | 38ms | 13936kb | C++14 | 3.3kb | 2024-09-18 19:10:32 | 2024-09-18 19:10:38 |
Judging History
answer
/*
进制转换练习题
*/
#include<bits/stdc++.h>
#define endl '\n'
#define int unsigned long long
using namespace std;
int T,a[20],tot,dp1[20][1<<10],dp2[20][1<<16];
char c[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
map<char,int> mp;
int get(string s){
int res=0;
for(auto c:s) res=res*16+mp[c];
return res;
}
void print(int x){
if(x>=16) print(x/16);
cout<<c[x%16];
}
int dfs1(int now,int state,bool flg1,bool flg2){
if(!now) return 1;
if(flg1&&flg2&&~dp1[now][state]) return dp1[now][state];
int res=0;
if(!flg2) res=dfs1(now-1,state,flg1|a[now],0);
for(int i=0;i<=(flg1?9:a[now]);++i){
if(!flg2&&!i) continue;
if((state>>i)&1) continue;
res+=dfs1(now-1,state|(1<<i),flg1|(i<a[now]),1);
}
if(flg1&&flg2) dp1[now][state]=res;
return res;
}
int solve1(int x){
tot=0;
while(x){
a[++tot]=x%10;
x/=10;
}
return dfs1(tot,0,0,0);
}
int dfs2(int now,int state,bool flg1,bool flg2){
if(!now) return 1;
if(flg1&&flg2&&~dp2[now][state]) return dp2[now][state];
int res=0;
if(!flg2) res=dfs2(now-1,state,flg1|a[now],0);
for(int i=0;i<=(flg1?15:a[now]);++i){
if(!flg2&&!i) continue;
if((state>>i)&1) continue;
res+=dfs2(now-1,state|(1<<i),flg1|(i<a[now]),1);
}
if(flg1&&flg2) dp2[now][state]=res;
return res;
}
int solve2(int x){
tot=0;
while(x){
a[++tot]=x%16;
x/=16;
}
return dfs2(tot,0,0,0);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
memset(dp1,-1,sizeof(dp1));
memset(dp2,-1,sizeof(dp2));
mp['0']=0,mp['1']=1,mp['2']=2,mp['3']=3,mp['4']=4,mp['5']=5,mp['6']=6,mp['7']=7,mp['8']=8,mp['9']=9,mp['a']=10,mp['b']=11,mp['c']=12,mp['d']=13,mp['e']=14,mp['f']=15;
cin>>T;
int cnt=0;
while(cnt<=T){
++cnt;
char c;
bool op;
cin>>c>>op;
if(c=='d'){
if(!op){
int l,r;
cin>>l>>r;
cout<<solve1(r)-solve1(l-1)<<endl;
} else{
int x;
cin>>x;
int l=1,r=9876543210;
if(solve1(r)<x){
cout<<'-'<<endl;
continue;
}
while(l<r){
int mid=l+r>>1;
if(solve1(mid)<x) l=mid+1;
else r=mid;
}
cout<<r<<endl;
}
} else{
if(!op){
string s1,s2;
cin>>s1>>s2;
int l=get(s1),r=get(s2);
print(solve2(r)-solve2(l-1));
cout<<endl;
} else{
string s;
cin>>s;
int x=get(s);
int l=1,r=get("fedcba9876543210");
if(solve2(r)<x){
cout<<'-'<<endl;
continue;
}
while(l<r){
int mid=l+r>>1;
if(solve2(mid)<x) l=mid+1;
else r=mid;
}
print(r);
cout<<endl;
}
}
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 38ms
memory: 13936kb
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 - - 1
result:
wrong output format Extra information in the output file