結果

問題 No.1265 Balloon Survival
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-12-23 00:06:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 5,793 bytes
コンパイル時間 2,428 ms
コンパイル使用メモリ 220,484 KB
実行使用メモリ 16,232 KB
最終ジャッジ日時 2023-12-23 00:06:57
合計ジャッジ時間 4,901 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 11 ms
6,676 KB
testcase_15 AC 9 ms
6,676 KB
testcase_16 AC 5 ms
6,676 KB
testcase_17 AC 42 ms
16,228 KB
testcase_18 AC 6 ms
6,676 KB
testcase_19 AC 5 ms
6,676 KB
testcase_20 AC 10 ms
6,676 KB
testcase_21 AC 20 ms
7,408 KB
testcase_22 AC 13 ms
7,404 KB
testcase_23 AC 15 ms
7,404 KB
testcase_24 AC 74 ms
16,232 KB
testcase_25 AC 90 ms
16,232 KB
testcase_26 AC 75 ms
16,232 KB
testcase_27 AC 74 ms
16,232 KB
testcase_28 AC 74 ms
16,232 KB
testcase_29 AC 74 ms
16,232 KB
testcase_30 AC 73 ms
16,232 KB
testcase_31 AC 75 ms
16,232 KB
testcase_32 AC 73 ms
16,232 KB
testcase_33 AC 75 ms
16,232 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

// vector OA = (x, y)
template <typename T>
struct vec{
    T x, y;

    vec (T xx=0, T yy=0) : x(xx), y(yy) {};
    vec operator-() const {
      return vec(-x, -y);
    }
    vec& operator+=(const vec &w) {
        x += w.x; y += w.y;
        return *this;
    }
    vec& operator-=(const vec &w) {
        x -= w.x; y -= w.y;
        return *this;
    }
    vec operator+(const vec &w) const {
        vec res(*this);
        return res += w;
    }
    vec operator-(const vec &w) const {
        vec res(*this);
        return res-=w;
    }
    vec operator*=(T a){
        x *= a; y *= a;
        return *this;
    }
    vec operator*(T a){
        vec res(*this);
        return res*=a;
    }
    pair<T, T> to_pair() {return {x, y};}
};

//Inner product of vectors v and w
template <typename T>
T dot(vec<T> v, vec<T> w){
    return v.x * w.x + v.y * w.y;
}

//Outer product of vector v and w
template <typename T>
T outer(vec<T> v, vec<T> w){
    return v.x * w.y - w.x * v.y;
}

template <typename T>
vec<T> normalize(vec<T> &a){
    T x=a.x, y=a.y, g;
    if (x == 0) return vec((T)0,y/abs(y));
    else if (y == 0) return vec(x/abs(x), (T)0);
    g = abs(gcd(x, y));
    return vec(x/g, y/g);
}

//size of triangle ABC
template <typename T>
T heron(vec<T> &a, vec<T> &b, vec<T> &c){
    return abs(outer(b-a, c-a)) / 2;
}

//size of polygon A1A2...An
template <typename T>
T area(vector<vec<T>> P){
    int n=P.size();
    T S=0;
    for (int i=0; i<n; i++) S += outer(P[i], P[(i+1)%n]);

    return abs(S)/2;
}

//Distance between point a and b
template <typename T>
T distance(vec<T> &a, vec<T> &b){
    return dot(a-b, a-b);
}

//Manhattan distance between point a and b
template <typename T>
T manhattan(vec<T> &a, vec<T> &b){
    return abs(a.x-b.x)+abs(a.y-b.y);
}

//Argument of complex
template <typename T>
T arg(vec<T> a){
    complex<T> c(a.x, a.y);
    T res = arg(c);
    if (res < 0) res += M_PI*2;
    return res;
}

//rotation around origin
template <typename T>
vec<T> rotate(vec<T> &a, T theta){
    complex<T> c(a.x, a.y), p = polar((T)1, theta);
    c *= p;
    return vec(real(c), imag(c));
}

