QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#242192#7049. Base62Anwar#AC ✓41ms3852kbC++205.3kb2023-11-07 00:44:562023-11-07 00:44:56

Judging History

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

  • [2023-11-07 00:44:56]
  • 评测
  • 测评结果:AC
  • 用时:41ms
  • 内存:3852kb
  • [2023-11-07 00:44:56]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 1e5 + 3 , MOD =  1e9 + 7;

#define all(x)  x.begin() , x.end()

#define rep(i , st , en) for(int i = st ;i < en ; i++)

string  sub(string s,string ss)
{
    if(s.size()<ss.size())cout<<"-",swap(s,ss);
    else if(s.size()==ss.size() && s<ss)cout<<"-",swap(s,ss);
    vector<int>v1,v2,res;
    reverse(all(s));
    reverse(all(ss));
    rep(i,0,s.size())v1.push_back(s[i]-'0');
    rep(i,0,ss.size())v2.push_back(ss[i]-'0');
    while(v2.size()<v1.size())v2.push_back(0);
    while(res.size()<v1.size())res.push_back(0);
    res.push_back(0);
    rep(i,0,v1.size())
    {
        if(v1[i]>=v2[i])res[i]=v1[i]-v2[i];
        else
        {
            res[i]=10+v1[i]-v2[i];
            v1[i+1]--;
        }
    }
    while(res.size()>1 && res.back()==0)res.pop_back();
    reverse(all(res));
    s="";
    rep(i,0,res.size())s+=(char)(res[i]+'0');
    return s;
}
pair<string,string> div(string s,string ss)
{
    if(s.size()<ss.size())return {"0",s};
    else if(s.size()==ss.size() && s<ss)return {"0",s};
    else
    {
        vector<int>res;
        int r=0;
        string te="";
        while(1)
        {
            while(r<s.size() && te.size()<ss.size() && te!="0")te+=s[r],r++,res.push_back(0);
            if(te=="0")
            {
                res.push_back(0);
                if(r==s.size())
                {
                    s="0";
                    break;
                }
                te="";
                te+=s[r];
                r++;
                continue;
            }
            if(r==s.size())
            {
                if(te.size()<ss.size())
                {
                    s=te;
                    res.push_back(0);
                    break;
                }
                if(te.size()==ss.size() && ss>te)
                {
                    s=te;
                    res.push_back(0);
                    break;
                }
            }
            if(te.size()==ss.size() && ss>te && r<s.size())te+=s[r],r++,res.push_back(0);
            string tt = sub(te,ss);
            int divv=1;
            while(tt.size()>ss.size() || (tt.size()==ss.size() && tt>=ss))
            {
                divv++;
                tt=sub(tt,ss);
            }
            res.push_back(divv);


            if(r==s.size())
            {
                s=tt;
                break;
            }
            if(tt=="0")te=s[r];
            else te=tt+s[r];
            r++;
        }
        string divi="";
        reverse(all(res));
        while(res.size()>1 && res.back()==0)res.pop_back();
        reverse(all(res));
        rep(i,0,res.size())divi+=(char)(res[i]+'0');
        reverse(all(s));
        while(s.size()>1 && s.back()=='0')s.pop_back();
        reverse(all(s));
        return {divi,s};
    }
}

string add(string s,string ss)
{
    vector<int>v1,v2,res;
    reverse(all(s));
    reverse(all(ss));
    rep(i,0,s.size())v1.push_back(s[i]-'0');
    rep(i,0,ss.size())v2.push_back(ss[i]-'0');
    while(v1.size()<v2.size())v1.push_back(0);
    while(v2.size()<v1.size())v2.push_back(0);
    while(res.size()<v1.size())res.push_back(0);
    int carry=0;
    rep(i,0,v1.size())
    {
        int sum=v1[i]+v2[i]+carry+res[i];
        res[i]=sum%10;
        carry=sum/10;
    }
    if(carry)
    {
        res.push_back(carry);
    }
    reverse(all(res));
    string te="";
    rep(i,0,res.size())te+=(char)(res[i]+'0');
    return te;
}
string mul(string s,string ss)
{
    if(s.size()<ss.size())swap(s,ss);
    vector<int>v1,v2,res;
    reverse(all(s));
    reverse(all(ss));
    rep(i,0,s.size())v1.push_back(s[i]-'0');
    rep(i,0,ss.size())v2.push_back(ss[i]-'0');
    rep(i,0,s.size()+ss.size())res.push_back(0);
    rep(i,0,v2.size())
    {
        rep(j,0,v1.size())
        {
            int sum = v1[j]*v2[i];
            sum+=res[i+j];
            res[i+j]=sum%10;
            res[i+j+1]+=sum/10;
        }
        int j=v1.size(),carry=res[i+j];
        while(carry)
        {
            int sum=carry;
            res[i+j]=sum%10;
            carry = sum/10;
            j++;
        }
    }
    while(res.size()>1 && res.back()==0)res.pop_back();
    reverse(all(res));
    s="";
    rep(i,0,res.size())s+=(char)(res[i]+'0');
    return s;
}

