QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573446#2519. Number with BachelorspzjQWQWA 36ms14028kbC++143.3kb2024-09-18 18:47:012024-09-18 18:47:07

Judging History

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

  • [2024-09-18 18:47:07]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:14028kb
  • [2024-09-18 18:47:01]
  • 提交

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(T--){
        char c;
        bool op;
        cin>>c>>op;
        ++cnt;
        if(cnt==51) cerr<<c<<' '<<op<<endl;
        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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 35ms
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:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 36ms
memory: 13968kb

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...

output:

1b36
43
6587
7710
953
3
8daab378500
26054
3
1356
-
946307
4681
40
387
-
-
-
491850
0
1
29
-
4605298
1
1
-
15b4
175f
9b944134000
124b7
6279
9
6257
-
39be22a900
5c636b59300
146ce
2a55
-
0
-
7
d
6
2041
-
1c94afe7300
0
5

result:

wrong answer 51st lines differ - expected: '9149', found: ''