Submission #72434

# Submission time Handle Problem Language Result Execution time Memory
72434 2018-08-26T08:07:08 Z 이시대의진정한갓겜스타투(#2216, kjp4155) Hill Reconstruction (FXCUP3_hill) C++17
0 / 100
3 ms 488 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];
int nxt[300500], prv[300500];
struct Tri{
	int a,b,c;
	bool operator < (const Tri x)const{
		if ( (Y[c]-Y[a]) * (X[x.c]-X[x.a]) == (Y[x.c]-Y[x.a]) * (X[c]-X[a]) ){
			if( a == x.a ){
				if( b == x.b ){
					return c < x.c;
				}
				return b < x.b;
			}
			return a < x.a;
		}
		return (Y[c]-Y[a]) * (X[x.c]-X[x.a]) > (Y[x.c]-Y[x.a]) * (X[c]-X[a]);
	}
	bool operator == (const Tri x) const{
		return a == x.a && b == x.b && c == x.c;
	}
};
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(Tri X){
	return area(p[X.a], p[X.b], p[X.c]  );
}
set<Tri> s;

void add(int a, int b, int c){
	if( (p[b]-p[a]) / (p[c]-p[b]) < 0 ) return;
	s.insert({a,b,c});
}
ll gcd(ll a, ll b){
	if( b == 0 ) return a;
	return gcd(b,a%b);
}
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]};
	
	nxt[1] = 2; prv[N] = N-1;
	for(int i=2;i<=N-1;i++){
		nxt[i] = i+1; prv[i] = i-1;
	}
	for(int i=2;i<=N-1;i++){
		add(i-1,i,i+1);
	}

	while( !s.empty() && C >= 0 ){

		Tri cur = *s.begin(); s.erase(s.begin());
	//	Debug(cur.a,cur.b,cur.c);
		ll A = area(cur);

		if( A > C ) continue;
		C -= A;
		die[cur.b] = 1;
		// erase two triangles
		if( cur.a != 1 ) s.erase({ prv[cur.a],cur.a, nxt[cur.a] });
		if( cur.c != N ) s.erase({ prv[cur.c], cur.c, nxt[cur.c]});
		nxt[cur.a] = cur.c; prv[cur.c] = cur.a;

		// insert new one 
		if( cur.a != 1 ) add(prv[cur.a], cur.a, cur.c);
		if( cur.c != N ) add(cur.a, cur.c, nxt[cur.c]);
	}

	Pll ans = {1,0};
	for(int i=1;i<=N-1;i++) if(!die[i] ){
		ll dx = X[nxt[i]] - X[i];
		ll dy = Y[nxt[i]] - Y[i];
	//	Debug(i,dx,dy);
		if( ans.Se * dx < dy * ans.Fi ) ans = {dx,dy};
	}
	ll g = gcd(ans.Fi,ans.Se);
	ans.Fi /= g; ans.Se /= g;
	printf("%lld/%lld\n",ans.Se,ans.Fi);

}

Compilation message

hill.cpp: In function 'int main()':
hill.cpp:108: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:109: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:110: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);
            ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 2 ms 488 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 2 ms 488 KB Output isn't correct
3 Halted 0 ms 0 KB -