//Convex Hull(Smallest Convex set containing all given vecs)
//Grahum Scan (O(NlogN))
template <typename T>
vector<vec<T>> convex_hull(vector<vec<T>> P){

    sort(P.begin(), P.end(), [](vec<T> &p1, vec<T> &p2) {
        if (p1.x != p2.x) return p1.x < p2.x;
        return p1.y < p2.y;
    });

    int N=P.size(), k=0, t;
    vector<vec<T>> res(N*2);

    for (int i=0; i<N; i++){
        while(k > 1 && outer(res[k-1]-res[k-2], P[i]-res[k-1]) <= 0) k--;
        res[k] = P[i];
        k++;
    }
    t = k;

    for (int i=N-2; i>=0; i--){
        while(k > t && outer(res[k-1]-res[k-2], P[i]-res[k-1]) <= 0) k--;
        res[k] = P[i];
        k++;
    }
    res.resize(k-1);

    return res;
}

//Sorting by argument(O(NlogN))
template <typename T>
void arg_sort(vector<vec<T>> &P){
    int N=P.size();
    vector<vec<T>> U, L;

    for (int i=0; i<N; i++){
        if (P[i].y > 0) U.push_back(P[i]);
        else if (P[i].y < 0) L.push_back(P[i]);
        else{
            assert (P[i].x != 0);
            if (P[i].x > 0) U.push_back(P[i]);
            else L.push_back(P[i]);
        }
    }

    auto key=[](vec<T> const &a, vec<T> const &b)->bool{ return outer(a, b) > 0;};

    sort(U.begin(), U.end(), key);
    sort(L.begin(), L.end(), key);

    P = U;
    for (auto &x : L) P.push_back(x);
}

//judge if segment AB intersects segment CD
template <typename T>
bool intersect(vec<T> &a, vec<T> &b, vec<T> &c, vec<T> &d){
    T s, t;
    s = outer(b-a, c-a);
    t = outer(b-a, d-a);
    if (s == 0 && t == 0){
        if (max(a.x, b.x)<min(c.x, d.x) || max(a.y, b.y)<min(c.y, d.y) || min(a.x, b.x)>max(c.x, d.x) || min(a.y, b.y)>max(c.y, d.y)) return 0;
        else return 1;
    }
    if ((s > 0 && t > 0) || (s < 0 && t < 0)) return 0;
    s = outer(d-c, a-c);
    t = outer(d-c, b-c);
    if ((s > 0 && t > 0) || (s < 0 && t < 0)) return 0;

    return 1;
}

//straight line
template <typename T>
struct line{
    //ax+by+c=0
    T a, b, c;

    // Ax+By+C=0
    line (T A=0, T B=0, T C=0) : a(A), b(B), c(C) {};
    // line passing through p and q
    line (vec<T> &p, vec<T> &q) {a = (q.y-p.y); b = (p.x-q.x); c = -p.x*q.y + p.y*q.x;};

    T slope() {return (b == 0 ? numeric_limits<T>::infinity() : -a/b);}
    T intercept() {return (b == 0 ? numeric_limits<T>::infinity() : -c/b);}
};

//Intersection of straight lines p and q
template <typename T>
vec<T> intersection(line<T> &p, line<T> &q){
    T coef = - (T)1/(p.a*q.b-q.a*p.b), x, y;
    x = (q.b*p.c-p.b*q.c) * coef;
    y = (-q.a*p.c+p.a*q.c) * coef;
    return vec(x, y);
}

//distance between line PQ and point R
template <typename T>
T dist_line_point(vec<T> &p, vec<T> &q, vec<T> &r){
    // ax+by+c=0
    T a = (q.y-p.y), b = (p.x-q.x), c = -p.x*q.y + p.y*q.x;
    return abs(a*r.x+b*r.y-c) / sqrt(a*a+b*b);
};

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

    ll N, ans=0;
    ll x, y, d;

    cin >> N;
    vector<vec<ll>> p(N);

    for (int i=0; i<N; i++){
        cin >> x >> y;
        p[i] = vec(x, y);
    }

    vector<tuple<ll, ll, ll>> v;

    for (int i=0; i<N; i++){
        for (int j=i+1; j<N; j++){
            v.push_back({distance(p[i], p[j]), i, j});
        }
    }
    sort(v.begin(), v.end());
    unordered_set<ll> st;
    for (int i=1; i<N; i++) st.insert(i);    

    for (auto [d, i, j] : v){
        if (i == 0 && st.count(j)){
            ans++;
            st.erase(j);
        }
        if (st.count(i) && st.count(j)){
            st.erase(i);
            st.erase(j);
        }
    }

    cout << ans << endl;

    return 0;
}

0