QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788362#9622. 有限小数EvanWA 0ms3740kbC++231.2kb2024-11-27 16:41:072024-11-27 16:41:07

Judging History

This is the latest submission verdict.

  • [2024-11-27 16:41:07]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3740kb
  • [2024-11-27 16:41:07]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define gcd __gcd
const int maxd=1E9;
void solve()
{
    int a,b,c=1E18,d=0;
    scanf("%lld %lld",&a,&b);
    int k=b;
    while(k%2==0){k=k/2;}
    while(k%5==0){k=k/5;}
    if(k==1)
    {
        printf("0 1\n");return;
    }
    map<int,int> mp;
    priority_queue<int,vector<int>,greater<int>> pq;
    mp[b]=1;
    pq.push(b);pq.push(k);
    while(!pq.empty())
    {
        int x=pq.top();pq.pop();
        if(x!=k){
        if(5*x<=maxd&&!mp[5*x])
        {
            mp[5*x]=1;
            pq.push(5*x);
        }
        if(2*x<=maxd&&!mp[2*x])
        {
            mp[2*x]=1;
            pq.push(2*x);
        }
        }
        int l=0,r=1E18/k;
        int y=a*x/b;
        while(l<r)
        {
            int mid=(l+r)/2;
            if(mid*k<y){l=mid+1;}
            else{r=mid;}
        }
        while(l*k<y){l++;}
        int o=l*k-y;
        int m=gcd(o,x);
        o=o/m;x=x/m;
        if(o<c){c=o;d=x;}
    }
    printf("%lld %lld\n",c,d);
}

signed main()
{
    int tt;
    scanf("%lld",&tt);
    while(tt--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3740kb

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
4 7
60 79

result:

wrong answer Jury found better answer than participant's 1 < 4 (Testcase 3)