QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#309630 | #8030. Traveling in the Grid World | algotester# | WA | 0ms | 3892kb | C++23 | 1.6kb | 2024-01-20 19:22:21 | 2024-01-20 19:22:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;
#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define MP make_pair
int gcd(int a, int b)
{
return a == 0 ? b : gcd(b % a, a);
}
double dist(double a, double b)
{
return sqrt(a*a + b*b);
}
double f(double best, int n, int m, int r, int c)
{
if(r < 0 || n < r) return best;
if(c < 0 || m < c) return best;
if(r == 0 && c == 0) return best;
if(r == n && c == m) return best;
if(r == n - r && c == m - c) return best;
if(gcd(r, c) != 1) return best;
if(gcd(n - r, m - c) != 1) return best;
return min(best, dist(r, c) + dist(n - r, m - c));
}
double f(int n, int m)
{
if(gcd(n, m) == 1) return dist(n, m);
int i, j;
double inf = 1e47;
double res = inf;
FOR(i, 0, n + 1)
{
Int t = i;
t *= n;
t /= m;
FOR(j, 0, 2)
{
int c = int(t) + j;
res = f(res, n, m, i, c);
}
}
FOR(i, 0, m + 1)
{
Int t = i;
t *= m;
t /= n;
FOR(j, 0, 2)
{
int r = int(t) + j;
res = f(res, n, m, r, i);
}
}
assert(res != inf);
return res;
}
void SolveTest(int test)
{
int n, m;
cin >> n >> m;
cout << fixed << setprecision(14) << f(n, m) << endl;
}
int main()
{
int T, t;
T = 1;
cin >> T;
FOR(t, 0, T)
{
//cerr << "Solving " << t << "/" << T << endl;
SolveTest(t);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3844kb
input:
2 2 2 2 3
output:
3.23606797749979 3.60555127546399
result:
ok 2 numbers
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3892kb
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.41421356237310 2.23606797749979 3.16227766016838 4.12310562561766 5.09901951359278 6.08276253029822 7.07106781186548 8.06225774829855 9.05538513813742 10.04987562112089 11.04536101718726 12.04159457879230 13.03840481040530 14.03566884761820 15.03329637837291 2.23606797749979 3.23606797749979 3.605...
result:
wrong answer 21st numbers differ - expected: '6.3591736', found: '6.3851648', error = '0.0040872'