QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#573482#2519. Number with Bachelorstx344RE 26ms14840kbC++144.2kb2024-09-18 18:58:202024-09-18 18:58:23

Judging History

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

  • [2024-09-18 18:58:23]
  • 评测
  • 测评结果:RE
  • 用时:26ms
  • 内存:14840kb
  • [2024-09-18 18:58:20]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define Ull unsigned ll
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PPIII pair<PII,int>
#define PLPII pair<ll,PII>
#define fi first
#define se second
using namespace std;
int Q,num[21],nt;
ll f1[15][1<<10],f2[21][1<<16];
inline int id(char x){return x<='9'&&x>='0'?x-'0':x-'a'+10;}
ll DFS1(int i,int j,int S)
{
    if(!i)return 1;
    if(j>1&&~f1[i][S])return f1[i][S];
    ll sum=0;
    if(!j)sum+=DFS1(i-1,0,S);
    for(int o=!j;o<=((j==1||((!j&&i==nt)))?num[i]:9);o++)if(!(S>>o&1))
    {
        sum+=DFS1(i-1,((j==1||((!j&&i==nt)))&&o==num[i])?1:2,S^(1<<o));
    }
    if(j>1)f1[i][S]=sum;
    // if(i==nt)
    // {
    //     puts("-------------------------");
    //     for(int i=nt;i;i--)printf("%d ",num[i]);puts("");
    //     printf("%lld\n",sum);
    //     puts("-------------------------");
    // }
    return sum;
}
ll DFS2(int i,int j,int S)
{
    if(!i)return 1;
    if(j>1&&~f2[i][S])return f2[i][S];
    ll sum=0;
    if(!j)sum+=DFS2(i-1,0,S);
    for(int o=!j;o<=((j==1||((!j&&i==nt)))?num[i]:15);o++)if(!(S>>o&1))
    {
        sum+=DFS2(i-1,((j==1||((!j&&i==nt)))&&o==num[i])?1:2,S^(1<<o));
    }
    if(j>1)f2[i][S]=sum;
    // if(i==nt)
    // {
    //     puts("+++++++++++++++++++++++++");
    //     for(int i=nt;i;i--)printf("%d ",num[i]);puts("");
    //     printf("%lld\n",sum);
    //     puts("+++++++++++++++++++++++++");
    // }
    return sum;
}
ll Solve_d0()
{
    return DFS1(nt,0,0);
}
ll Solve_f0()
{
    return DFS2(nt,0,0);
}
void Solve_d1(Ull C)
{
    if(C>8877691)return puts("-"),void();
    memset(num,0,sizeof(num));
    bool Flag=0;
    for(int i=10;i;i--)
    {
        if(!Flag)nt=i;
        int l=1,r=9;
        while(l<=r)
        {
            int mid=l+r>>1;
            num[i]=mid;
            if(Solve_d0()<C)l=mid+1;
            else r=mid-1;
        }
        if(r)Flag=1;
        num[i]=r;
    }
    int sg=1;
    while(sg<=nt&&num[sg]==9)num[sg++]=0;
    if(sg<=nt)++num[sg];
    else num[++nt]=1;
    for(int i=nt;i;i--)printf("%d",num[i]);puts("");
}
void Solve_f1(Ull C)
{
    if(C>53319412081141)return puts("-"),void();
    memset(num,0,sizeof(num));
    bool Flag=0;
    for(int i=16;i;i--)
    {
        if(!Flag)nt=i;
        int l=1,r=15;
        while(l<=r)
        {
            int mid=l+r>>1;
            num[i]=mid;
            // for(int i=nt;i;i--)printf("%c",num[i]<10?num[i]+'0':num[i]-10+'a');puts("");
            // printf("%lld %lld\n",Solve_f0(),C);
            if(Solve_f0()<C)l=mid+1;
            else r=mid-1;
        }
        if(r)Flag=1;
        num[i]=r;
    }
    int sg=1;
    while(sg<=nt&&num[sg]==15)num[sg++]=0;
    if(sg<=nt)++num[sg];
    else num[++nt]=1;
    for(int i=nt;i;i--)printf("%c",num[i]<10?num[i]+'0':num[i]-10+'a');puts("");
}
void Print_f(ll x)
{
    if(x>15)Print_f(x/16);
    printf("%c",x%16<10?x%16+'0':x%16-10+'a');
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
	#endif
    
    memset(f1,-1,sizeof(f1));
    memset(f2,-1,sizeof(f2));
    scanf("%d",&Q);
    while(Q--)
    {
        char op1[5],x[21],y[21];
        int op2;
        Ull z=0;
        scanf("%s%d%s",op1,&op2,x);
        if(op2)
        {
            nt=strlen(x);
            for(int i=0;i<nt;i++)z=z*(op1[0]=='d'?10:16)+id(x[i]);
            // printf("z=%llu\n",z);
            if(op1[0]=='d')Solve_d1(z);
            else Solve_f1(z);
        }
        else
        {
            scanf("%s",y);
            nt=strlen(y);
            for(int i=0;i<nt;i++)num[nt-i]=id(y[i]);
            ll sum;
            if(op1[0]=='d')sum=Solve_d0();
            else sum=Solve_f0();
            nt=strlen(x);
            for(int i=0;i<nt;i++)num[nt-i]=id(x[i]);
            if(nt>1||num[1])
            {
                int sg=1;
                while(!num[sg])num[sg++]=op1[0]=='d'?9:15;
                if(!--num[sg]&&sg==nt)--nt;
                if(op1[0]=='d')sum-=Solve_d0();
                else sum-=Solve_f0();
            }
            if(op1[0]=='d')printf("%lld\n",sum);
            else Print_f(sum),puts("");
        }
    }
    
    cerr<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 26ms
memory: 14840kb

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
Runtime Error

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:


result: