QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#677145 | #7693. Convex Hull Extension | new_game_plus_players# | WA | 469ms | 3828kb | C++14 | 3.1kb | 2024-10-26 10:06:17 | 2024-10-26 10:06:21 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define double long double
struct point {
double x, y;
point (double X=0, double Y=0) {x=X; y=Y;}
point operator + (const point &t) const {return point(x+t.x, y+t.y);}
point operator - (const point &t) const {return point(x-t.x, y-t.y);}
point operator * (const double &t) const {return point(x*t, y*t);}
double det(const point &t) const {return x*t.y - y*t.x;}
double dot(const point &t) const {return x*t.x + y*t.y;}
double mx() const {return max(x, y);}
double mn() const {return min(x, y);}
void out() {
cerr<<x<<','<<y<<" ";
}
}a[55];
const double eps = 1e-10;
bool parallel(point a, point b, point c, point d) {
return fabs((b-a).det(d-c)) < eps;
}
point LxL(point a, point b, point c, point d) { // a-b x c-d
double t = (c-a).det(d-a) / (b-a).det(d-c);
return a + (b-a) * t;
}
int n;
bool in_triangle(point p, point a, point b, point c) {
if ((b-a).det(p-a) < eps) return false;
if ((c-b).det(p-b) < eps) return false;
if ((a-c).det(p-c) < eps) return false;
return true;
}
void solvex(point a, point b, int x, int &l, int &r) {
if (fabs(a.x - b.x) < eps) {
return;
}
point p = LxL(a, b, point(x, 0), point(x, 1));
if (a.x < b.x) {
l = max(l, (int)ceil(p.y + eps));
} else {
r = min(r, (int)floor(p.y - eps));
}
}
ll ANS;
const int inf = 2e9;
ll solve(point a, point b, point c) {
double R = -inf;
R = max(R, a.x);
R = max(R, b.x);
R = max(R, c.x);
double L = inf;
L = min(L, a.x);
L = min(L, b.x);
L = min(L, c.x);
ll ret = 0;
// cerr<<"solve:";
// a.out();
// b.out();
// c.out();
// cerr<<"["<<L<<","<<R<<"]"<<endl;
for (int i=L-2; i<=R+2; i++) {
int l = -inf, r = inf;
solvex(a, b, i, l, r);
solvex(b, c, i, l, r);
solvex(c, a, i, l, r);
// cerr<<"i="<<i<<" "<<l<<","<<r<<endl;
if (l<=r && l != -inf && r != inf) {
if (in_triangle(point(i, l), a, b, c)) {
ret += r-l+1;
}
}
}
return ret;
}
int solve_parallel(point a, point b, point c, point d) {
ll ret = 0;
if (fabs(a.x-b.x)<eps) {
return fabs(c.x - a.x) > 1.5;
}
for (int i=-1e6; i<=1e6; i++) {
int l = -inf, r = inf;
solvex(a, b, i, l, r);
solvex(c, d, i, l, r);
// cerr<<"i="<<i<<" "<<l<<","<<r<<endl;
if (l<=r && l != -inf && r != inf) {
if (in_triangle(point(i, l), a, b, c)) {
ret += r-l+1;
return ret;
}
}
}
return ret;
}
int main() {
cin>>n;
for (int i=1; i<=n; i++) {
cin>>a[i].x>>a[i].y;
}
a[0] = a[n];
a[n+1] = a[1];
a[n+2] = a[2];
ll ans = 0;
for (int i=1; i<=n; i++) {
if (parallel(a[i-1], a[i], a[i+1], a[i+2])) {
int cnt = solve_parallel(a[i-1], a[i], a[i+1], a[i+2]);
if (cnt>0) {
puts("infinitely many");
return 0;
}
continue;
}
point p = LxL(a[i-1], a[i], a[i+1], a[i+2]);
double test = (p - a[i]).det(a[i+1] - a[i]);
if (test < 0) {
puts("infinitely many");
return 0;
}
ans += solve(a[i], p, a[i+1]);
}
cout<<ans<<endl;
// cerr<<"ANS="<<ANS<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3724kb
input:
5 0 2 -2 0 -1 -3 1 -3 2 1
output:
23
result:
ok single line: '23'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
4 -7 -7 7 -7 7 7 -7 7
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #3:
score: 0
Accepted
time: 158ms
memory: 3736kb
input:
4 -1000 1000 -1000 999 -999 999 -999 1000
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 88ms
memory: 3796kb
input:
6 0 -901 900 -900 900 900 0 901 -900 900 -900 -900
output:
1457999998
result:
ok single line: '1457999998'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
6 900 -900 901 0 900 900 -900 900 -901 0 -900 -900
output:
1457999998
result:
ok single line: '1457999998'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
6 0 0 400 1 400 2 0 3 -400 2 -400 1
output:
1596
result:
ok single line: '1596'
Test #7:
score: 0
Accepted
time: 59ms
memory: 3672kb
input:
6 0 -901 900 -899 900 900 0 901 -900 900 -900 -899
output:
970921796
result:
ok single line: '970921796'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
6 2 -2 401 399 399 401 -2 2 -401 -399 -399 -401
output:
4794
result:
ok single line: '4794'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
6 399 -401 401 -399 2 2 -399 401 -401 399 -2 -2
output:
4794
result:
ok single line: '4794'
Test #10:
score: 0
Accepted
time: 160ms
memory: 3796kb
input:
4 -1 -1 -2 -2 -2 -3 -1 -2
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 159ms
memory: 3712kb
input:
4 0 0 0 1 -1 2 -1 1
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
48 5 -70 14 -68 22 -66 31 -63 39 -58 46 -52 52 -46 58 -39 63 -31 66 -22 68 -14 70 -5 70 5 68 14 66 22 63 31 58 39 52 46 46 52 39 58 31 63 22 66 14 68 5 70 -5 70 -14 68 -22 66 -31 63 -39 58 -46 52 -52 46 -58 39 -63 31 -66 22 -68 14 -70 5 -70 -5 -68 -14 -66 -22 -63 -31 -58 -39 -52 -46 -46 -52 -39 -58 ...
output:
36
result:
ok single line: '36'
Test #13:
score: 0
Accepted
time: 159ms
memory: 3760kb
input:
4 -10 -10 -11 11 -11 10 -10 -11
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 159ms
memory: 3716kb
input:
4 10 -10 10 -11 11 10 11 11
output:
0
result:
ok single line: '0'
Test #15:
score: 0
Accepted
time: 319ms
memory: 3720kb
input:
4 5 5 6 5 -5 6 -6 6
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 323ms
memory: 3800kb
input:
4 100 -99 -99 -98 -100 -98 99 -99
output:
0
result:
ok single line: '0'
Test #17:
score: -100
Wrong Answer
time: 469ms
memory: 3672kb
input:
4 0 1 -1 0 0 -1 1 0
output:
0
result:
wrong answer 1st lines differ - expected: 'infinitely many', found: '0'