QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#419276 | #4189. Flappy Bird | zezoo050# | WA | 1ms | 3740kb | C++20 | 1.9kb | 2024-05-23 19:44:47 | 2024-05-23 19:44:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct point {
long long x, y;
bool operator<(point other) const {
return (1LL * x * other.y < 1LL * other.x * y);
}
bool operator>(point other) const {
return (1LL * x * other.y > 1LL * other.x * y);
}
void reduce() {
long long g = gcd(x, y);
x /= g;
y /= g;
}
};
point slope(point p1, point p2) {
// cerr << p1.x << ' ' << p1.y << ' ' << p2.x << ' ' << p2.y << '\n';
point ret;
ret.x = p2.y - p1.y;
ret.y = p2.x - p1.x;
ret.reduce();
// cerr << ret.x << ' ' << ret.y << '\n';
return ret;
}
const int N = 1e6 + 5;
pair<point, point> a[N];
void tc() {
int n;
cin >> a[0].first.x >> a[0].first.y;
a[0].second = a[0].first;
int tex, tey;
cin >> tex >> tey;
cin >> n;
a[n + 1].second = a[n + 1].first = {tex, tey};
for (int i = 1; i <= n; i++) {
int x, y1, y2;
cin >> x >> y1 >> y2;
a[i].first = {x, y1};
a[i].second = {x, y2};
}
point cur = a[0].first;
cout << cur.x << ' ' << cur.y << '\n';
point l = {-INT_MAX , 1}, r = {INT_MAX, 1};
for (int i = 1; i <= n + 1; i++) {
point s1 = slope(cur, a[i].first);
point s2 = slope(cur, a[i].second);
if (s1 > r) {
cur = a[i - 1].second;
l = {-INT_MAX, 1}, r = {INT_MAX, 1};
cout << cur.x << ' ' << cur.y << '\n';
} else if (s2 < l) {
cur = a[i - 1].first;
l = {-INT_MAX, 1}, r = {INT_MAX, 1};
cout << cur.x << ' ' << cur.y << '\n';
} else {
l = max(l, s1);
r = min(r, s2);
}
}
cout << tex << ' ' << tey << '\n';
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
tc();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3688kb
input:
0 0 10 0 1 5 -10 10
output:
0 0 10 0
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
0 0 10 0 4 2 1 3 4 2 3 7 0 2 9 -2 -1
output:
0 0 4 2 9 -1 10 0
result:
ok
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3668kb
input:
0 0 7 -12 3 1 -1 1 2 -3 3 5 -12 -8
output:
0 0 2 -3 7 -12
result:
wrong answer Output doesn't match expected line