QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#573930#2519. Number with BachelorspzjQWQWA 37ms13968kbC++143.3kb2024-09-18 20:20:342024-09-18 20:20:35

Judging History

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

  • [2024-09-18 20:20:35]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:13968kb
  • [2024-09-18 20:20:34]
  • 提交

answer

/*
进制转换练习题
*/
#include<bits/stdc++.h>
#define endl '\n'
#define int unsigned long long
using namespace std;
int T,cnt,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;
        ++cnt;
        if(c=='d'){
            if(!op){
                int l,r;
                cin>>l>>r;
                cout<<solve1(r)-(!l?1: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)-(!l?1:solve1(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;
}

详细

Test #1:

score: 0
Wrong Answer
time: 37ms
memory: 13968kb

input:

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

output:

10
10
9
e
-
-

result:

wrong answer 2nd lines differ - expected: 'f', found: '10'