Submission #537659

# Submission time Handle Problem Language Result Execution time Memory
537659 2022-03-15T11:03:34 Z jamezzz Planine (COCI21_planine) C++17
0 / 110
5 ms 768 KB
#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define INF 1023456789
typedef long long ll;
typedef long double ld;

struct frac{
	ll a,b;
};

typedef pair<frac,frac> ii;

int n,h,x[1000005],y[1000005];
vector<ii> v;

int main(){
	sf("%d%d",&n,&h);
	for(int i=1;i<=n;++i)sf("%d%d",&x[i],&y[i]);
	for(int i=3;i<n;i+=2){
		int x1=x[i-1],x2=x[i],y1=y[i-1],y2=y[i];
		frac a={(ll)h*(x2-x1)-y1*x2+x1*y2,y2-y1};
		if(a.b<0)a.a=-a.a,a.b=-a.b;
		x1=x[i],x2=x[i+1],y1=y[i],y2=y[i+1];
		frac b={(ll)h*(x2-x1)-y1*x2+x1*y2,y2-y1};
		if(b.b<0)b.a=-b.a,b.b=-b.b;
		v.pb({a,b});
	}
	sort(all(v),[](ii &a,ii &b){return a.se.a*b.se.b<a.se.b*b.se.a;});
	int ans=0;frac pv=v[0].fi;
	pv.a-=1;
	for(int i=0;i<sz(v);++i){
		if(pv.a*v[i].fi.b<pv.b*v[i].fi.a){
			++ans;
			pv=v[i].se;
		}
	}
	pf("%d\n",ans);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:25:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  sf("%d%d",&n,&h);
      |    ^
Main.cpp:26:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  for(int i=1;i<=n;++i)sf("%d%d",&x[i],&y[i]);
      |                         ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Incorrect 5 ms 768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Incorrect 5 ms 768 KB Output isn't correct
3 Halted 0 ms 0 KB -