結果

問題 No.245 貫け!
ユーザー parukiparuki
提出日時 2016-07-30 11:49:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 1,913 bytes
コンパイル時間 1,976 ms
コンパイル使用メモリ 176,684 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 12:53:53
合計ジャッジ時間 2,783 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 9 ms
5,376 KB
testcase_12 AC 23 ms
5,376 KB
testcase_13 AC 22 ms
5,376 KB
testcase_14 AC 22 ms
5,376 KB
testcase_15 AC 22 ms
5,376 KB
testcase_16 AC 22 ms
5,376 KB
testcase_17 AC 22 ms
5,376 KB
testcase_18 AC 21 ms
5,376 KB
testcase_19 AC 21 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define EPS 1e-8
class V2{
public:
    double x, y;

    V2(){}
    V2(double x_, double y_):x(x_),y(y_){}

    bool operator<(const V2 &p) const{
        return x!=p.x?x<p.x:y<p.y;
    }
    V2 operator+(V2 p) const{
        return V2(add(x,p.x), add(y,p.y));
    }
    V2 operator-(V2 p) const{
        return V2(add(x,-p.x), add(y,-p.y));
    }
    double dist()const{
        return sqrt(x*x+y*y);
    }
private:
    double add(double a, double b)const{
        return abs(a+b)<EPS*(abs(a)+abs(b))?0:a+b;
    }
};

double cross(const V2 &a, const V2 &b){
    return a.x * b.y - a.y * b.x;
}

bool colLinSeg(const V2 &la, const V2 &lb, const V2 &sa, const V2 &sb){
    return cross(lb - la, sa - la)*cross(lb - la, sb - la) < EPS;
}

int N;
vi A, B, C, D;

int main(){
    cin >> N;
    A = B = C = D = vi(N);
    
    rep(i, N)cin >> A[i] >> B[i] >> C[i] >> D[i];
    vector<pii> P;
    rep(i, N){
        for(pii p : {mp(A[i], B[i]), mp(C[i], D[i])})
            P.push_back(p);
    }
    sort(all(P));
    P.erase(unique(all(P)), P.end());

    int ans = min(2, N);
    rep(i, sz(P))FOR(j, i + 1, sz(P)){
        int ax, ay, bx, by;
        tie(ax, ay) = P[i];
        tie(bx, by) = P[j];
        V2 S(ax, ay), T(bx, by);

        int tmp = 0;
        rep(k, N){
            tmp += colLinSeg(S, T, V2(A[k], B[k]), V2(C[k], D[k]));
        }
        smax(ans, tmp);
    }
    cout << ans << endl;
}
0