답안 #72436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72436 2018-08-26T08:08:15 Z 이시대의진정한갓겜스타투(#2216, kjp4155) 오르막길 (FXCUP3_hill) C++17
100 / 100
989 ms 11200 KB
#include<bits/stdc++.h>
using namespace std;

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 6,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,_6,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define Debug1(a)           cout<<#a<<"="<<(a)<<"\n"
#define Debug2(a,b)         cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define Debug3(a,b,c)       cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define Debug4(a,b,c,d)     cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define Debug5(a,b,c,d,e)   cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define Debug6(a,b,c,d,e,f) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define Debug(...) macro_dispatcher(Debug, __VA_ARGS__)(__VA_ARGS__)
#define DA(a,n) cout<<#a<<"=["; printarray(a,n); cout<<"]\n"
#define DAR(a,n,s) cout<<#a<<"["<<s<<"-"<<n-1<<"]=["; printarray(a,n,s); cout<<"]\n"

#define TT1 template<class T>
#define TT1T2 template<class T1, class T2>
#define TT1T2T3 template<class T1, class T2, class T3>
template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v);
TT1T2 ostream& operator << (ostream& os, const pair<T1, T2>& p){ return os <<"("<<p.first<<", "<< p.second<<")"; }
TT1 ostream& operator << (ostream& os, const vector<T>& v){       bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v) {     bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const set<T1, T2>&v){    bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const multiset<T1,T2>&v){bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2T3 ostream& operator << (ostream& os, const map<T1,T2,T3>& v){ bool f = 1; os << "["; for (auto& ii : v) { if (!f)os << ", "; os << "(" << ii.first << " -> " << ii.second << ") "; f = 0; }return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const multimap<T1, T2>& v){ bool f = 1; os << "["; for (auto& ii : v) { if (!f)os << ", "; os << "(" << ii.first << " -> " << ii.second << ") "; f = 0; }return os << "]"; }
TT1T2 ostream& operator << (ostream& os, priority_queue<T1, T2> v) { bool f = 1; os << "["; while (!v.empty()) { auto x = v.top(); v.pop(); if (!f) os << ", "; f = 0; os << x; } return os << "]"; }
TT1T2 void printarray(const T1& a, T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()
#define geti1(X) cin >> X
#define geti2(X,Y) cin >> X >> Y
#define geti3(X,Y,Z) cin >> X >> Y >> Z
#define geti4(X,Y,Z,W) cin >> X >> Y >> Z >> W
#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321

#define endl '\n'
int N;ll C;
ll X[300500], Y[300500];
Pll p[300500]; bool die[300500];

Pll operator + (Pll a, Pll b){
	return {a.Fi+b.Fi, a.Se+b.Se};
}
Pll operator - (Pll a, Pll b){
	return {a.Fi-b.Fi, a.Se-b.Se};
}
ll operator * (Pll a, Pll b){
	return a.Fi*b.Fi + a.Se*b.Se;
}
ll operator / (Pll a, Pll b){
	return a.Fi*b.Se-a.Se*b.Fi;
}
ll area(Pll a, Pll b, Pll c){
	return abs((b-a)/(c-a));
}
ll area(int a, int b, int c){
	return area(p[a], p[b], p[c]  );
}

ll gcd(ll a, ll b){
	if( b == 0 ) return a;
	return gcd(b,a%b);
}
inline double slope(int a, int b){
	double dx = (double) (1.0*X[b]-1.0*X[a]);
	double dy = (double) (1.0*Y[b]-1.0*Y[a]);
	return dy/dx;
}
int prv[300500];
bool chk(double m){
	repp(i,N) if(i!=1) prv[i] = i-1;
	ll total = 0;
	for(int i=N;i>=2;i--) prv[i] = i-1;
	for(int i=N;i>=2;i--){
		if( slope(i-1,i) > m ){
			int j = i-2;
			prv[i-1] = 0;
			for(;j>=1;j--){
				ll tmp = (p[j+1]-p[j]) / (p[i]-p[j+1]);
				if( tmp < 0 ) total -= area(j,j+1,i);
				else total += area(j,j+1,i);
				prv[i] = j;
				if( tmp >= 0 && slope(j,i) <= m ) break;
				prv[j] = 0;
			}
			if( j == 0 ) return false;
			i = j+1;
			continue;
		}
	}
	return total <= C;
}

Pll ans = {0,1};
void setans(){
	Pll tmp = {1,0};
//	for(int i=1;i<=N;i++) printf("%d ",prv[i]);
//	printf("\n");
	for(int i=N;i>=2;i--) if(prv[i]!=0){
		int l = prv[i]; int r = i;
		ll dx = X[r] - X[l], dy = Y[r] - Y[l];
//		printf("%lld/%lld\n",dy,dx);
		if( tmp.Fi * dy > dx * tmp.Se ) tmp = {dx,dy};
	}
	ll g = gcd(tmp.Fi,tmp.Se);
	tmp.Fi /= g; tmp.Se /= g;

//	Debug(tmp,ans);
	if( tmp.Se * ans.Fi < ans.Se * tmp.Fi ) ans = tmp;
}

int main(){
	scanf("%d%lld",&N,&C); C *= 2;
	repp(i,N) scanf("%lld",X+i);
	repp(i,N) scanf("%lld",Y+i);
	repp(i,N) p[i] = {X[i],Y[i]};

	

	int bcnt = 200;
	double low = 0.0, high = 1e15;

	for(int i=2;i<=N;i++) prv[i] = i-1;
	setans();

//	double ans = -1.0;
	while( bcnt-- ){
		double mid = (low+high)/2.0;
		bool b = chk(mid);
		if( b ){
			setans();
			high = mid;
		}
		else{
			low = mid;
		}
	}


	printf("%lld/%lld",ans.Se,ans.Fi);

//	cout << setprecision(12) << ans << endl;
}

Compilation message

hill.cpp: In function 'int main()':
hill.cpp:133:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%lld",&N,&C); C *= 2;
  ~~~~~^~~~~~~~~~~~~~~~
hill.cpp:134:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  repp(i,N) scanf("%lld",X+i);
            ~~~~~^~~~~~~~~~~~
hill.cpp:135:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  repp(i,N) scanf("%lld",Y+i);
            ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 4 ms 484 KB Output is correct
4 Correct 4 ms 484 KB Output is correct
5 Correct 4 ms 484 KB Output is correct
6 Correct 4 ms 516 KB Output is correct
7 Correct 6 ms 516 KB Output is correct
8 Correct 7 ms 516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 4 ms 484 KB Output is correct
4 Correct 4 ms 484 KB Output is correct
5 Correct 4 ms 484 KB Output is correct
6 Correct 4 ms 516 KB Output is correct
7 Correct 6 ms 516 KB Output is correct
8 Correct 7 ms 516 KB Output is correct
9 Correct 542 ms 11160 KB Output is correct
10 Correct 583 ms 11160 KB Output is correct
11 Correct 989 ms 11200 KB Output is correct
12 Correct 789 ms 11200 KB Output is correct
13 Correct 396 ms 11200 KB Output is correct
14 Correct 278 ms 11200 KB Output is correct
15 Correct 608 ms 11200 KB Output is correct
16 Correct 551 ms 11200 KB Output is correct
17 Correct 397 ms 11200 KB Output is correct
18 Correct 442 ms 11200 KB Output is correct
19 Correct 565 ms 11200 KB Output is correct