ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213298 | #3847. 分数约分 | drdilyor | 60 | 3325ms | 1232kb | C++11 | 1.6kb | 2024-11-10 12:49:40 | 2024-11-10 13:08:45 |
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI\n";}
inline int read(){
int n=0,f=1,ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
n=n*10+ch-'0';
ch=getchar();
}
return n*f;
}
void solve(){
string a,b;
cin>>a>>b;
int ta=0,tb=0;
int la=(int)a.size(),lb=(int)b.size();
for(int i=0;i<la;i++)ta=ta*10+a[i]-'0';
for(int i=0;i<lb;i++)tb=tb*10+b[i]-'0';
int cnt[10]={0};
for(int i=0;i<lb;i++)cnt[b[i]-'0']++;
int p=ta;
for(int i=1;i<(1<<la);i++){
int r=0;
int vv[10]={0};
for(int j=0;j<la;j++){
if(i&(1<<j)){
r=r*10+a[j]-'0';
}
else vv[a[j]-'0']++;
}
if(!r)continue;
int gg=__gcd(ta,tb);
if((r)%(ta/gg)==0){
int del=lb-(la-__builtin_popcount(i));
int g=(tb/gg)*(r/(ta/gg));
string pp="";
int cnt2[10]={0};
while(g)pp+=char(g%10+'0'),cnt2[g%10]++,g/=10,del--;
if(del<0)continue;
//if(r==21)cout<<del<<"\n";
for(int j=1;j<=del;j++){
pp+='0';
}
reverse(pp.begin(),pp.end());
cnt2[0]+=del;
bool o=1;
for(int j=0;j<10;j++){
if(cnt[j]<cnt2[j]||cnt[j]-cnt2[j]!=vv[j]){
o=0;break;
}
}
if(o){
int x=0;
for(int j=0;j<(int)b.size();j++){
if(x<(int)pp.size()&&b[j]==pp[x]){
x++;
}
}
if(x==(int)pp.size())p=min(p,r);
}
//ta->r
//tb->
}
//留下来.
}
cout<<p<<" "<<tb/(ta/p)<<"\n";
}
signed main(){
int t=read();
while(t--)solve();
return 0;
}
//look at my code
//my code is amazing
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 1232kb
input:
10 295227892 738069730 21284157 63852471 312774536 781936340 82221828 68518190 167752458 55917486 90...
output:
295227892 738069730 21 63 31277456 86881815 822228 692102 167752458 55917486 904 7232 171 1197 24114...
result:
wrong answer 6th numbers differ - expected: '78193640', found: '86881815'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 1228kb
input:
10 7231248 1807812 4301415 3441132 1931046 3862092 5184264 3240165 1144774 1717161 298584 2388672 87...
output:
324 81 4301415 3441132 193146 429121 518424 324016 1144774 1717161 298584 2388672 878 7902 370928 29...
result:
wrong answer 6th numbers differ - expected: '386292', found: '429121'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1232kb
input:
10 72320000 27120000 110000 11000000 90100000 9010000 270000 75600000 8230000 82300000 17910000 5970...
output:
32 12 1 100 10 1 2 560 2 20 171 57 893 94 60 6 7 70 434 620
result:
ok 20 numbers
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 1232kb
input:
10 6700512 10050768 6712050 10068075 7172058 10758087 9318720 13978080 71635224 107452836 71643522 1...
output:
670512 1116752 671250 1118675 717258 1195343 931872 1397808 3522 5283 3522 5283 7192128 10798819 717...
result:
wrong answer 2nd numbers differ - expected: '1005768', found: '1116752'
Test #5:
score: 10
Accepted
time: 405ms
memory: 1232kb
input:
10 44896548685746979 44896548685746979 76555658957975878 76555658957975878 9999998899899899 99999988...
output:
4 4 5 5 8 8 5 5 2 2 8 8 8 8 1 1 4 4 9 9
result:
ok 20 numbers
Test #6:
score: 10
Accepted
time: 386ms
memory: 1232kb
input:
10 5586978859946748 5586978859946748 5875932326322532 5875932326322532 7877997999879887 787799799987...
output:
4 4 2 2 7 7 9 9 4 4 6 6 8 8 4 4 7 7 4 4
result:
ok 20 numbers
Test #7:
score: 10
Accepted
time: 795ms
memory: 1232kb
input:
10 163163163163163 326326326326326 163163111163111 326326222326222 142847142847 285714285714 2857142...
output:
11111 22222 111111111 222222222 142847142847 285714285714 285714 714285 8 4 432106661661438007 38112...
result:
ok 20 numbers
Test #8:
score: 0
Time Limit Exceeded
input:
10 142847114287112857 285714228574225714 142847111111112857 285714222222225714 142847111111111111 28...
output:
142847114287112857 285714228574225714 142847111111112857 285714222222225714 142847111111111111 28571...
result:
Test #9:
score: 10
Accepted
time: 783ms
memory: 1232kb
input:
10 687069149440626451 336182506802090732 216198376277246428 246457923661369649 43706817238884428 372...
output:
687069149440626451 336182506802090732 216198376277246428 246457923661369649 43706817238884428 372089...
result:
ok 20 numbers
Test #10:
score: 10
Accepted
time: 956ms
memory: 1232kb
input:
10 142847114247112857 285714228714225714 142847111111112857 285714222222225714 142847111111111111 28...
output:
142847114247112857 285714228714225714 142847111111112857 285714222222225714 142847111111111111 28571...
result:
ok 20 numbers