QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#673952 | #5276. K-Shaped Figures | IllusionaryDominance# | WA | 0ms | 3540kb | C++20 | 3.3kb | 2024-10-25 12:17:26 | 2024-10-25 12:17:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using pii = pair <int, int>;
inline int untitled(const pii &a) {
if (a.first < 0) {
// x < 0
return a.second < 0 ? 3 : 2;
}else {
return a.second < 0 ? 4 : 1;
}
}
inline bool cmp(const pii &a, const pii &b) {
int a_ = untitled(a), b_ = untitled(b);
if (a_ != b_) return a_ < b_;
// dya / dxa < dyb / dxb
return 1ll * a.second * b.first < 1ll * a.first * b.second;
}
const int MAX_N = 1000 + 5;
int N;
struct Segment{
int x1, y1, x2, y2;
Segment (int x1_ = 0, int y1_ = 0, int x2_ = 0, int y2_ = 0) : x1(x1_), y1(y1_), x2(x2_), y2(y2_) {}
inline bool operator < (const Segment &comp) const {
return cmp(pair(x2 - x1, y2 - y1), pair(comp.x2 - comp.x1, comp.y2 - comp.y1));
// return atan2(y2 - y1, x2 - x1) < atan2(comp.y2 - comp.y1, comp.x2 - comp.x1);
}
}seg[MAX_N];
pii node[MAX_N << 1];
inline bool check(const Segment &seg, int x0, int y0) {
int dx1 = x0 - seg.x1, dy1 = x0 - seg.y1;
int dx2 = seg.x2 - x0, dy2 = seg.y2 - y0;
// dy1 / dx1 = dy2 / dx2
return 1ll * dy1 * dx2 == 1ll * dx1 * dy2;
}
void solve() {
cin >> N;
for (int i = 1; i <= N; i ++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
node[i] = pair(x1, y1);
node[i + N] = pair(x2, y2);
seg[i] = Segment(x1, y1, x2, y2);
}
int ans = 0;
sort(node + 1, node + (N << 1) + 1);
int M = unique(node + 1, node + (N << 1) + 1) - node - 1;
for (int i = 1; i <= M; i ++) {
auto [x0, y0] = node[i];
vector <Segment> seg1;
vector <pii> seg2;
for (int j = 1; j <= N; j ++) {
if (seg[j].x1 == x0 && seg[j].y1 == y0) {
seg2.emplace_back(seg[j].x2 - seg[j].x1, seg[j].y2 - seg[j].y1);
}else if (seg[j].x2 == x0 && seg[j].y2 == y0) {
seg2.emplace_back(seg[j].x1 - seg[j].x2, seg[j].y1 - seg[j].y2);
}else if (check(seg[j], x0, y0)) {
seg1.push_back(seg[j]);
}
}
if (!(seg1.empty() || seg2.empty())) {
sort(seg1.begin(), seg1.end());
sort(seg2.begin(), seg2.end(), cmp);
auto ed = unique(seg2.begin(), seg2.end());
int n = ed - seg2.begin();
int i = 0, j = n - 1;
for (int k = 0; k < (int)seg1.size(); k ++) {
pii dir0 = pair(seg1[k].x2 - seg1[k].x1, seg1[k].y2 - seg1[k].y1);
pii dir1 = pair(seg1[k].x1 - seg1[k].x2, seg1[k].y1 - seg1[k].y2);
if (cmp(dir0, seg2[i])) i = 0;
if (cmp(seg2[j], dir1)) j = n - 1;
// i < dir0, j > dir1
while (i < n && cmp(seg2[i], dir0)) i ++;
if (i == n) i --;
while (j >= 0 && cmp(dir1, seg2[j])) j --;
if (j < 0) j ++;
int cnt0 = i <= j ? j - i + 1 : n - (i - j - 1), cnt1 = n - cnt0;
ans += (cnt0 * (cnt0 - 1) + cnt1 * (cnt1 - 1)) / 2;
}
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.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: 100
Accepted
time: 0ms
memory: 3508kb
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
output:
6 2
result:
ok 2 number(s): "6 2"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3540kb
input:
10 3 -1 -1 0 -1 -1 -1 0 -1 -1 -1 1 1 3 1 -1 0 0 0 -1 1 1 0 1 1 -1 3 0 -1 1 1 -1 1 1 -1 1 1 -1 0 3 -1 0 0 1 -1 1 0 1 -1 1 -1 0 3 -1 1 1 1 1 0 0 -1 1 -1 -1 0 3 0 -1 0 0 1 -1 0 0 -1 -1 1 1 3 1 0 1 1 1 -1 1 0 0 -1 -1 0 3 1 1 0 -1 -1 0 0 1 0 1 -1 0 3 1 0 0 -1 1 0 1 -1 1 0 0 0 3 -1 -1 -1 0 1 -1 1 0 1 0 0 -1
output:
0 0 0 0 0 0 0 0 0 0
result:
wrong answer 6th numbers differ - expected: '1', found: '0'