string co(char c)
{
    if(isdigit(c)) return to_string(c - '0') ;
    if( c >= 'A' && c <= 'Z' ) return to_string( c - 'A' + 10 ) ;

    return to_string( c - 'a' + 36 ) ;
}

char co2(string s)
{
    int x = stoi(s) ;

    if(x < 10) return '0' + x;

    if( x < 36 ) return 'A' + x - 10 ;

    return 'a' + x - 36 ;
}

int32_t main() {

    cin.tie(0);cin.sync_with_stdio(0);
    cout.tie(0);cout.sync_with_stdio(0);

    int  x , y ;
    cin >> x >> y ;

    string z ;
    cin >> z;

    string zz = "" ;
    string xx = to_string(x) ;
    string yy = to_string(y) ;

    for(char c : z)
    {
        zz = add ( mul( zz,  xx ) , co(c) ) ;
    }

    pair<string , string > d = div( zz , yy ) ;
    string res = "" ;
    res += co2( d.second)  ;

    while ( d.first != "0" )
    {
        d = div( d.first , yy ) ;

        res += co2( d.second)  ;
    }

    reverse(res.begin() , res.end()) ;

    cout << res;

    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

input:

16 2 FB

output:

11111011

result:

ok single line: '11111011'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3844kb

input:

62 2 abcdefghiz

output:

11011100000100010111110010010110011111001001100011010010001

result:

ok single line: '11011100000100010111110010010110011111001001100011010010001'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3632kb

input:

10 16 1234567890123456789012345678901234567890

output:

3A0C92075C0DBF3B8ACBC5F96CE3F0AD2

result:

ok single line: '3A0C92075C0DBF3B8ACBC5F96CE3F0AD2'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3512kb

input:

16 35 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2

output:

333YMHOUE8JPLT7OX6K9FYCQ8A

result:

ok single line: '333YMHOUE8JPLT7OX6K9FYCQ8A'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

35 23 333YMHOUE8JPLT7OX6K9FYCQ8A

output:

946B9AA02MI37E3D3MMJ4G7BL2F05

result:

ok single line: '946B9AA02MI37E3D3MMJ4G7BL2F05'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

23 49 946B9AA02MI37E3D3MMJ4G7BL2F05

output:

1VbDkSIMJL3JjRgAdlUfcaWj

result:

ok single line: '1VbDkSIMJL3JjRgAdlUfcaWj'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3512kb

input:

61 5 dl9MDSWqwHjDnToKcsWE1S

output:

42104444441001414401221302402201233340311104212022133030

result:

ok single line: '42104444441001414401221302402201233340311104212022133030'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

5 10 42104444441001414401221302402201233340311104212022133030

output:

1234567890123456789012345678901234567890

result:

ok single line: '1234567890123456789012345678901234567890'

Test #9:

score: 0
Accepted
time: 5ms
memory: 3592kb

input:

62 10 123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

output:

361097996547231939420324315862125604148156665886431480862914942937732101183106158332978897913678986703118641

result:

ok single line: '361097996547231939420324315862...6158332978897913678986703118641'

Test #10:

score: 0
Accepted
time: 4ms
memory: 3560kb

input:

10 62 361097996547231939420324315862125604148156665886431480862914942937732101183106158332978897913678986703118641

output:

123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

result:

ok single line: '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'

Test #11:

score: 0
Accepted
time: 1ms
memory: 3852kb

input:

62 2 1000000000000

output:

101011101110010101110010000011101110100000110000011010000001000000000000

result:

ok single line: '101011101110010101110010000011...0110000011010000001000000000000'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3516kb

input:

62 2 0

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 41ms
memory: 3648kb

input:

62 2 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

output:

101101010111011101011010100010010111100101010100101110001000001101101111000000111101111101011101101111010000100001111110100110110110001101010010101000000011010000100100110101000110110010001110001011001111001100001101010010001111001100110100110110111101001010111100010010011111110111111000010011110010...

result:

ok single line: '101101010111011101011010100010...1111111111111111111111111111111'