QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#574641 | #2519. Number with Bachelors | Others | TL | 873ms | 106116kb | C++14 | 3.2kb | 2024-09-18 23:29:26 | 2024-09-18 23:29:27 |
Judging History
answer
#include <bits/stdc++.h>
#define ll __int128
#define int __int128
#define db long double
#define x first
#define y second
#define wdnmd const int mod=::mod;
#define eps 1e-12
#define lb(i) ((i)&(-(i)))
#define wr(x,ch) write(x),putchar(ch)
using namespace std;
typedef pair<int,char> paic;
typedef pair<int,int> pai;
typedef pair<pai,int> paii;
typedef pair<pai,pai> ppai;
typedef pair<ppai,int> ppaii;
pai operator+(const pai &x,const pai &y) {return pai(x.x+y.x,x.y+y.y);}
pai operator-(const pai &x,const pai &y) {return pai(x.x-y.x,x.y-y.y);}
#define gh() getchar()
inline long long read() {
char ch=gh();
long long x=0;
char t=0;
while(ch<'0'||ch>'9') t|=ch=='-',ch=gh();
while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
return t?-x:x;
}
void write(ll x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) write(x/10);
putchar(x%10^48);
return ;
}
const int one=1;
int dp[2][2][25][1<<16],sta[25],len,l,r,k;
char typ[12],Typ[12],num[105];
int dfs1(int x,int f1,int f0,int S) {
if(x==0) return 1;
if(dp[f1][f0][x][S]!=-1) return dp[f1][f0][x][S];
int ans;
if(f0) ans=dfs1(x-1,0,1,0);
else ans=(S&1)?0:dfs1(x-1,f1&(!sta[x]),0,S|1);
for(int i=1;i<10;i++) {
if(S>>i&1) continue;
if(f1&&i>sta[x]) break;
ans+=dfs1(x-1,f1&(i==sta[x]),0,S|(1<<i));
}
return dp[f1][f0][x][S]=ans;
}
int dfs2(int x,int f1,int f0,int S) {
if(x==0) return 1;
if(dp[f1][f0][x][S]!=-1) return dp[f1][f0][x][S];
int ans;
if(f0) ans=dfs2(x-1,0,1,0);
else ans=(S&1)?0:dfs2(x-1,f1&(!sta[x]),0,S&1);
for(int i=1;i<16;i++) {
if(S>>i&1) continue;
if(f1&&i>sta[x]) break;
ans+=dfs2(x-1,f1&(i==sta[x]),0,S|(1<<i));
}
return dp[f1][f0][x][S]=ans;
}
int solve1(int x) {
len=0;
while(x) sta[++len]=x%10,x/=10;
memset(dp[1],-1,sizeof(dp[1]));
return dfs1(len,1,1,0);
}
int solve2(int x) {
len=0;
while(x) sta[++len]=x%16,x/=16;
memset(dp[1],-1,sizeof(dp[1]));
return dfs2(len,1,1,0);
}
char id(int x) {
if(x<10) return x+'0';
return x-10+'a';
}
int id2(char x) {
if(isdigit(x)) return x^48;
return x-'a'+10;
}
int calc(char *a) {
int l=strlen(a);
int ans=0;
for(int i=0;i<l;i++) ans=ans*16+id2(a[i]);
return ans;
}
void print(int x) {
if(x>=16) print(x/16);
putchar(id(x%16));
return ;
}
void solve() {
memset(dp,-1,sizeof(dp));
scanf("%s",typ),scanf("%s",Typ);
if(typ[0]=='d') {
if(Typ[0]=='0') {//10th count
l=read(),r=read(),l--;
wr(solve1(r)-solve1(l),'\n');
} else {//10th kth
k=read();
int l=0,r=one<<70,mid;
while(l<r) {
mid=l+r>>1;
// wr(mid,' '),wr(solve1(mid),'\n');
if(solve1(mid)<k) l=mid+1;
else r=mid;
}
if(solve1(l)==k) wr(l,'\n');
else puts("-");
}
} else {
if(Typ[0]=='0') {//16th count
scanf("%s",num),l=calc(num)-1;
scanf("%s",num),r=calc(num);
print(solve2(r)-solve2(l)),putchar('\n');
} else {//16th kth
scanf("%s",num);
k=calc(num);
int l=0,r=one<<70,mid;
while(l<r) {
mid=l+r>>1;
if(solve2(mid)<k) l=mid+1;
else r=mid;
}
if(solve2(l)==k) print(l),putchar('\n');
else puts("-");
}
}
return ;
}
signed main() {
int Test=read();
while(Test--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 873ms
memory: 106116kb
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...