QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#605593 | #8030. Traveling in the Grid World | ucup-team3519# | WA | 0ms | 3956kb | C++17 | 1.8kb | 2024-10-02 18:07:27 | 2024-10-02 18:07:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
typedef pair<int, int> pi;
#define fi first
#define se second
#define V vector
#define pb push_back
#define all1(x) (x).begin() + 1, (x).end()
#define all0(x) (x).begin(), (x).end()
db dis2(LL x, LL y, LL a, LL b) {
return sqrt(1LL * (x - a) * (x - a) + 1LL * (y - b) * (y - b));
}
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
mt19937 mrand(chrono::steady_clock().now().time_since_epoch().count());
using i64 = int64_t;
i64 gcd(i64 a, i64 b) {
return b ? gcd(b, a % b) : a;
}
void solve() {
cout << fixed << setprecision(12);
LL n, m;
cin >> n >> m;
if (n > m)
swap(n, m);
startTime = clock();
if (__gcd(n, m) == 1) {
cout << dis2(0, 0, n, m) << "\n";
return;
}
db ans = 1e18;
for (LL i = 0; i <= n; i++) {
LL base = (1LL * m * i + n - 1) / n - 1;
LL x = base;
while (x >= 0 && (gcd(i, x) != 1 || gcd(n - i, m - x) != 1))
x--;
if (x >= 0) {
ans = min(ans, dis2(0, 0, i, x) + dis2(i, x, n, m));
// cout << i << " " << x << endl;
}
x = base + 1;
if (1LL * x * n == 1LL * i * m)
x++;
while (x <= m && (gcd(i, x) != 1 || gcd(n - i, m - x) != 1))
x++;
if (x <= m) {
ans = min(ans, dis2(0, 0, i, x) + dis2(i, x, n, m));
// cout << i << " " << x << endl;
}
// if(i % 100 == 0) cout << i << endl;
}
cout << ans << "\n";
cout << getCurrentTime() << endl;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t;
cin >> t;
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3956kb
input:
2 2 2 2 3
output:
3.236067977500 0.000000000000 3.605551275464
result:
wrong answer 2nd numbers differ - expected: '3.6055513', found: '0.0000000', error = '1.0000000'