QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#375936 | #4226. Cookie Cutter | 8BQube# | WA | 3967ms | 4200kb | C++20 | 4.6kb | 2024-04-03 18:04:28 | 2024-04-03 18:04:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define SZ(a) ((int)a.size())
#define double long double
typedef pair<double, double> pdd;
const double eps = 1e-10;
pll operator-(const pll &a, const pll &b) { return pll(a.X - b.X, a.Y - b.Y); }
pll operator+(const pll &a, const pll &b) { return pll(a.X + b.X, a.Y + b.Y); }
pdd operator-(const pdd &a, const pdd &b) { return pdd(a.X - b.X, a.Y - b.Y); }
pdd operator*(const pdd &a, const double &b) { return pdd(a.X * b, a.Y * b); }
pdd operator/(const pdd &a, const double &b) { return pdd(a.X / b, a.Y / b); }
template<class T>
T cross(const pair<T, T> &a, const pair<T, T> &b) { return a.X * b.Y - a.Y * b.X; }
template<class T>
T dot(const pair<T, T> &a, const pair<T, T> &b) { return a.X * b.X + a.Y * b.Y; }
template<class T>
T abs2(const pair<T, T> &a) { return dot(a, a); }
int sign(const ll &a) { return a == 0 ? 0 : a > 0 ? 1 : -1; }
int sign(const double &a) { return fabs(a) < eps ? 0 : a > 0 ? 1 : -1; }
template<class T>
int ori(const T &a, const T &b, const T &c) { return sign(cross(b - a, c - a)); }
bool line_seg_intersect(pdd p1, pdd p2, pdd p3, pdd p4) { // the four points should not colinear
int a123 = ori(p1, p2, p3);
int a124 = ori(p1, p2, p4);
if (a123 == 0 && a124 == 0) return false;
return a123 * a124 <= 0;
}
pdd intersect(pdd p1, pdd p2, pdd p3, pdd p4) {
double a123 = cross(p2 - p1, p3 - p1);
double a124 = cross(p2 - p1, p4 - p1);
return (p4 * a123 - p3 * a124) / (a123 - a124);
}
void hull(vector<pdd> &dots) {
sort(ALL(dots)), dots.resize(unique(ALL(dots)) - dots.begin());
vector<pdd> ans(1, dots[0]);
for (int ct = 0; ct < 2; ++ct, reverse(ALL(dots)))
for (int i = 1, t = SZ(ans); i < SZ(dots); ans.pb(dots[i++]))
while (SZ(ans) > t && ori(ans[SZ(ans) - 2], ans.back(), dots[i]) <= 0)
ans.pop_back();
if (SZ(ans) > 1)
ans.pop_back();
ans.swap(dots);
}
bool cmp(pll a, pll b) {
#define is_neg(k) (sign(k.Y) < 0 || (sign(k.Y) == 0 && sign(k.X) < 0))
int A = is_neg(a);
int B = is_neg(b);
if (A != B) return A < B;
if (sign(cross(a, b)) == 0)
return abs2(a) < abs2(b);
return sign(cross(a, b)) > 0;
}
pll arr[3005];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i)
cin >> arr[i].X >> arr[i].Y;
vector<pdd> square;
square.pb(pdd(0, 0));
square.pb(pdd(n, 0));
square.pb(pdd(n, n));
square.pb(pdd(0, n));
auto area = [&](pdd a, pdd b) {
vector<pdd> points;
for (int i = 0; i < SZ(square); ++i) {
if (ori(a, b, square[i]) >= 0)
points.pb(square[i]);
if (line_seg_intersect(a, b, square[i], square[(i + 1) % SZ(square)]))
points.pb(intersect(a, b, square[i], square[(i + 1) % SZ(square)]));
}
hull(points);
double res = 0;
for (int i = 0; i < SZ(points); ++i)
res += cross(points[i], points[(i + 1) % SZ(points)]);
return res;
};
double ans = 0;
auto chmax = [&](int cnt, double a) {
double val = (double)cnt / m - a / n / n;
//cerr << "get val " << cnt << ", " << a << " = " << val << "\n";
ans = max(ans, val);
};
for (int i = 0; i < m; ++i) {
// solve one
chmax(1, 2 * min(arr[i].X, n - arr[i].X) * min(arr[i].Y, n - arr[i].Y));
}
for (int base = 0; base < m; ++base) {
vector<pll> vec;
for (int i = 0; i < m; ++i)
if (i != base)
vec.pb(arr[i] - arr[base]);
sort(ALL(vec), cmp);
//for (auto [x, y] : vec)
//cerr << "(" << x << ", " << y << ") ";
//cerr << endl;
for (int i = 0, j = 0; i < SZ(vec); ++i) {
if (i == j) j = (j + 1) % SZ(vec);
while (i != j && (cross(vec[i], vec[j]) > 0 || (cross(vec[i], vec[j]) == 0 && (dot(vec[i], vec[j]) < 0 || abs2(vec[i]) < abs2(vec[j]))))) j = (j + 1) % SZ(vec);
int cnt = (j + SZ(vec) - i) % SZ(vec) + 1;
if (i == j) cnt = SZ(vec) + 1;
double a = area(arr[base], arr[base] + vec[i]) / 2;
//cerr << "(" << arr[base].X << ", " << arr[base].Y << ") -> (" << (arr[base] + vec[i]).X << ", " << (arr[base] + vec[i]).Y << "): " << cnt << " " << a << "\n";
chmax(cnt, a);
}
}
cout << fixed << setprecision(15) << ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4036kb
input:
5 8 1 1 1 2 1 3 2 1 3 1 3 4 4 1 4 2
output:
0.375000000000000
result:
ok found '0.3750000', expected '0.3750000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 3552ms
memory: 3952kb
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.009344444444444
result:
ok found '0.0093444', expected '0.0093444', error '0.0000000'
Test #3:
score: 0
Accepted
time: 3551ms
memory: 4192kb
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.100000000000000
result:
ok found '0.1000000', expected '0.1000000', error '0.0000000'
Test #4:
score: 0
Accepted
time: 3551ms
memory: 4052kb
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.013518518518519
result:
ok found '0.0135185', expected '0.0135185', error '0.0000000'
Test #5:
score: 0
Accepted
time: 3967ms
memory: 3952kb
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.500000000000000
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #6:
score: 0
Accepted
time: 3865ms
memory: 3964kb
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.030199133624716
result:
ok found '0.0301991', expected '0.0301991', error '0.0000000'
Test #7:
score: 0
Accepted
time: 3851ms
memory: 4200kb
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.027504747525583
result:
ok found '0.0275047', expected '0.0275047', error '0.0000000'
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3808kb
input:
5 2 2 3 1 4
output:
0.500000000000000
result:
wrong answer 1st numbers differ - expected: '0.6800000', found: '0.5000000', error = '0.1800000'