QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#71412 | #5276. K-Shaped Figures | neko_nyaa# | RE | 0ms | 0kb | C++20 | 3.6kb | 2023-01-09 22:34:17 | 2023-01-09 22:34:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define int long long
template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
typedef Point P;
T x, y;
explicit Point(T x=0, T y=0) : x(x), y(y) {}
bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
P operator+(P p) const { return P(x+p.x, y+p.y); }
P operator-(P p) const { return P(x-p.x, y-p.y); }
P operator*(T d) const { return P(x*d, y*d); }
P operator/(T d) const { return P(x/d, y/d); }
T dot(P p) const { return x*p.x + y*p.y; }
T cross(P p) const { return x*p.y - y*p.x; }
T cross(P a, P b) const { return (a-*this).cross(b-*this); }
T dist2() const { return x*x + y*y; }
double dist() const { return sqrt((double)dist2()); }
// angle to x-axis in interval [-pi, pi]
double angle() const { return atan2(y, x); }
P unit() const { return *this/dist(); } // makes dist()=1
P perp() const { return P(-y, x); } // rotates +90 degrees
P normal() const { return perp().unit(); }
// returns point rotated 'a' radians ccw around the origin
P rotate(double a) const {
return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
friend ostream& operator<<(ostream& os, P p) {
return os << "(" << p.x << "," << p.y << ")"; }
};
template<class P> bool onSegment(P s, P e, P p) {
if (p == s || p == e) return 0;
return p.cross(s, e) == 0 && (s - p).dot(e - p) <= 0;
}
template<class P>
int sideOf(P s, P e, P p) { return sgn(s.cross(e, p)); }
template<class P>
int sideOf(const P& s, const P& e, const P& p, double eps) {
auto a = (e-s).cross(p-s);
double l = (e-s).dist()*eps;
return (a > l) - (a < -l);
}
template<class P> vector<P> segInter(P a, P b, P c, P d) {
auto oa = c.cross(d, a), ob = c.cross(d, b),
oc = a.cross(b, c), od = a.cross(b, d);
// Checks if intersection is single non-endpoint point.
if (sgn(oa) * sgn(ob) < 0 && sgn(oc) * sgn(od) < 0)
return {(a * ob - b * oa) / (ob - oa)};
set<P> s;
if (onSegment(c, d, a)) s.insert(a);
if (onSegment(c, d, b)) s.insert(b);
if (onSegment(a, b, c)) s.insert(c);
if (onSegment(a, b, d)) s.insert(d);
return {all(s)};
}
typedef Point<ll> P;
void solve() {
int n; cin >> n;
vector<P> p(n), q(n);
for (int i = 0; i < n; i++) {
cin >> p[i].x >> p[i].y >> q[i].x >> q[i].y;
}
int ans = 0;
for (int i = 0; i < n; i++) {
map<P, map<P, int>> cnt[2];
for (int j = 0; j < n; j++) {
if (j == i) continue;
int onP = 0;
if (onSegment(p[i], q[i], p[j])) onP = 1;
if (onSegment(p[i], q[i], q[j])) onP = 2;
if (segInter(p[i], q[i], p[j], q[j]).size() != 1) onP = 0;
if (onP == 0) continue;
P p1, p2; int side = 0;
if (onP == 1) {
p1 = p[j]; p2 = q[j] - p[j];
side = sideOf(p[i], q[i], q[j]);
} else {
p1 = q[j]; p2 = p[j] - q[j];
side = sideOf(p[i], q[i], p[j]);
}
assert(side != 0);
int g = abs(__gcd(p2.x, p2.y));
p2.x /= g; p2.y /= g;
if (side == -1) {
cnt[0][p1][p2]++;
} else {
cnt[1][p1][p2]++;
}
}
for (int j = 0; j < 2; j++) {
for (auto [pp, mp]: cnt[j]) {
int sum = 0;
for (auto [p2, vl]: mp) {
ans += vl*sum; sum += vl;
}
}
}
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
2 5 0 0 0 10 0 5 3 10 0 5 3 0 0 5 7 4 0 5 6 2 8 0 0 10 10 3 4 4 4 4 4 4 5 3 4 4 4 7 7 7 8 7 7 8 7 5 5 4 6 5 5 3 7