結果

問題 No.1144 Triangles
ユーザー IKyoproIKyopro
提出日時 2020-07-31 22:25:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,852 bytes
コンパイル時間 2,391 ms
コンパイル使用メモリ 210,700 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-21 00:02:36
合計ジャッジ時間 49,029 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 AC 262 ms
4,380 KB
testcase_20 AC 13 ms
4,380 KB
testcase_21 AC 14 ms
4,376 KB
testcase_22 TLE -
testcase_23 AC 188 ms
4,376 KB
testcase_24 TLE -
testcase_25 AC 1,066 ms
4,380 KB
testcase_26 AC 102 ms
4,380 KB
testcase_27 AC 787 ms
4,376 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> X(N),Y(N);
    for(int i=0;i<N;i++) cin >> X[i] >> Y[i];
    mint ans = 0;


    auto solve = [&](vec<ll> A,vec<ll> B){
        int N = A.size();
        vec<int> idx(N);
        iota(idx.begin(),idx.end(),0);
        sort(idx.begin(),idx.end(),[&](int i,int j){
            long double la = atan2(B[i],A[i]);
            long double ra = atan2(B[j],A[j]);
            if(abs(la - ra) > 1) return la < ra;
            else return A[i] * B[j] > A[j] * B[i];
        });
        auto cross = [&](int i,int j){
            return A[i] * B[j] > A[j] * B[i];
        };
        mint sx = 0,sy = 0;
        int r = 0;
        for(int l=0;l<N;l++){
            if(l==r) r = (l+1)%N;
            while(r!=l && cross(idx[l],idx[r])){
                sx += A[idx[r]];
                sy += B[idx[r]];
                (r += 1)%=N;
            }
//            cerr << A[idx[l]] << " " << B[idx[l]] << " " << l << " " << r << "\n";
            ans += sy*A[idx[l]]-sx*B[idx[l]];
            if(l!=N-1 && r!=(l+1)%N) sy -= B[idx[l+1]],sx -= A[idx[l+1]];
        }
    };

    for(int i=0;i<N;i++){
        vec<ll> A,B;
        for(int j=0;j<N;j++) if(i!=j){
            A.push_back(X[j]-X[i]);
            B.push_back(Y[j]-Y[i]);
        }
        solve(A,B);
    }

    cout << ans/3 << "\n";
}
0