QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#137944#6725. Pick UpYarema#WA 204ms6564kbC++171.8kb2023-08-10 19:27:392023-08-10 19:27:41

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 19:27:41]
  • Judged
  • Verdict: WA
  • Time: 204ms
  • Memory: 6564kb
  • [2023-08-10 19:27:39]
  • Submitted

answer


#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

struct point
{
	int x, y;
	
	point() {}
	point(int a, int b): x(a), y(b) {}
	
	LL dis(point p)
	{
		return LL(abs(x - p.x)) + abs(y - p.y);
	}
};

point A, B, C;
int dx, dy;
int p = 0;
const int N = 1 << 18;
LL ans[N];
int a[N], b[N];

LL f(point X)
{
	LL d1 = A.dis(X) * b[p];
	LL d2 = B.dis(X) * a[p];
	LL d3 = C.dis(X) * a[p];
	return max(d1, d2) + d3;
}

LL g(int st)
{
	int cx = (C.x - A.x);
	if (dx) cx /= dx;
	int cy = (C.y - A.y);
	if (dy) cy /= dy;
	
	point pt(A.x, A.y);
	pt.x += cx * min(st, dx);
	pt.y += cy * min(max(0, st - dx), dy);
	LL a1 = f(pt);
	
	pt = point(A.x, A.y);
	pt.x += cx * min(st, dy);
	pt.y += cy * min(max(0, st - dy), dx);
	LL res = min(a1, f(pt));
	ans[p] = min(res, ans[p]);
	return res;
}


void solve()
{
	cin >> a[p] >> b[p];
	cin >> A.x >> A.y;
	cin >> B.x >> B.y;
	cin >> C.x >> C.y;
	ans[p] = A.dis(C) * b[p];
	
	dx = abs(A.x - C.x);
	dy = abs(A.y - C.y);
	
	LL lx = 0, rx = dx + dy;
	while (lx + 4 < rx)
	{
		LL d = (rx - lx) / 2;
		LL m1 = lx + d;
		LL m2 = lx + d + 1;
		if (g(m1) < g(m2))
			rx = m2;
		else
			lx = m1;
	}
	FOR (i, lx, rx + 1)
		g(i);
	p++;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int t;
	cin >> t;
	//scanf("%d", &t);
	FOR (tt, 0, t)
	{
		solve();
	}
	cout << fixed << setprecision(7);
	FOR (i, 0, t) cout << double(ans[i]) / (a[i] * b[i]) << '\n';
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5680kb

input:

3
1 2
0 2 1 0 2 2
1 3
1 1 0 1 3 1
1 2
0 0 100 100 1 1

output:

1.5000000
1.0000000
2.0000000

result:

ok 3 numbers

Test #2:

score: -100
Wrong Answer
time: 204ms
memory: 6564kb

input:

100000
158260522 877914575
602436426 24979445 861648772 623690081 433933447 476190629
731963982 822804784
450968417 430302156 982631932 161735902 880895728 923078537
317063340 492686568
773361868 125660016 650287940 839296263 462224593 492601449
576823355 782177068
404011431 818008580 954291757 1604...

output:

-230034591.4466960
357225688.6932317
501578951.5648248
179827368.4032943
116356303.7670982
341157494.3668529
-1050979906.5895314
-627918246.8713715
-588589189.8225443
668430178.0667348
482293386.7295483
-1240483100.7113988
243210140.3956461
-284986555.2036806
195435029.7740800
23532061.4230757
-3980...

result:

wrong answer 1st numbers differ - expected: '1.3846072', found: '-230034591.4466960', error = '166137071.0492393'