QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574079#2519. Number with BachelorscqbztzlWA 46ms111620kbC++142.2kb2024-09-18 20:44:462024-09-18 20:44:48

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 20:44:48]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:111620kb
  • [2024-09-18 20:44:46]
  • 提交

answer

// 
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
using namespace std;
int T,tp,cnt,num[105];
ull dp[105][(1<<16)+5][2];
ull dfs(int x,bool lim,int now){
    if(!x)return 1;
    if(!lim&&dp[x][now][(tp==10)?0:1]!=-1)return dp[x][now][(tp==10)?0:1];
	ull res=0;
    for(int i=0;i<=(lim?num[x]:tp-1);i++){
        if((now>>i)&1)continue;
        if(now==0&&i==0)res+=dfs(x-1,lim&&i==num[x],now);
        else res+=dfs(x-1,lim&&i==num[x],now|(1<<i));
    }
    if(!lim)dp[x][now][(tp==10)?0:1]=res;
    return res;
}
ull Get(ull x){
    cnt=0;
    while(x)num[++cnt]=x%tp,x/=tp;
    return dfs(cnt,1,0);
}
ull read(){
    ull x=0;
    char s[22];
    scanf("%s",s+1);
    int len=strlen(s+1);
    for(int i=1;i<=len;i++) {
        if(s[i]<='9'&&s[i]>='0')x=x*tp+s[i]-'0';
        else x=x*tp+s[i]-'a'+10;
    }
    return x;
}
void print(ull x){
    if(x==0){
        printf("0\n");
        return ;
    }
    if(tp==10)printf("%llu\n", x);
    else{
        vector<int>ans;
        while(x){
            ans.push_back(x%tp);
            x/=tp;
        }
        for(int i=ans.size()-1;i>=0;i--){
            if(ans[i]>=10)printf("%c",ans[i]-10+'a');
            else printf("%c",ans[i]+'0');
        }
        printf("\n");
    }
}
signed main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%d",&T);
    while(T--){
        char op[10];
        scanf("%s",op);
        if(op[0]=='d')tp=10;
        else tp=16;
        int fff;
        scanf("%d",&fff);
        if(!fff){
            ull a=read(),b=read();
            ull ans=Get(b);
            if(a>0)ans-=Get(a-1);
            print(ans);
        }
        else{
            ull x=read();
            if(x<10){
                printf("%llu\n",x-1);
                continue;
            }
            ull l=0,r=0,ans=0;
			r--;
            if(Get(r)<x){
                printf("-\n");
                continue;
            }
            while(l<=r){
                ull mid=(l+r)>>1;
                if(Get(mid)>=x){
                	ans=mid;
                	r=mid-1;
				}
				else l=mid+1;
            }
            print(ans);
        }
    }
}

详细

Test #1:

score: 0
Wrong Answer
time: 46ms
memory: 111620kb

input:

6
d 0 10 20
h 0 10 1f
d 1 10
h 1 f
d 1 1000000000
h 1 ffffffffffffffff

output:

9
10
1f
9
e
-

result:

wrong answer 1st lines differ - expected: '10', found: '9'