QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#344855 | #4368. Oil | Mindeveloped | WA | 1ms | 3620kb | C++14 | 2.8kb | 2024-03-05 16:14:06 | 2024-03-05 16:14:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int eps = 1e-9;
inline bool iszero (double x) {
return abs (x) <= eps;
}
inline bool eq (double x, double y) {
return iszero (x - y);
}
inline int sign (double x) {
if (iszero (x)) return 0;
else return x > 0 ? 1 : -1;
}
struct vec {
double x = 0, y = 0;
vec () = default;
vec (double px, double py): x(px), y(py) {
}
vec (const vec &obj) {
x = obj.x;
y = obj.y;
}
vec operator + (vec b) const {return {x + b.x, y + b.y};} // Addition
vec operator - (vec b) const {return {x - b.x, y - b.y};} // Subtraction
vec operator - () const {return {-x, -y};} // Negation
vec operator * (double k) const {return {x * k, y * k};} // Scalar multiplication
double operator * (vec b) const {return x * b.x + y * b.y;} // Dot product
double slope () {return y / x;}
};
double cross (vec a, vec b) { // Cross product
return a.x * b.y - a.y * b.x;
}
bool parallel (vec a1, vec a2, vec b1, vec b2) { // checks if line A1A2 is parallel with B1B2
return cross (a1 - a2, b1 - b2) == 0;
}
bool intersect_sl (vec a, vec b, vec p, vec l) { // checks if segment AB intersects with the line on point P with the direction l
double c1 = cross (p - a, l), c2 = cross (p - b, l);
return sign (c1 * c2) != -1;
}
bool intersect_ss (vec a1, vec a2, vec b1, vec b2) { // checks if segment A1A2 intersects with B1B2
double axl = min (a1.x, a2.x), axr = max (a1.x, a2.x), ayl = min (a1.y, a2.y), ayr = max (a1.y, a2.y);
double bxl = min (b1.x, b2.x), bxr = max (b1.x, b2.x), byl = min (b1.y, b2.y), byr = max (b1.y, b2.y);
if (sign (axr - bxl) == -1 || sign (axl - bxr) == 1 || sign (ayr - byl) == -1 || sign (ayl - byr) == 1) return false;
return intersect_sl (a1, a2, b1, b1 - b2) && intersect_sl (b1, b2, a1, a1 - a2);
}
const int N = 2005;
int n;
struct node {
int l, r, y;
} a[N];
struct event {
double d;
int t;
bool operator < (event b) const {
if (eq (d, b.d)) return t < b.t;
else return d < b.d;
}
} b[2 * N];
int main () {
cin >> n;
for (int i = 1;i <= n;i++) {
cin >> a[i].l >> a[i].r >> a[i].y;
if (a[i].l > a[i].r) swap (a[i].l, a[i].r);
}
int ans = 0;
for (int i = 1;i <= n;i++) {
vec p (a[i].l, a[i].y);
b[i * 2 - 1].t = b[i * 2].t = 0;
for (int j = 1;j <= n;j++) {
if (i == j) continue;
vec q1 (a[j].l, a[j].y), q2 (a[j].r, a[j].y);
double s1 = 1 / (p - q1).slope (), s2 = 1 / (p - q2).slope ();
b[j * 2 - 1].d = min (s1, s2);
b[j * 2 - 1].t = a[j].r - a[j].l;
b[j * 2].d = max (s1, s2);
b[j * 2].t = -a[j].r + a[j].l;
}
sort (b + 1, b + 2 * n + 1);
int res = a[i].r - a[i].l;
ans = max (ans, res);
for (int j = 1;j <= 2 * n;j++) {
res += b[j].t;
ans = max (ans, res);
}
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3620kb
input:
5 100 180 20 30 60 30 70 110 40 10 40 50 0 80 70
output:
200
result:
ok single line: '200'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3572kb
input:
3 50 60 10 -42 -42 20 25 0 10
output:
35
result:
wrong answer 1st lines differ - expected: '25', found: '35'