QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#199683 | #7049. Base62 | lyzqs# | AC ✓ | 2ms | 4024kb | C++14 | 2.9kb | 2023-10-04 13:42:25 | 2023-10-04 13:42:26 |
Judging History
answer
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <cmath>
#include <queue>
using namespace std;
#define x first
#define y second
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<double,double> PDD;
typedef pair<LD,int> PLDI;
typedef pair<LD,LD> PLDLD;
typedef pair<int,PII> PIII;
const int N = 200010,M=2*N,U=200000,P=13331,INF=1e9+10,mod=998244353;
const double PI=acos(-1);
char str[N];
vector<int> add(vector<int> &A, vector<int> &B)
{
if (A.size() < B.size()) return add(B, A);
vector<int> C;
int t = 0;
for (int i = 0; i < A.size(); i ++ )
{
t += A[i];
if (i < B.size()) t += B[i];
C.push_back(t % 10);
t /= 10;
}
if (t) C.push_back(t);
return C;
}
vector<int> sub(vector<int> &A, vector<int> &B)
{
vector<int> C;
for (int i = 0, t = 0; i < A.size(); i ++ )
{
t = A[i] - t;
if (i < B.size()) t -= B[i];
C.push_back((t + 10) % 10);
if (t < 0) t = 1;
else t = 0;
}
while (C.size() > 1 && C.back() == 0) C.pop_back();
return C;
}
vector<int> div(vector<int> &A, int b, int &r)
{
vector<int> C;
r = 0;
for (int i = A.size() - 1; i >= 0; i -- )
{
r = r * 10 + A[i];
C.push_back(r / b);
r %= b;
}
reverse(C.begin(), C.end());
while (C.size() > 1 && C.back() == 0) C.pop_back();
return C;
}
// C = A * b, A >= 0, b >= 0
vector<int> mul(vector<int> &A, int b)
{
vector<int> C;
int t = 0;
for (int i = 0; i < A.size() || t; i ++ )
{
if (i < A.size()) t += A[i] * b;
C.push_back(t % 10);
t /= 10;
}
while (C.size() > 1 && C.back() == 0) C.pop_back();
return C;
}
int p,q;
int get1(char c)
{
if(c>='0'&&c<='9') return c-'0';
else if(c>='A'&&c<='Z') return c-'A'+10;
else return c-'a'+36;
}
char get2(int x)
{
if(x>=0&&x<=9) return '0'+x;
else if(x>=10&&x<=35) return 'A'+x-10;
else return 'a'+x-36;
}
int main()
{
scanf("%d%d%s",&p,&q,str);
int len=strlen(str);
if(len==1&&str[0]=='0')
{
puts("0");
return 0;
}
vector<int> res;
res.push_back(0);
for(int i=len-1;i>=0;i--)
{
vector<int> temp;
temp.push_back(1);
for(int j=0;j<len-1-i;j++)
{
auto C=mul(temp,p);
temp=C;
}
int v=get1(str[i]);
auto C=mul(temp,v);
temp=C;
C=add(res,temp);
res=C;
}
vector<int> ans;
while(true)
{
if(res.size()==1&&res[0]==0) break;
int r;
auto C = div(res, q, r);
ans.push_back(r);
res=C;
}
for(int i=(int)ans.size()-1;i>=0;i--)
printf("%c",get2(ans[i]));
puts("");
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3800kb
input:
16 2 FB
output:
11111011
result:
ok single line: '11111011'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
62 2 abcdefghiz
output:
11011100000100010111110010010110011111001001100011010010001
result:
ok single line: '11011100000100010111110010010110011111001001100011010010001'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3704kb
input:
10 16 1234567890123456789012345678901234567890
output:
3A0C92075C0DBF3B8ACBC5F96CE3F0AD2
result:
ok single line: '3A0C92075C0DBF3B8ACBC5F96CE3F0AD2'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
16 35 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2
output:
333YMHOUE8JPLT7OX6K9FYCQ8A
result:
ok single line: '333YMHOUE8JPLT7OX6K9FYCQ8A'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3992kb
input:
35 23 333YMHOUE8JPLT7OX6K9FYCQ8A
output:
946B9AA02MI37E3D3MMJ4G7BL2F05
result:
ok single line: '946B9AA02MI37E3D3MMJ4G7BL2F05'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
23 49 946B9AA02MI37E3D3MMJ4G7BL2F05
output:
1VbDkSIMJL3JjRgAdlUfcaWj
result:
ok single line: '1VbDkSIMJL3JjRgAdlUfcaWj'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
61 5 dl9MDSWqwHjDnToKcsWE1S
output:
42104444441001414401221302402201233340311104212022133030
result:
ok single line: '42104444441001414401221302402201233340311104212022133030'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
5 10 42104444441001414401221302402201233340311104212022133030
output:
1234567890123456789012345678901234567890
result:
ok single line: '1234567890123456789012345678901234567890'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3728kb
input:
62 10 123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
output:
361097996547231939420324315862125604148156665886431480862914942937732101183106158332978897913678986703118641
result:
ok single line: '361097996547231939420324315862...6158332978897913678986703118641'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3680kb
input:
10 62 361097996547231939420324315862125604148156665886431480862914942937732101183106158332978897913678986703118641
output:
123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
result:
ok single line: '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
62 2 1000000000000
output:
101011101110010101110010000011101110100000110000011010000001000000000000
result:
ok single line: '101011101110010101110010000011...0110000011010000001000000000000'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
62 2 0
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 0ms
memory: 4024kb
input:
62 2 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
output:
101101010111011101011010100010010111100101010100101110001000001101101111000000111101111101011101101111010000100001111110100110110110001101010010101000000011010000100100110101000110110010001110001011001111001100001101010010001111001100110100110110111101001010111100010010011111110111111000010011110010...
result:
ok single line: '101101010111011101011010100010...1111111111111111111111111111111'