Submission #373043

# Submission time Handle Problem Language Result Execution time Memory
373043 2021-03-03T07:02:26 Z sam571128 Planine (COCI21_planine) C++14
20 / 110
264 ms 49724 KB
#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;

const int N = 1e6+5;
const double EPS = 1e-7;
pair<double,double> seg[N];
int st[N], id[N];
int n, h;
double findp(int x1, int y1, int x2, int y2){
	assert(y1!=y2);
	return 1.0*(h-y1)*(x2-x1)/(y2-y1)+x1;
}

signed main(){
	fastio
	//freopen("input.in","r",stdin);
	cin >> n >> h;
	vector<pair<double,double>> v(1);
	for(int i = 1;i <= n;i++){
		int x,y;
		cin >> x >> y;
		v.push_back({x,y});
	}
    for (int i = 3; i <= n; i+=2) {
        seg[i].first = findp(v[i].first,v[i].second, v[i-1].first, v[i-1].second);
    	//cout << i << " " << seg[i].first << "\n";
    }
    for (int i = n-2; i >= 1; i-=2) {
        seg[i].second = findp(v[i].first,v[i].second, v[i+1].first, v[i+1].second);
    	//cout << i << " " << seg[i/2].second << "\n";
    }

    for(int i = 3;i <= n;i++){
    	id[i/2] = i;
    }
    sort(id+1,id+n/2,[&](int a, int b){
    	return seg[a].second < seg[b].second;
    });
    double tmp = seg[id[1]].second;
    int ans = 1;
    for (int i = 1; i <= n / 2 - 1; ++i) {
        if (tmp >= seg[id[i]].first)
            continue;
        //cout << seg[i].first << " " << seg[i].second << "\n";
        tmp = seg[id[i]].second;
        ++ans;
    }
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 880 KB Output is correct
2 Correct 3 ms 880 KB Output is correct
3 Correct 3 ms 880 KB Output is correct
4 Correct 22 ms 5092 KB Output is correct
5 Correct 24 ms 5220 KB Output is correct
6 Correct 26 ms 5476 KB Output is correct
7 Correct 229 ms 45800 KB Output is correct
8 Correct 252 ms 47676 KB Output is correct
9 Correct 264 ms 49724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Incorrect 1 ms 492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 880 KB Output is correct
2 Correct 3 ms 880 KB Output is correct
3 Correct 3 ms 880 KB Output is correct
4 Correct 22 ms 5092 KB Output is correct
5 Correct 24 ms 5220 KB Output is correct
6 Correct 26 ms 5476 KB Output is correct
7 Correct 229 ms 45800 KB Output is correct
8 Correct 252 ms 47676 KB Output is correct
9 Correct 264 ms 49724 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Incorrect 1 ms 492 KB Output isn't correct
12 Halted 0 ms 0 KB -