QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#709533 | #8030. Traveling in the Grid World | UESTC_DECAYALI# | WA | 0ms | 3908kb | C++20 | 1.6kb | 2024-11-04 15:16:01 | 2024-11-04 15:16:02 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cassert>
#define RI register int
#define CI const int&
using namespace std;
int t,n,m;
int main()
{
for (scanf("%d",&t);t;--t)
{
scanf("%d%d",&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 ans1=1e18;
for (RI p=0;p<=n;++p)
{
for (RI q=1;q<=m;++q)
{
if (__gcd(p,q)!=1||__gcd(n-p,m-q)!=1||(p==n-p&&q==m-q)) continue;
ans1=min(ans1,dist(p,q)+dist(n-p,m-q)); break;
}
}
for (RI q=0;q<=m;++q)
{
for (RI p=1;p<=n;++p)
{
if (__gcd(p,q)!=1||__gcd(n-p,m-q)!=1||(p==n-p&&q==m-q)) continue;
ans1=min(ans1,dist(p,q)+dist(n-p,m-q)); break;
}
}
double ans2=dist(n/g,m/g),ret=1e18;
n-=n/g; m-=m/g;
for (RI p=0;p<=n;++p)
{
for (RI q=1;q<=m;++q)
{
if (__gcd(p,q)!=1||__gcd(n-p,m-q)!=1||(p==n-p&&q==m-q)) continue;
ret=min(ret,dist(p,q)+dist(n-p,m-q)); break;
}
}
for (RI q=0;q<=m;++q)
{
for (RI p=1;p<=n;++p)
{
if (__gcd(p,q)!=1||__gcd(n-p,m-q)!=1||(p==n-p&&q==m-q)) continue;
ret=min(ret,dist(p,q)+dist(n-p,m-q)); break;
}
}
printf("%.15lf\n",min(ans1,ans2+ret));
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3908kb
input:
2 2 2 2 3
output:
3.236067977499790 3.605551275463989
result:
ok 2 numbers
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3864kb
input:
225 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 ...
output:
1.414213562373095 2.236067977499790 3.162277660168380 4.123105625617661 5.099019513592784 6.082762530298219 7.071067811865476 8.062257748298549 9.055385138137417 10.049875621120890 11.045361017187261 12.041594578792296 13.038404810405298 14.035668847618199 15.033296378372908 2.236067977499790 3.2360...
result:
wrong answer 57th numbers differ - expected: '12.6652747', found: '12.6671094', error = '0.0001449'