#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef pair<int,int> point;
#define x first
#define y second
int operator^(point a, point b){
return a.x*b.y-a.y*b.x;
}
int operator*(point a, point b){
return a.x*b.x+a.y*b.y;
}
point operator-(point a, point b){
return {a.x-b.x,a.y-b.y};
}
point operator+(point a, point b){
return {a.x+b.x,a.y+b.y};
}
int ori(point a, point b, point c){
int tmp = (b-a)^(c-a);
if(tmp == 0) return 0;
return abs(tmp)/tmp;
}
int intersect(point a, point b, point c, point d){
int abc = ori(a,b,c);
int abd = ori(a,b,d);
int cda = ori(c,d,a);
int cdb = ori(c,d,b);
if(abc*abd < 0 && cda*cdb < 0) return true;
else return false;
}
signed main(){
fastio
int n;
cin >> n;
vector<point> arr;
for(int i = 0;i < n;i++){
int a,b;
cin >> a >> b;
arr.push_back({a,b});
}
int ans = n*(n-1)/2;
map<point,int> m;
for(int a = 0; a < n; a++){
for(int b = a+1; b < n; b++){
for(int c = 0; c < n; c++){
for(int d = c+1; d < n; d++){
if(intersect(arr[a],arr[b],arr[c],arr[d])){
m[{a,b}]++;
m[{c,d}]++;
}
}
}
}
}
cout << ans-m.size() << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
320 KB |
Output is correct |
2 |
Correct |
15 ms |
356 KB |
Output is correct |
3 |
Correct |
15 ms |
356 KB |
Output is correct |
4 |
Correct |
9 ms |
308 KB |
Output is correct |
5 |
Correct |
10 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
332 KB |
Output is correct |
7 |
Correct |
18 ms |
352 KB |
Output is correct |
8 |
Correct |
19 ms |
360 KB |
Output is correct |
9 |
Correct |
14 ms |
356 KB |
Output is correct |
10 |
Correct |
14 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
320 KB |
Output is correct |
2 |
Correct |
15 ms |
356 KB |
Output is correct |
3 |
Correct |
15 ms |
356 KB |
Output is correct |
4 |
Correct |
9 ms |
308 KB |
Output is correct |
5 |
Correct |
10 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
332 KB |
Output is correct |
7 |
Correct |
18 ms |
352 KB |
Output is correct |
8 |
Correct |
19 ms |
360 KB |
Output is correct |
9 |
Correct |
14 ms |
356 KB |
Output is correct |
10 |
Correct |
14 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
216 KB |
Output is correct |
12 |
Execution timed out |
1088 ms |
1584 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
320 KB |
Output is correct |
2 |
Correct |
15 ms |
356 KB |
Output is correct |
3 |
Correct |
15 ms |
356 KB |
Output is correct |
4 |
Correct |
9 ms |
308 KB |
Output is correct |
5 |
Correct |
10 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
332 KB |
Output is correct |
7 |
Correct |
18 ms |
352 KB |
Output is correct |
8 |
Correct |
19 ms |
360 KB |
Output is correct |
9 |
Correct |
14 ms |
356 KB |
Output is correct |
10 |
Correct |
14 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
216 KB |
Output is correct |
12 |
Execution timed out |
1088 ms |
1584 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |