ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213265 | #3847. 分数约分 | X_X | 80 | 269ms | 1196kb | C++ | 1.2kb | 2024-11-10 10:24:42 | 2024-11-10 13:05:02 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 i128;
const int N=22;
int n,m,cnt[N];
LL x,y,ans=2e18,ans2=2e18;
int a[N],b[N];
void work(int u,LL sum){
if(u>n){
if(!sum) return;
i128 A=x,B=y,C=sum;
i128 D=B*C/A;
if(D*A!=B*C) return;
LL id=D,cp=id;
bool flag=0;
while(cp){
if(!cnt[cp%10]) flag=1;
cnt[cp%10]--,cp/=10;
}
cp=id;
while(cp)
cnt[cp%10]++,cp/=10;
if(flag) return;
cp=id;
for(int i=m;i>=1;i--)
if(b[i]==id%10) id/=10;
if(!id) ans=min(ans,sum),ans2=min(ans2,cp);
return;
}
work(u+1,sum*10+a[u]);
if(cnt[a[u]]){
cnt[a[u]]--;
work(u+1,sum);
cnt[a[u]]++;
}
}
int Main()
{
ans=1e18,ans2=1e18;n=m=0;
memset(cnt,0,sizeof cnt);
scanf("%lld%lld",&x,&y);
LL tx=x,ty=y;
while(x) a[++n]=x%10,x/=10;
for(int i=1;i<=n/2;i++) swap(a[i],a[n-i+1]);
while(y) b[++m]=y%10,cnt[y%10]++,y/=10;
x=tx,y=ty;
for(int i=1;i<=m/2;i++) swap(b[i],b[m-i+1]);
work(1,0);
printf("%lld %lld\n",ans,ans2);
return 0;
}
int main()
{
int Case=1;
scanf("%d",&Case);
while(Case--) Main();
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1192kb
input:
10 295227892 738069730 21284157 63852471 312774536 781936340 82221828 68518190 167752458 55917486 90...
output:
295227892 738069730 21 63 31277456 78193640 822228 685190 167752458 55917486 904 7232 171 1197 24114...
result:
ok 20 numbers
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 1192kb
input:
10 7231248 1807812 4301415 3441132 1931046 3862092 5184264 3240165 1144774 1717161 298584 2388672 87...
output:
324 81 15 12 193146 386292 518424 324015 1144774 1717161 298584 2388672 878 7902 370928 2967424 4414...
result:
wrong answer 3rd numbers differ - expected: '4301415', found: '15'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1196kb
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: 1192kb
input:
10 6700512 10050768 6712050 10068075 7172058 10758087 9318720 13978080 71635224 107452836 71643522 1...
output:
12 18 12 18 12 18 12 18 12 18 12 18 12 18 12 18 12 18 12 18
result:
wrong answer 1st numbers differ - expected: '670512', found: '12'
Test #5:
score: 10
Accepted
time: 122ms
memory: 1196kb
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: 113ms
memory: 1196kb
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: 8ms
memory: 1192kb
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: 10
Accepted
time: 8ms
memory: 1196kb
input:
10 142847114287112857 285714228574225714 142847111111112857 285714222222225714 142847111111111111 28...
output:
142847114287112857 285714228574225714 142847111111112857 285714222222225714 142847111111111111 28571...
result:
ok 20 numbers
Test #9:
score: 10
Accepted
time: 5ms
memory: 1192kb
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: 13ms
memory: 1196kb
input:
10 142847114247112857 285714228714225714 142847111111112857 285714222222225714 142847111111111111 28...
output:
142847114247112857 285714228714225714 142847111111112857 285714222222225714 142847111111111111 28571...
result:
ok 20 numbers