結果

問題 No.245 貫け!
ユーザー antaanta
提出日時 2015-07-18 02:19:36
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 5,742 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 99,456 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-08 10:05:12
合計ジャッジ時間 2,658 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 14 ms
5,376 KB
testcase_11 AC 52 ms
5,376 KB
testcase_12 AC 138 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 142 ms
5,376 KB
testcase_15 AC 140 ms
5,376 KB
testcase_16 AC 146 ms
5,376 KB
testcase_17 AC 138 ms
5,376 KB
testcase_18 AC 141 ms
5,376 KB
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:129:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  129 |                         scanf("%d%d%d%d", &a, &b, &c, &d);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

struct P {
	typedef int T; typedef ll T2;	//T2は{a*b | a:T, b:T}を含むタイプ
	T x, y;
	P(T x_, T y_): x(x_), y(y_) {}
	P(): x(0), y(0) {}
};
inline bool operator==(const P& a, const P& b) { return a.x == b.x && a.y == b.y; }
inline bool operator<(const P& a, const P& b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
inline P operator+(const P& a, const P& b) { return P(a.x+b.x, a.y+b.y); }
inline P operator-(const P& a, const P& b) { return P(a.x-b.x, a.y-b.y); }
inline P operator-=(P& a, const P& b) { a.x -= b.x, a.y -= b.y ; return a; }
inline P::T2 cross(const P& a, const P& b) { return (P::T2)a.x*b.y - (P::T2)a.y*b.x; }
inline P::T2 dot(const P& a, const P& b) { return (P::T2)a.x*b.x + (P::T2)a.y*b.y; }
inline P::T2 norm(const P& a) { return (P::T2)a.x*a.x + (P::T2)a.y*a.y; }
ostream& operator<<(ostream& out, const P& x) { out << "(" << x.x << ", " << x.y << ")"; return out; }

int compareAngle(const P &a, const P &b) {
	int za = a.y > 0 || (a.y == 0 && a.x > 0) ? 0 : 1;
	int zb = b.y > 0 || (b.y == 0 && b.x > 0) ? 0 : 1;
	if(za != zb) return za - zb;
	P::T2 t1 = (P::T2)a.x * b.y;
	P::T2 t2 = (P::T2)a.y * b.x;
	return t1 > t2 ? 1 : t1 < t2 ? -1 : 0;
}

struct Angle {
	P point;
	int infty;
	int eps;
	Angle(): point(), infty(0), eps(0) { }
	Angle(P::T x, P::T y, int eps_ = 0): point(P(x, y)), infty(0), eps(eps_) { }
	Angle(P point_, int eps_ = 0): point(point_), infty(0), eps(eps_) { }
	Angle(P origin, P target, int eps_ = 0): point(target.x - origin.x, target.y - origin.y), infty(0), eps(eps_) { }
	explicit Angle(int infty_): point(), infty(infty_), eps(0) { }
	bool zero() const { return point.x == 0 && point.y == 0; }
	int compare_to(const Angle &that) const {
		if(infty != 0)
			return that.infty == 0 ? infty : (infty > 0) - (that.infty > 0);
		else if(that.infty != 0)
			return -that.infty;
		assert(!zero() && !that.zero());
		int t = compareAngle(point, that.point);
		if(t != 0)
			return t;
		return eps == that.eps ? 0 : eps > that.eps ? 1 : -1;
	}
	bool operator==(const Angle &that) const { return compare_to(that) == 0; }
	bool operator!=(const Angle &that) const { return compare_to(that) != 0; }
	bool operator< (const Angle &that) const { return compare_to(that) <  0; }
	bool operator<=(const Angle &that) const { return compare_to(that) <= 0; }
	bool operator> (const Angle &that) const { return compare_to(that) >  0; }
	bool operator>=(const Angle &that) const { return compare_to(that) >= 0; }
	friend ostream &operator<<(ostream &o, const Angle &a) {
		if(a.infty != 0)
			return o << (a.infty > 0 ? "+" : "-") << "oo";
		o << "(" << a.point.x << ", " << a.point.y << ")";
		if(a.eps != 0) o << a.eps;
		return o;
	}
	Angle operator-() const {
		if(infty != 0)
			return Angle(-infty);
		return Angle(-point.x, -point.y, -eps);
	}
	static bool get_order(Angle a, Angle b) {
		if(a.zero() || b.zero() || a == -b)
			return false;
		if(a < -a) {
			if(-a < b || b < a)
				return true;
		}else {
			if(-a < b && b < a)
				return true;
		}
		return false;
	}
	bool ordered_sandwich(Angle a, Angle b) const {
		if(a <= b)
			return a <= *this && *this <= b;
		else
			return a <= *this || *this <= b;
	}
};

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<P> ps;
		vector<pair<P,P> > segs(N);
		rep(i, N) {
			int a, b, c, d;
			scanf("%d%d%d%d", &a, &b, &c, &d);
			segs[i] = mp(P(a, b), P(c, d));
			ps.push_back(P(a, b));
			ps.push_back(P(c, d));
		}
		int ans = 0;
		rep(i, ps.size()) {
			P org = ps[i];
			int cnt = 0;
			vector<pair<Angle,int> > angles;
			Angle inita(P(-1, 0), -1);
			rep(j, N) {
				Angle a(org, segs[j].first), b(org, segs[j].second);
				if(a.zero() || b.zero() || a == -b) {
					++ cnt;
				}else {
					if(Angle::get_order(a, b))
						swap(a, b);
					angles.push_back(mp(a, j));
					angles.push_back(mp(b, N + j));
					if(inita.ordered_sandwich(a, b))
						++ cnt;
				}
			}
			sort(all(angles));
			/*
			amax(ans, cnt);
			for(int j = 0; j < (int)angles.size(); ++ j) {
				if(angles[j].second / N == 0)
					++ cnt;
				else
					-- cnt;
				if(cnt <= 0 || cnt > N) {
					cerr << i << ", " << j << ": " << cnt << endl;
				}
				amax(ans, cnt);
			}
			*/
			rep(j, angles.size()) {
				Angle angle = angles[j].first;
				int t = 0;
				rep(k, N) {
					Angle a(org, segs[k].first), b(org, segs[k].second);
					if(a.zero() || b.zero() || a == -b) {
						++ t;
					}else {
						if(Angle::get_order(a, b))
							swap(a, b);
						if(angle.ordered_sandwich(a, b))
							++ t;
					}
				}
				amax(ans, t);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}
0