QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#371305 | #8505. Almost Aligned | ucup-team3215 | WA | 0ms | 4036kb | C++20 | 1.8kb | 2024-03-30 04:37:47 | 2024-03-30 04:37:48 |
Judging History
answer
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <vector>
#pragma GCC optimize "no-unsafe-math-optimizations"
using namespace std;
using point = array<int, 2>;
int64_t operator^(point a, point b) { return a[0] * (int64_t)b[1] - a[1] * (int64_t)b[0]; }
int64_t operator&(point a, point b) { return a[0] * (int64_t)b[0] + a[1] * (int64_t)b[1]; }
point operator-(point a) { return {-a[0], -a[1]}; }
point operator-(point a, point b) { return {a[0] - b[0], a[1] - b[1]}; }
vector<point> env(const vector<point>& v) {
vector<point> e;
for (auto& p: v) {
while (e.size() > 1 && (e.back() - e.end()[-2] ^ p - e.back()) >= 0) e.pop_back();
e.push_back(p);
}
return e;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vector<point> v[2];
v[0].resize(n), v[1].resize(n);
for (int i = 0; i < n; ++i) cin >> v[0][i][1] >> v[1][i][1] >> v[0][i][0] >> v[1][i][0];
vector<point> e[4];
for (int c: {0, 1}) {
sort(v[c].begin(), v[c].end());
e[c * 2] = env(v[c]);
for (auto& p: v[c]) p = -p;
reverse(v[c].begin(), v[c].end());
e[c * 2 + 1] = env(v[c]);
}
auto ans = 1. / 0;
int i[4]{};
while (1) {
int w = -1;
for (int j = 0; j < 4; ++j) if (i[j] + 1 < e[j].size() && (!~w || (e[j][i[j] + 1] - e[j][i[j]] ^ e[w][i[w] + 1] - e[w][i[w]]) < 0)) w = j;
auto a = e[0][i[0]] - -e[1][i[1]], b = e[2][i[2]] - -e[3][i[3]];
double t;
if (~w) { auto d = e[w][i[w] + 1] - e[w][i[w]]; ++i[w]; t = -d[1] * 1. / d[0]; }
if ((!~w || t > 0) && isinf(ans)) ans = a[1] * 1. * b[1];
if (!~w) break;
if (t > 0) ans = min(ans, (a[0] * t + a[1]) * (b[0] * t + b[1]));
}
cout.precision(9);
cout << fixed << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4036kb
input:
4 0 0 10 10 0 0 10 10 10 10 -10 -10 10 0 -20 0
output:
22.222222222
result:
ok found '22.222222222', expected '22.222222222', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
3 0 -1 0 2 1 1 1 1 -1 1 -1 1
output:
0.000000000
result:
ok found '0.000000000', expected '0.000000000', error '-0.000000000'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3920kb
input:
3 0 -1 0 -2 1 1 1 1 -1 1 -1 1
output:
179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184...
result:
wrong answer 1st numbers differ - expected: '4.0000000', found: '1797693134862315708145274237317043567980705675258449965989174768031572607800285387605895586327668781715404589535143824642343213268894641827684675467035375169860499105765512820762454900903893289440758685084551339423045832369032229481658...