QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#354267 | #7862. Land Trade | ucup-team1198# | WA | 100ms | 103844kb | C++20 | 7.9kb | 2024-03-15 02:04:31 | 2024-03-15 02:04:33 |
Judging History
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ld = long double;
struct Vector {
ld x;
ld y;
Vector(ld x = 0, ld y = 0): x(x), y(y) {}
Vector(const Vector& u, const Vector& v): x(v.x - u.x), y(v.y - u.y) {}
};
const ld EPS = 1e-9;
struct Line {
ld a;
ld b;
ld c;
Line(ld a = 0, ld b = 0, ld c = 0): a(a), b(b), c(c) {}
bool check(const Vector& v) const {
return v.x * a + v.y * b + c >= -EPS;
}
};
const int MAXN = 310;
Line ln[MAXN];
int id_l = 0;
const int MAXT = 1e4 + 100;
int tp[MAXT];
vector<int> ch[MAXT];
int id_tp = 0;
int nn() {
return id_tp++;
}
int read_int(const string& s, int& l) {
int res = 0;
bool neg = false;
if (s[l] == '-') {
neg = true;
++l;
}
while (s[l] >= '0' && s[l] <= '9') {
res = res * 10 + s[l] - '0';
++l;
}
if (neg) res = -res;
return res;
}
set<char> op = {'&', '|', '^', '!'};
string str = "&|^!";
int get_tp(char ch) {
for (int i = 0; i < (int)str.size(); ++i) {
if (str[i] == ch) return -1 - i;
}
return 0;
}
int build(const string& s, int l, int r) {
int v = nn();
if (s[l] == '[') {
++l;
ln[id_l].a = read_int(s, l);
++l;
ln[id_l].b = read_int(s, l);
++l;
ln[id_l].c = read_int(s, l);
tp[v] = id_l++;
return v;
}
int bal = 0;
int ind = -1;
for (int i = l + 1; i < r; ++i) {
if (s[i] == '(') {
++bal;
} else if (s[i] == ')') {
--bal;
} else if (bal == 0 && get_tp(s[i]) < 0) {
ind = i;
break;
}
}
tp[v] = get_tp(s[ind]);
if (ind != l + 1) {
ch[v].push_back(build(s, l + 1, ind));
}
ch[v].push_back(build(s, ind + 1, r - 1));
/// if (rand() % 2 == 0) swap(ch[v][0], ch.back());
return v;
}
bool eval(int v, const Vector& a) {
if (tp[v] >= 0) {
return ln[tp[v]].check(a);
}
if (tp[v] == -4) {
return !eval(ch[v][0], a);
} else if (tp[v] == -1) {
return eval(ch[v][0], a) && eval(ch[v][1], a);
} else if (tp[v] == -2) {
return eval(ch[v][0], a) || eval(ch[v][1], a);
} else {
return eval(ch[v][0], a) ^ eval(ch[v][1], a);
}
}
Vector inter(const Line& l1, const Line& l2) {
ld denom = l1.a * l2.b - l1.b * l2.a;
return {(-l1.c * l2.b + l1.b * l2.c) / denom
, (-l1.a * l2.c + l1.c * l2.a) / denom};
}
int inter_id[MAXN][MAXN];
Vector pts[MAXN * MAXN];
vector<int> online[MAXN];
struct HalfEdge {
Vector dir;
int to;
int used;
HalfEdge(Vector dir = Vector(), int to = -1): dir(dir), to(to), used(0) {}
};
const int MAXE = 2e6;
HalfEdge he[MAXE];
int id_he = 0;
vector<int> g[MAXN * MAXN];
ld operator*(const Vector& a, const Vector& b) {
return a.x * b.x + a.y * b.y;
}
ld operator%(const Vector& a, const Vector& b) {
return a.x * b.y - a.y * b.x;
}
Vector operator-(const Vector& a) {
return {-a.x, -a.y};
}
bool hp(const Vector& v) {
if (v.y == 0) return v.x > 0;
return v.y > 0;
}
bool cmpv(const Vector& u, const Vector& v) {
if (hp(u) != hp(v)) return hp(u);
return u % v > 0;
}
bool cmp(int i, int j) {
return cmpv(he[i].dir, he[j].dir);
}
int nxt(int i) {
int v = he[i].to;
Vector dir = -he[i].dir;
HalfEdge tmp(dir, -1);
he[id_he] = tmp;
int res = upper_bound(g[v].begin(), g[v].end(), id_he, cmp) - g[v].begin();
if (res == (int)g[v].size()) res = 0;
return g[v][res];
}
ostream& operator<<(ostream& out, const Vector& v) {
out << v.x << " " << v.y;
return out;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(20);
int xmn, xmx, ymn, ymx;
cin >> xmn >> xmx >> ymn >> ymx;
ln[id_l++] = {1, 0, -xmn};
ln[id_l++] = {-1, 0, xmx};
ln[id_l++] = {0, 1, -ymn};
ln[id_l++] = {0, -1, ymx};
string s;
cin >> s;
int root = build(s, 0, s.size());
int n = id_l;
/**for (int i = 0; i < n; ++i) {
cerr << ln[i].a << " " << ln[i].b << " " << ln[i].c << endl;
}*/
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
inter_id[i][j] = -1;
}
}
int id_point = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (abs(ln[i].a * ln[j].b - ln[i].b * ln[j].a) < 0.5) {
inter_id[i][j] = inter_id[j][i] = -1;
continue;
}
Vector p = inter(ln[i], ln[j]);
bool good = true;
for (int i = 0; i < 4; ++i) {
good &= ln[i].check(p);
}
/// cerr << i << " " << j << ": " << p << endl;
if (!good) {
inter_id[i][j] = inter_id[j][i] = -1;
continue;
}
int ind = -1;
for (int k = 0; k < i; ++k) {
if (inter_id[k][j] != -1) {
Vector v = pts[inter_id[k][j]];
if (abs(v.x - p.x) < EPS && abs(v.y - p.y) < EPS) {
ind = inter_id[k][j];
}
}
}
if (ind == -1) {
/// cerr << i << "-" << j << endl;
ind = id_point++;
}
/// cerr << i << " " << j << ": " << p << endl;
pts[ind] = p;
inter_id[i][j] = inter_id[j][i] = ind;
online[i].push_back(ind);
online[j].push_back(ind);
}
}
int vert = id_point;
for (int i = 0; i < n; ++i) {
sort(online[i].begin(), online[i].end());
online[i].resize(unique(online[i].begin(), online[i].end()) - online[i].begin());
Vector dir = {-ln[i].b, ln[i].a};
sort(online[i].begin(), online[i].end(), [&](int i, int j) { return pts[i] * dir < pts[j] * dir; });
for (int j = 1; j < (int)online[i].size(); ++j) {
int u = online[i][j], v = online[i][j - 1];
/// cerr << u << " " << v << endl;
he[id_he] = HalfEdge(dir, u);
g[v].push_back(id_he++);
he[id_he] = HalfEdge(-dir, v);
g[u].push_back(id_he++);
}
}
/// cerr << "points: ";
/// cerr << vert << endl;
for (int i = 0; i < vert; ++i) {
sort(g[i].begin(), g[i].end(), cmp);
/// cerr << pts[i] << endl;
}
/**for (int i : g[10]) {
cerr << i << ": " << he[i].to << " " << he[i].dir << endl;
}*/
/// cerr << nxt(38) << endl;
ld ans = 0;
for (int i = 0; i < id_he; ++i) {
if (he[i].used) continue;
vector<Vector> face;
int j = i;
while (!he[j].used) {
/// cerr << j << "; ";
face.push_back(pts[he[j].to]);
he[j].used = true;
j = nxt(j);
}
/// cerr << endl;
ld area = 0;
for (int i = 0; i < face.size(); ++i) {
area += (face[i] % face[(i + 1) % face.size()]);
/// cout << face[i] << "; ";
}
/// cout << endl;
/// cout << area << endl;
if (area >= 0) continue;
Vector s = Vector();
for (int i = 0; i < face.size(); ++i) {
s.x += face[i].x;
s.y += face[i].y;
}
s.x /= face.size();
s.y /= face.size();
if (eval(root, s)) {
ans -= area / 2;
}
}
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 100608kb
input:
0 1 0 1 ([-1,1,0]^[-1,-1,1])
output:
0.50000000000000000000
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 15ms
memory: 102528kb
input:
-5 10 -10 5 ((!([1,2,-3]&[10,3,-2]))^([-2,3,1]|[5,-2,7]))
output:
70.45169340463458110269
result:
ok found '70.4516934', expected '70.4516934', error '0.0000000'
Test #3:
score: 0
Accepted
time: 4ms
memory: 100980kb
input:
0 1 -1 1 ([1,1,1]&[-1,-1,-1])
output:
0.00000000000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 14ms
memory: 101376kb
input:
0 1000 0 1000 (([1,-1,0]&[-1000,999,999])&([1,0,-998]&[0,1,-998]))
output:
0.00050000000001659828
result:
ok found '0.0005000', expected '0.0005000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 15ms
memory: 101024kb
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.33485244147654924518
result:
ok found '47063.3348524', expected '47063.3348524', error '0.0000000'
Test #6:
score: 0
Accepted
time: 18ms
memory: 101156kb
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.05865566322222548479
result:
ok found '36999.0586557', expected '36999.0586557', error '0.0000000'
Test #7:
score: -100
Wrong Answer
time: 100ms
memory: 103844kb
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:
295705.57614144637395270365
result:
wrong answer 1st numbers differ - expected: '295728.6081036', found: '295705.5761414', error = '0.0000779'