QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#511002 | #4226. Cookie Cutter | RngBased# | WA | 2538ms | 4192kb | C++17 | 4.5kb | 2024-08-09 15:03:24 | 2024-08-09 15:03:26 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
pll operator+(pll a, pll b)
{
return pll(a.F + b.F, a.S + b.S);
}
pll operator-(pll a)
{
return pll(-a.F, -a.S);
}
pll operator-(pll a, pll b)
{
return pll(a.F - b.F, a.S - b.S);
}
pll operator*(pll a, double b)
{
return pdd(a.F * b, a.S * b);
}
pdd operator/(pll a, double b)
{
return pdd(a.F / b, a.S / b);
}
ll dot(pll a, pll b)
{
return a.F * b.F + a.S + b.S;
}
ll cross(pll a, pll b)
{
return a.F * b.S - a.S * b.F;
}
int sign(ll a)
{
return a == 0 ? 0 : (a < 0 ? -1 : 1);
}
int ori(pll a, pll b, pll c)
{
return sign(cross(b - a, c - a));
}
bool collinear(pll a, pll b, pll c)
{
return ori(a, b, c) == 0;
}
bool btw(pll a, pll b, pll c)
{
return collinear(a, b, c) && sign(dot(a - c, b - c)) <= 0;
}
bool is_intersect(pll p1, pll p2, pll p3, pll p4)
{
int a123 = ori(p1, p2, p3);
int a124 = ori(p1, p2, p4);
return a123 * a124 <= 0;
}
pdd intersect(pll p1, pll p2, pll p3, pll p4)
{
ll a123 = cross(p2 - p1, p3 - p1);
ll a124 = cross(p2 - p1, p4 - p1);
return (p4 * a123 - p3 * a124) / (a123 - a124);
}
#define is_neg(k) (sign(k.S) < 0 || (sign(k.S) == 0 && sign(k.F) < 0))
int cmp(pll a, pll b)
{
int A = is_neg(a), B = is_neg(b);
if (A != B)
return A < B;
if (sign(cross(a, b)) == 0)
return -1;
return sign(cross(a, b)) > 0;
}
int n, m;
pll p[3005];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++)
cin >> p[i].F >> p[i].S;
double ans = 0;
if (m == 1)
{
p[1].F = min(p[1].F, n - p[1].F);
p[1].S = min(p[1].S, n - p[1].S);
ans = 1 - 2.0 * p[1].F * p[1].S / n / n;
cout << fixed << setprecision(10) << ans << '\n';
return 0;
}
vector<pll> sq = {{0, 0}, {n, 0}, {n, n}, {0, n}}, sq3;
for (int t = 1; t <= 3; t++)
for (auto P : sq)
sq3.emplace_back(P);
for (int i = 1; i <= m; i++)
{
pll O = p[i];
vector<pair<pll, int>> v;
int in = 1;
for (int j = 1; j <= m; j++)
if (j != i)
{
pll vec = p[j] - O;
if (is_neg(vec))
in++;
v.emplace_back(vec, +1);
v.emplace_back(-vec, -1);
}
sort(all(v), [&](pair<pll, int> a, pair<pll, int> b)
{
if (cmp(a.F, b.F) == -1)
return a.S > b.S;
return (bool)cmp(a.F, b.F);
});
for (auto [P, t] : v)
if (t == -1)
in--;
else
{
in++;
pll A = O + P, B = O;
for (int j = 4; j < 8; j++)
if (ori(A, B, sq3[j]) > 0)
{
deque<pdd> poly = {sq3[j]};
for (int k = j - 1;; k--)
if (is_intersect(A, B, sq3[k], sq3[k + 1]))
{
poly.emplace_front(intersect(A, B, sq3[k], sq3[k + 1]));
break;
}
else
poly.emplace_front(pdd(sq3[k]));
for (int k = j + 1;; k++)
if (is_intersect(A, B, sq3[k], sq3[k - 1]))
{
poly.emplace_back(intersect(A, B, sq3[k], sq3[k - 1]));
break;
}
else
poly.emplace_back(sq3[k]);
double area = 0;
int k = (int)poly.size();
for (int l = 0; l < k; l++)
{
auto [x1, y1] = poly[l];
auto [x2, y2] = poly[(l + 1) % k];
area += .5 * (x1 * y2 - x2 * y1);
}
ans = max(ans, double(in) / m - area / n / n);
break;
}
}
}
cout << fixed << setprecision(10) << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3948kb
input:
5 8 1 1 1 2 1 3 2 1 3 1 3 4 4 1 4 2
output:
0.3750000000
result:
ok found '0.3750000', expected '0.3750000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 2163ms
memory: 4120kb
input:
10000 2916 93 93 93 278 93 463 93 649 93 834 93 1019 93 1204 93 1389 93 1574 93 1760 93 1945 93 2130 93 2315 93 2500 93 2685 93 2871 93 3056 93 3241 93 3426 93 3611 93 3796 93 3982 93 4167 93 4352 93 4537 93 4722 93 4907 93 5093 93 5278 93 5463 93 5648 93 5833 93 6018 93 6204 93 6389 93 6574 93 6759...
output:
0.0093444444
result:
ok found '0.0093444', expected '0.0093444', error '0.0000000'
Test #3:
score: 0
Accepted
time: 2175ms
memory: 4124kb
input:
10000 2916 1000 1000 1000 1151 1000 1302 1000 1453 1000 1604 1000 1755 1000 1906 1000 2057 1000 2208 1000 2358 1000 2509 1000 2660 1000 2811 1000 2962 1000 3113 1000 3264 1000 3415 1000 3566 1000 3717 1000 3868 1000 4019 1000 4170 1000 4321 1000 4472 1000 4623 1000 4774 1000 4925 1000 5075 1000 5226...
output:
0.1000000000
result:
ok found '0.1000000', expected '0.1000000', error '0.0000000'
Test #4:
score: 0
Accepted
time: 2168ms
memory: 3904kb
input:
10000 2916 50 50 50 237 50 424 50 610 50 797 50 984 50 1171 50 1358 50 1544 50 1731 50 1918 50 2105 50 2292 50 2478 50 2665 50 2852 50 3039 50 3225 50 3412 50 3599 50 3786 50 3973 50 4159 50 4346 50 4533 50 4720 50 4907 50 5093 50 5280 50 5467 50 5654 50 5841 50 6027 50 6214 50 6401 50 6588 50 6775 ...
output:
0.0135185185
result:
ok found '0.0135185', expected '0.0135185', error '0.0000000'
Test #5:
score: 0
Accepted
time: 1460ms
memory: 4024kb
input:
3000 2999 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52...
output:
0.5000000000
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #6:
score: 0
Accepted
time: 2531ms
memory: 4192kb
input:
10000 3000 2291 3747 7077 9024 8698 5564 5000 4856 7265 103 6672 3043 1458 8108 17 7872 7084 6565 3127 304 6905 9627 5572 6607 1922 489 2273 7798 2548 7044 3082 4225 4242 2287 6284 2489 4802 3096 6902 8724 49 5126 5275 1878 2269 3237 9323 8048 1174 5680 5992 6262 609 433 6690 2531 9430 5618 5410 210...
output:
0.0301991336
result:
ok found '0.0301991', expected '0.0301991', error '0.0000000'
Test #7:
score: 0
Accepted
time: 2538ms
memory: 4032kb
input:
10000 3000 156 1582 2398 3319 7701 5829 4040 1938 7464 4347 111 9210 6412 541 4390 4151 2359 7197 2606 1160 594 722 1473 5727 3781 5857 3468 5814 3980 6917 1106 1389 6968 9552 9538 7438 1704 9872 9004 2595 7285 1722 3217 5133 7389 4704 7724 5553 7584 4281 4362 4220 4361 5456 7241 9044 9942 5132 9582...
output:
0.0275047475
result:
ok found '0.0275047', expected '0.0275047', error '0.0000000'
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3856kb
input:
5 2 2 3 1 4
output:
0.5000000000
result:
wrong answer 1st numbers differ - expected: '0.6800000', found: '0.5000000', error = '0.1800000'