結果

問題 No.3074 Divide Points Fairly
ユーザー srjywrdnprkt
提出日時 2025-03-28 21:48:39
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,363 bytes
コンパイル時間 4,087 ms
コンパイル使用メモリ 277,764 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2025-03-28 21:48:50
合計ジャッジ時間 6,569 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/modint>

using namespace std;
//using namespace atcoder;
using ll = long long;
//using mint = modint998244353;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    /*
       ax+by+c = 0
       a, bを乱択して半分に分けるbは二分探索で見つける。
       直線上に点が存在しなければそれが答え。
    */

    ll N, M=2e10;
    cin >> N;
    vector<ll> x(N*2), y(N*2);
    for (int i=0; i<N*2; i++) cin >> x[i] >> y[i];

    random_device seed;
    mt19937 engine(seed());
    uniform_int_distribution<> dist(-100000, 100000);

    while(1){
        ll a = dist(engine), b = dist(engine);
        if (a == 0 && b == 0) continue;
        ll l=-M-1, r=M, c;
        while(r-l>1){
            c = (l+r)/2;
            ll cnt=0;
            for (int i=0; i<N*2; i++){
                if (a*x[i]+b*y[i]+c>0) cnt++;
            }
            if (cnt >= N) r=c;
            else l=c;
        }
        ll cnt=0;
        bool f=1;
        for (int i=0; i<N*2; i++){
            ll z = a*x[i]+b*y[i]+r;
            if (z == 0){
                f = 0;
                break;
            }
            cnt += (z > 0);
        }
        if (f && (cnt == N)){
            cout << a << " " << b << " " << r << endl;
            return 0;
        }
    }
    
    return 0;
}
0