Submission #35997613
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using point = pair<long double, long double>;
using points = vector<point>;
long double cross(point o, point a, point b) {
return (a.first - o.first) * (b.second - o.second) - (a.second - o.second) * (b.first - o.first);
}
points lower_hull(points p) {
int n = p.size(), k = 0;
sort(p.begin(), p.end());
vector<point> res(n);
for(int i = 0; i < n; i++) {
while(k >= 2 and cross(res[k - 2], res[k - 1], p[i]) <= 0) k--;
res[k++] = p[i];
}
res.resize(k);
return res;
}
int main() {
int n;
cin >> n;
cout << fixed << setprecision(10);
points p(n);
for(int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
int c;
cin >> c;
p[i].first /= c, p[i].second /= c;
}
sort(p.begin(), p.end());
//下側凸包を作る
points lh = lower_hull(p);
n = lh.size();
if(n == 1) {
cout << 1 / max(lh[0].first, lh[0].second) << endl;
return 0;
}
long double mx = 1ll << 60;
for(int i = 0; i < n - 1; i++) {
auto [lx, ly] = lh[i];
auto [rx, ry] = lh[i + 1];
if(ly <= ry) {
mx = min(mx, max(lx, ly));
continue;
}
if(rx <= ry) {
mx = min(mx, ry);
continue;
}
if(lx >= ly) {
mx = min(mx, lx);
continue;
}
auto lef_diff = ly - lx;
auto rig_diff = ry - rx;
assert(lef_diff >= 0 and rig_diff <= 0);
auto md = lx + (rx - lx) * lef_diff / (lef_diff + abs(rig_diff));
mx = min(mx, md);
}
cout << 1 / mx << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | G - Infinite Knapsack |
| User | nok0 |
| Language | C++ (GCC 9.2.1) |
| Score | 600 |
| Code Size | 1486 Byte |
| Status | AC |
| Exec Time | 253 ms |
| Memory | 22076 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 600 / 600 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 03_hack_01.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_01.txt | AC | 7 ms | 3716 KiB |
| 00_sample_02.txt | AC | 2 ms | 3720 KiB |
| 01_test_01.txt | AC | 234 ms | 21992 KiB |
| 01_test_02.txt | AC | 246 ms | 22032 KiB |
| 01_test_03.txt | AC | 248 ms | 21992 KiB |
| 01_test_04.txt | AC | 250 ms | 21992 KiB |
| 01_test_05.txt | AC | 248 ms | 21956 KiB |
| 01_test_06.txt | AC | 248 ms | 21880 KiB |
| 01_test_07.txt | AC | 249 ms | 21952 KiB |
| 01_test_08.txt | AC | 249 ms | 21940 KiB |
| 01_test_09.txt | AC | 251 ms | 22064 KiB |
| 01_test_10.txt | AC | 248 ms | 22000 KiB |
| 01_test_11.txt | AC | 248 ms | 21936 KiB |
| 01_test_12.txt | AC | 247 ms | 21996 KiB |
| 01_test_13.txt | AC | 248 ms | 21940 KiB |
| 01_test_14.txt | AC | 253 ms | 21956 KiB |
| 01_test_15.txt | AC | 248 ms | 22024 KiB |
| 01_test_16.txt | AC | 249 ms | 22076 KiB |
| 01_test_17.txt | AC | 250 ms | 21996 KiB |
| 01_test_18.txt | AC | 248 ms | 22064 KiB |
| 02_handmade_01.txt | AC | 3 ms | 3692 KiB |
| 02_handmade_02.txt | AC | 248 ms | 22076 KiB |
| 02_handmade_03.txt | AC | 250 ms | 22004 KiB |
| 02_handmade_04.txt | AC | 248 ms | 21956 KiB |
| 02_handmade_05.txt | AC | 248 ms | 22052 KiB |
| 02_handmade_06.txt | AC | 250 ms | 21880 KiB |
| 02_handmade_07.txt | AC | 249 ms | 21956 KiB |
| 02_handmade_08.txt | AC | 248 ms | 21880 KiB |
| 02_handmade_09.txt | AC | 248 ms | 22028 KiB |
| 03_hack_01.txt | AC | 110 ms | 10988 KiB |