# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
538368 |
2022-03-16T16:43:28 Z |
siewjh |
Planine (COCI21_planine) |
C++17 |
|
263 ms |
51780 KB |
#include <bits/stdc++.h>
typedef long double ld;
typedef long long ll;
using namespace std;
int nums; ll h;
bool asc;
struct pt{
ll x, y;
};
struct hull{
vector<pt> v;
bool ccw(pt a, pt b, pt c){
return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) > 0;
}
bool cw(pt a, pt b, pt c){
return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) < 0;
}
void insert(pt p){
if (asc) while (v.size() >= 2 && ccw(v[v.size() - 2], v.back(), p)) v.pop_back();
else while (v.size() >= 2 && cw(v[v.size() - 2], v.back(), p)) v.pop_back();
v.push_back(p);
}
pair<ll, ll> query(pt p){
if (asc) while (v.size() >= 2 && ccw(v[v.size() - 2], v.back(), p)) v.pop_back();
else while (v.size() >= 2 && cw(v[v.size() - 2], v.back(), p)) v.pop_back();
auto a = v.back();
return {(p.x - a.x) * (h - a.y) + a.x * (p.y - a.y), p.y - a.y};
}
};
bool cmpfrac(pair<ll, ll> a, pair<ll, ll> b){
return a.first * b.second < b.first * a.second;
}
bool cmp(pair<pair<ll ,ll>, pair<ll, ll>> a, pair<pair<ll ,ll>, pair<ll, ll>> b){
return cmpfrac(a.second, b.second);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> nums >> h;
pt vec[nums];
for (int i = 0; i < nums; i++) cin >> vec[i].x >> vec[i].y;
int valley = (nums - 3) / 2;
pair<pair<ll, ll>, pair<ll, ll>> range[valley];
hull left; asc = 1;
for (int i = 1, j = 0; i < nums - 1; i++){
if (i % 2) left.insert(vec[i]);
else {
range[j].first = left.query(vec[i]);
j++;
}
}
hull right; asc = 0;
for (int i = nums - 2, j = valley - 1; i >= 1; i--){
if (i % 2) right.insert(vec[i]);
else {
range[j].second = right.query(vec[i]);
j--;
}
}
sort(range, range + valley, cmp);
int ans = 0; pair<ll, ll> last_pos;
for (int i = 0; i < valley; i++)
if (i == 0 || cmpfrac(last_pos, range[i].first)){
ans++;
last_pos = range[i].second;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
852 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
21 ms |
5716 KB |
Output is correct |
5 |
Correct |
22 ms |
5740 KB |
Output is correct |
6 |
Correct |
26 ms |
5712 KB |
Output is correct |
7 |
Correct |
210 ms |
51780 KB |
Output is correct |
8 |
Correct |
242 ms |
51772 KB |
Output is correct |
9 |
Correct |
241 ms |
51772 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
852 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
21 ms |
5716 KB |
Output is correct |
5 |
Correct |
22 ms |
5740 KB |
Output is correct |
6 |
Correct |
26 ms |
5712 KB |
Output is correct |
7 |
Correct |
210 ms |
51780 KB |
Output is correct |
8 |
Correct |
242 ms |
51772 KB |
Output is correct |
9 |
Correct |
241 ms |
51772 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
246 ms |
51676 KB |
Output is correct |
18 |
Correct |
255 ms |
31696 KB |
Output is correct |
19 |
Correct |
22 ms |
3412 KB |
Output is correct |
20 |
Correct |
217 ms |
31632 KB |
Output is correct |
21 |
Correct |
22 ms |
3452 KB |
Output is correct |
22 |
Correct |
240 ms |
31564 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
222 ms |
31632 KB |
Output is correct |
25 |
Correct |
21 ms |
3412 KB |
Output is correct |
26 |
Correct |
263 ms |
31704 KB |
Output is correct |
27 |
Correct |
11 ms |
2132 KB |
Output is correct |