結果

問題 No.245 貫け!
コンテスト
ユーザー Binh Pham Phu
提出日時 2026-10-18 14:52:01
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 9 ms / 5,000 ms
+ 193µs
コード長 1,567 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,984 ms
コンパイル使用メモリ 356,088 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-10-18 14:52:08
合計ジャッジ時間 6,812 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:61:28: warning: C++20 says that these are ambiguous, even though the second is reversed:
   61 |             if (p[i] == p[j])   continue;
      |                            ^
main.cpp:21:10: note: candidate 1: 'bool P::operator==(const P&)'
   21 |     bool operator ==(const P &o){
      |          ^~~~~~~~
main.cpp:21:10: note: candidate 2: 'bool P::operator==(const P&)' (reversed)
main.cpp:21:10: note: try making the operator a 'const' member function

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define pii pair <int,int>
#define F first
#define S second
#define pb push_back
#define Task "SEGMENTS"

struct P{
    int x, y;
    P(int _x = 0, int _y = 0): x(_x), y(_y) {}

    void read(){
        cin >> x >> y;
    }

    P operator -(const P &o){
        return P(x - o.x, y - o.y);
    }

    bool operator ==(const P &o){
        return (x == o.x && y == o.y);
    }
};

int cross(const P &p1, const P &p2){
    return p1.x * p2.y - p1.y * p2.x;
}

const int N = 107;
int n, ans;
P a[N], b[N];
vector <P> p;

bool inter(P p1, P p2, P p3, P p4){
    // p1, p2: line
    // p3, p4: segment
    if (cross(p2 - p1, p4 - p3) == 0){
        if (cross(p2 - p1, p3 - p1) == 0)
            return true;
        return false;
    }
    int sign = cross(p2 - p1, p3 - p1), sign2 = cross(p2 - p1, p4 - p1);
    if ((sign > 0 && sign2 > 0) || (sign < 0 && sign2 < 0))
        return false;
    return true;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen(Task".inp", "r", stdin);
    // freopen(Task".out", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i ++){
        a[i].read(); b[i].read();
        p.pb(a[i]); p.pb(b[i]);
    }
    for (int i = 0; i < p.size(); i ++){
        for (int j = i + 1; j < p.size(); j ++){
            if (p[i] == p[j])   continue;
            int cnt = 0;
            for (int k = 1; k <= n; k ++){
                cnt += inter(p[i], p[j], a[k], b[k]);
            }
            ans = max(ans, cnt);
        }
    }
    cout << ans;
}

0