QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573988#2519. Number with BachelorspzjQWQWA 34ms14028kbC++143.3kb2024-09-18 20:30:532024-09-18 20:30:53

Judging History

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

  • [2024-09-18 20:30:53]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:14028kb
  • [2024-09-18 20:30:53]
  • 提交

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;
    while(T--){
        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=0,r=0;
                --r;
                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=0,r=0;
                --r;
                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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 34ms
memory: 14028kb

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:

wrong answer 5th lines differ - expected: '-', found: ''