# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
552723 |
2022-04-23T17:16:06 Z |
nvujica |
SIR (COI15_sir) |
C++14 |
|
188 ms |
8828 KB |
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int maxn = 3e5 + 10;
int n, m, mini = 0;
int x[maxn];
int y[maxn];
int xs[maxn];
int ys[maxn];
vector <int> v;
vector <int> hull;
ll ccw(int xa, int ya, int xb, int yb, int xc, int yc){
return (ll)xa * (yb - yc) + (ll)xb * (yc - ya) + (ll)xc * (ya - yb);
}
bool cmp(int a, int b){
return ccw(xs[mini], ys[mini], xs[a], ys[a], xs[b], ys[b]) > 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++){
cin >> x[i] >> y[i];
}
if(ccw(x[0], y[0], x[1], y[1], x[2], y[2]) < 0){
reverse(x, x + n);
reverse(y, y + n);
}
cin >> m;
for(int i = 0; i < m; i++){
cin >> xs[i] >> ys[i];
if(ys[i] < ys[mini] || ys[i] == ys[mini] && xs[i] < xs[mini]) mini = i;
}
//cout << mini << endl;
for(int i = 0; i < m; i++){
if(i != mini) v.push_back(i);
}
sort(v.begin(), v.end(), cmp);
// for(int i = 0; i < v.size(); i++){
// cout << v[i] << ' ';
// }
// cout << endl;
if(m == 1) v.push_back(mini);
hull.push_back(mini);
hull.push_back(v[0]);
for(int i = 1; i < m - 1; i++){
while(hull.size() >= 2 && ccw(xs[hull[hull.size() - 2]], ys[hull[hull.size() - 2]], xs[hull.back()], ys[hull.back()], xs[v[i]], ys[v[i]]) <= 0){
hull.pop_back();
}
hull.push_back(v[i]);
}
int h = hull.size();
// for(int i = 0; i < hull.size(); i++){
// cout << hull[i] << ' ';
// }
// cout << endl;
int mini2 = 0;
for(int i = 0; i < n; i++){
if(y[i] < y[mini2] || y[i] == y[mini2] && x[i] < x[mini2]) mini2 = i;
}
// cout << mini2 << endl;
int p = 0, q = (mini2 + 1) % n;
ll povr = 0, maks = 0;
for(int i = mini2; i < n + mini2; i++){
while(ccw(x[i % n], y[i % n], xs[hull[p]], ys[hull[p]], xs[hull[(p + 1) % h]], ys[hull[(p + 1) % h]]) < 0){
p++;
p %= h;
}
while(ccw(x[i % n], y[i % n], xs[hull[p]], ys[hull[p]], x[(q + 1) % n], y[(q + 1) % n]) < 0){
povr += ccw(x[i % n], y[i % n], x[q], y[q], x[(q + 1) % n], y[(q + 1) % n]);
q++;
q %= n;
}
// cout << i % n << ' ' << q << ' ' << p << endl;
maks = max(maks, povr);
povr -= ccw(x[i % n], y[i % n], x[(i + 1) % n], y[(i + 1) % n], x[q], y[q]);
}
cout << maks;
return 0;
}
Compilation message
sir.cpp: In function 'int main()':
sir.cpp:47:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
47 | if(ys[i] < ys[mini] || ys[i] == ys[mini] && xs[i] < xs[mini]) mini = i;
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
sir.cpp:86:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
86 | if(y[i] < y[mini2] || y[i] == y[mini2] && x[i] < x[mini2]) mini2 = i;
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
8828 KB |
Output is correct |
2 |
Correct |
188 ms |
7688 KB |
Output is correct |
3 |
Correct |
148 ms |
7252 KB |
Output is correct |
4 |
Correct |
44 ms |
2888 KB |
Output is correct |
5 |
Correct |
141 ms |
6476 KB |
Output is correct |
6 |
Incorrect |
110 ms |
7624 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |