QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#402621 | #7862. Land Trade | u2x1 | WA | 1161ms | 16940kb | C++20 | 6.7kb | 2024-05-01 02:11:35 | 2024-05-01 02:11:35 |
Judging History
answer
#include "bits/stdc++.h"
#define all(x) x.begin(), x.end()
#define NL std::cout << '\n'
using lnt = long long;
const int inf = 0x3f3f3f3f;
const lnt linf = 1ll << 62;
using db = long double; const db eps = 1e-12;
int sgn(db x) { return (x < -eps ? -1 : x > eps); }
struct Pt { db x, y; };
std::istream& operator>>(std::istream& is, Pt &p) {
int x, y; std::cin >> x >> y;
p.x = x; p.y = y; return is;
}
std::ostream& operator<<(std::ostream& os, Pt p) {
return os << "(" << p.x << "," << p.y << "),";
}
Pt operator-(Pt a, Pt b) { return { a.x - b.x, a.y - b.y }; }
Pt operator+(Pt a, Pt b) { return { a.x + b.x, a.y + b.y }; }
Pt operator*(Pt a, db x) { return { a.x * x, a.y * x }; }
Pt operator/(Pt a, db x) { return { a.x / x, a.y / x }; }
db dot(Pt a, Pt b) { return a.x * b.x + a.y * b.y; }
db det(Pt a, Pt b) { return a.x * b.y - a.y * b.x; }
bool operator==(Pt a, Pt b) { return !sgn(dot(a-b, a-b)); }
bool operator!=(Pt a, Pt b) { return sgn(dot(a-b, a-b)); }
bool operator<(Pt a, Pt b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }
int side(Pt a, Pt b, Pt x) { return sgn(det(b-a, x-a)); }
struct Line { Pt s, t; };
Pt intersect(Line a, Line b) {
db v = det(a.t - a.s, b.s - a.s);
db u = det(a.t - a.s, b.t - a.s);
return (b.s * u - b.t * v) / (u - v);
}
bool para(Line a, Line b) {
return !sgn(det(a.t - a.s, b.t - b.s));
}
std::pair<std::vector<Pt>, std::vector<Pt>> hullCut(std::vector<Pt> &hull, Line a) {
int l = -1, r = -1;
Pt il, ir;
for (int i = hull.size() - 1, j = 0; j < hull.size(); i = j++) {
auto &u = hull[i], &v = hull[j];
int s1 = side(a.s, a.t, u), s2 = side(a.s, a.t, v);
if (!s1 && !s2) { return {hull, {}}; }
if (s1 * s2 <= 0) {
if (l == -1) { l = j; il = intersect({u, v}, a); }
else {
Pt inter = intersect({u, v}, a);
if (inter != il) { r = j; ir = inter; }
}
}
}
if (r == -1) { return { hull, {} }; }
std::vector<Pt> lhs(hull.begin() + l, hull.begin() + r);
lhs.emplace_back(ir);
lhs.emplace_back(il);
std::vector<Pt> rhs(hull.begin() + r, hull.end()); rhs.insert(rhs.end(), hull.begin(), hull.begin() + l);
if (rhs.empty() || (il != rhs.back() && il != rhs.front())) { rhs.emplace_back(il); }
if (rhs.empty() || (ir != rhs.back() && ir != rhs.front())) { rhs.emplace_back(ir); }
return {lhs, rhs};
}
enum { ATOM = 128, AND, OR, XOR, NOT };
Pt polyCenter(std::vector<Pt> &v) {
Pt ret {0, 0}; db s = 0;
for (int j = 0, i = v.size() - 1; j < v.size(); i = j++) {
ret = ret + (v[i] + v[j]) * det(v[i], v[j]);
s += det(v[i], v[j]);
}
return ret / s / 3;
}
int main() {
std::ios::sync_with_stdio(0), std::cin.tie(0);
std::cout << std::fixed << std::setprecision(15);
std::vector<std::vector<Pt>> polys(1);
{
int xmi, xmx, ymi, ymx; std::cin >> xmi >> xmx >> ymi >> ymx;
polys[0].push_back({(db)xmi, (db)ymx});
polys[0].push_back({(db)xmi, (db)ymi});
polys[0].push_back({(db)xmx, (db)ymi});
polys[0].push_back({(db)xmx, (db)ymx});
}
std::string raw; std::cin >> raw;
Line tokenVal; int token;
int p = 0;
auto next = [&]() -> void {
while (p != raw.size()) {
token = raw[p++];
if (token == '[') {
static auto read = [&]() {
int ret = 0; bool neg = 0;
while (raw[p] == '-' || raw[p] == '+' || (raw[p] >= '0' && raw[p] <= '9')) {
if (raw[p] == '-') { neg = !neg; }
else if (raw[p] == '+') { }
else { ret = ret * 10 + raw[p] - '0'; }
++p;
}
if (neg) { ret = -ret; }
return ret;
};
int a = read();
++p; // parse ','
int b = read();
++p; // parse ','
int cc = read();
++p; // parse ']'
token = ATOM;
if (b == 0) {
tokenVal.s = { -1.L * cc / a, 0 };
tokenVal.t = { -1.L * cc / a, (a > 0 ? -1. : 1.) };
} else {
tokenVal.s = { 0, -1.L * cc / b };
tokenVal.t = tokenVal.s + Pt{ 1, -1.L * a / b };
}
if (b < 0) { std::swap(tokenVal.s, tokenVal.t); }
return;
} else if (token == '&') {
token = AND; return;
} else if (token == '|') {
token = OR; return;
} else if (token == '^') {
token = XOR; return;
} else if (token == '!') {
token = NOT; return;
} else if (token == '(' || token == ')') {
return;
}
}
};
auto expr1 = [&](auto &self, int level) -> void {
if (token == ATOM) {
std::vector<std::vector<Pt>> npolys; npolys.reserve(polys.size() * 2);
for (auto poly : polys) {
auto [a, b] = hullCut(poly, tokenVal);
npolys.emplace_back(a);
if (!b.empty()) { npolys.emplace_back(b); }
}
std::swap(npolys, polys);
next();
} else if (token == '(') {
next();
self(self, ATOM);
next();
} else if (token == NOT) {
next();
self(self, NOT);
}
while (token >= level) {
if (token == AND) {
next(); self(self, NOT);
} else if (token == OR) {
next(); self(self, NOT);
} else if (token == XOR) {
next(); self(self, NOT);
} else if (token == NOT) {
next(); self(self, NOT);
}
}
};
next(); expr1(expr1, ATOM);
std::vector<bool> stk;
Pt ct;
auto expr2 = [&](auto &self, int level) -> void {
if (token == ATOM) {
stk.emplace_back(side(tokenVal.s, tokenVal.t, ct) >= 0);
next();
} else if (token == '(') {
next();
self(self, ATOM);
next();
} else if (token == NOT) {
next();
self(self, NOT);
stk.back() = !stk.back();
}
while (token >= level) {
if (token == AND) {
next(); self(self, NOT);
bool a = stk.back(); stk.pop_back();
bool b = stk.back(); stk.pop_back();
stk.emplace_back(a & b);
} else if (token == OR) {
next(); self(self, NOT);
bool a = stk.back(); stk.pop_back();
bool b = stk.back(); stk.pop_back();
stk.emplace_back(a | b);
} else if (token == XOR) {
next(); self(self, NOT);
bool a = stk.back(); stk.pop_back();
bool b = stk.back(); stk.pop_back();
stk.emplace_back(a ^ b);
}
}
};
db ret = 0;
for (auto poly : polys) {
ct = polyCenter(poly);
p = 0; next(); expr2(expr2, ATOM);
if (stk.back()) {
for (int i = poly.size() - 1, j = 0; j < poly.size(); i = j++) {
ret += det(poly[i], poly[j]);
}
}
stk.pop_back();
}
std::cout << ret / 2;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3964kb
input:
0 1 0 1 ([-1,1,0]^[-1,-1,1])
output:
0.500000000000000
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
-5 10 -10 5 ((!([1,2,-3]&[10,3,-2]))^([-2,3,1]|[5,-2,7]))
output:
70.451693404634581
result:
ok found '70.4516934', expected '70.4516934', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
0 1 -1 1 ([1,1,1]&[-1,-1,-1])
output:
0.000000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3912kb
input:
0 1000 0 1000 (([1,-1,0]&[-1000,999,999])&([1,0,-998]&[0,1,-998]))
output:
0.000500000000073
result:
ok found '0.0005000', expected '0.0005000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3896kb
input:
-725 165 643 735 ((((!(([22,15,137]|(!([23,-5,-41]^(!([2,25,-515]&[-37,10,487])))))&(!(([25,24,47]^([-24,21,-114]^[19,-7,79]))^[4,20,241]))))^(!((!((!(([30,-1,474]^([14,17,155]^[-31,-6,-153]))|[-15,-15,108]))|(([-26,-11,421]&[-15,-3,-224])&[14,-3,458])))^[9,20,-404])))^(!((!((!(([14,-6,-464]^[-11,8,...
output:
47063.334852441478418
result:
ok found '47063.3348524', expected '47063.3348524', error '0.0000000'
Test #6:
score: 0
Accepted
time: 1ms
memory: 4056kb
input:
767 957 738 941 ((!(((!([3,-3,507]^[-30,-10,425]))^[-6,7,643])^((!((!([-11,0,450]^[21,17,-65]))&(!([17,0,64]^[-11,0,804]))))|[-31,10,-687])))&((!(([-34,12,-527]^(!([17,-14,-219]^(!([13,-27,-105]^(!([18,-47,-110]&(!([-9,-20,-455]^[-18,26,-228])))))))))^([-4,0,144]^[10,1,396])))^((!((!([35,0,-221]&[-5...
output:
36999.058655663216683
result:
ok found '36999.0586557', expected '36999.0586557', error '0.0000000'
Test #7:
score: 0
Accepted
time: 1161ms
memory: 16940kb
input:
-513 213 -733 114 (!((!((!((((!([2,16,-57]|[15,40,-272]))^((!(([0,26,315]|[5,-4,-336])^(!([-12,2,218]&([17,-16,-730]&[-7,3,-263])))))^[18,-7,29]))^[5,30,-126])^((!(((!((([8,9,406]^(!([-26,6,63]^[-38,-25,108])))^(([-9,20,220]^(!([-2,-27,213]^[29,16,-269])))|[-12,-4,-586]))^([30,0,-443]|(!((!([-17,0,3...
output:
295728.608103610679393
result:
ok found '295728.6081036', expected '295728.6081036', error '0.0000000'
Test #8:
score: 0
Accepted
time: 11ms
memory: 3988kb
input:
-517 -379 -789 477 (((!((!(([1,-12,191]^(!(((!([32,0,89]^[-35,6,33]))^[-3,6,-293])^[20,-39,77])))^(([16,15,-285]^[15,-7,430])^([20,3,-95]|(!((!(([-15,-27,339]^[-11,-13,221])^[33,28,596]))|([-17,21,402]^[22,16,90])))))))&(!((!((!([12,-1,-279]^[-30,-13,224]))^[-29,24,-33]))^([31,-19,288]^(!((!([-1,26,...
output:
107150.604879697182234
result:
ok found '107150.6048797', expected '107150.6048797', error '0.0000000'
Test #9:
score: 0
Accepted
time: 7ms
memory: 4328kb
input:
-477 275 -266 519 (!((!((!((!([-1,3,162]|[-32,16,269]))&(!(((((([-31,7,114]^([-12,7,-163]^[23,-10,159]))|(!(([0,-16,114]^[-33,15,-190])|(!([1,-22,308]^[-31,13,316])))))^((!([-12,29,-22]^(([23,15,-8]^[0,15,46])^[6,15,356])))^[22,13,-163]))^([18,17,487]^[28,23,143]))|(!(((!((!(([7,-45,-583]&([31,2,-22...
output:
335169.310517515870174
result:
ok found '335169.3105175', expected '335169.3105175', error '0.0000000'
Test #10:
score: 0
Accepted
time: 2ms
memory: 4032kb
input:
175 624 -835 683 (!(((!(([-32,30,-478]^[23,4,-120])^[28,33,413]))|(!((!((!((!([-15,-5,0]^(!((!(((!([0,-32,90]^[-9,-22,-7]))^[-10,-35,344])|(!([1,11,-235]|[-31,-6,-344]))))^(!((!([-15,0,-90]|[-17,-10,-153]))^[-1,6,-8]))))))^(!([8,-6,302]^[-2,4,91]))))|([13,28,-70]^[16,-11,-74])))^(((((!((!((([-5,8,45...
output:
411470.358504943449219
result:
ok found '411470.3585049', expected '411470.3585049', error '0.0000000'
Test #11:
score: 0
Accepted
time: 192ms
memory: 6944kb
input:
-1000 1000 -1000 1000 ([1,0,-1000]^([0,1,-1000]^([1,0,-980]^([0,1,-980]^([1,0,-960]^([0,1,-960]^([1,0,-940]^([0,1,-940]^([1,0,-920]^([0,1,-920]^([1,0,-900]^([0,1,-900]^([1,0,-880]^([0,1,-880]^([1,0,-860]^([0,1,-860]^([1,0,-840]^([0,1,-840]^([1,0,-820]^([0,1,-820]^([1,0,-800]^([0,1,-800]^([1,0,-780]^...
output:
2000000.000000000000000
result:
ok found '2000000.0000000', expected '2000000.0000000', error '0.0000000'
Test #12:
score: 0
Accepted
time: 206ms
memory: 6740kb
input:
-500 500 -500 500 ([2,-3,-1000]^([2,3,-1000]^([2,-3,-980]^([2,3,-980]^([2,-3,-960]^([2,3,-960]^([2,-3,-940]^([2,3,-940]^([2,-3,-920]^([2,3,-920]^([2,-3,-900]^([2,3,-900]^([2,-3,-880]^([2,3,-880]^([2,-3,-860]^([2,3,-860]^([2,-3,-840]^([2,3,-840]^([2,-3,-820]^([2,3,-820]^([2,-3,-800]^([2,3,-800]^([2,-...
output:
540000.000000000063721
result:
ok found '540000.0000000', expected '540000.0000000', error '0.0000000'
Test #13:
score: -100
Wrong Answer
time: 5ms
memory: 4252kb
input:
-1000 1000 -1000 1000 ([-57,281,0]^([478,81,0]^([-362,995,0]^([-339,614,0]^([491,769,0]^([673,486,0]^([-637,374,0]^([-204,383,0]^([-509,859,0]^([-973,757,0]^([-707,648,0]^([-792,409,0]^([-944,621,0]^([446,21,0]^([-553,473,0]^([795,704,0]^([-821,992,0]^([89,47,0]^([771,332,0]^([-845,259,0]^([271,867,...
output:
540531.891470066632223
result:
wrong answer 1st numbers differ - expected: '1823923.8971530', found: '540531.8914701', error = '0.7036434'