QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#709607#8030. Traveling in the Grid WorldUESTC_DECAYALI#WA 0ms3872kbC++201.0kb2024-11-04 15:45:202024-11-04 15:45:20

Judging History

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

  • [2024-11-04 15:45:20]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3872kb
  • [2024-11-04 15:45:20]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cassert>
#define int long long
#define RI register int
#define CI const int&
using namespace std;
int t,n,m;
signed main()
{
    for (scanf("%lld",&t);t;--t)
    {
        scanf("%lld%lld",&n,&m);
        int g=__gcd(n,m);
        auto dist=[&](CI x,CI y)
        {
            return sqrt(1LL*x*x+1LL*y*y);
        };
        if (g==1) { printf("%.15lf\n",dist(n,m)); continue; }
        double ans=1e18;
        for (RI p=1;p<=n;++p)
        {
            int q=1LL*m*p/n;
            if (__gcd(p,q)!=1||__gcd(n-p,m-q)!=1||(p==n-p&&q==m-q))
            {
                //do nothing
            } else ans=min(ans,dist(p,q)+dist(n-p,m-q));
        }
        for (RI q=1;q<=m;++q)
        {
            int p=1LL*n*q/m;
            if (__gcd(p,q)!=1||__gcd(n-p,m-q)!=1||(p==n-p&&q==m-q))
            {
                //do nothing
            } else ans=min(ans,dist(p,q)+dist(n-p,m-q));
        }
        printf("%.15lf\n",ans);
    }
    return 0;
}

詳細信息

Test #1:

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

input:

2
2 2
2 3

output:

1000000000000000000.000000000000000
3.605551275463989

result:

wrong answer 1st numbers differ - expected: '3.2360680', found: '1000000000000000000.0000000', error = '309016994374947392.0000000'