結果

問題 No.1144 Triangles
ユーザー IKyoproIKyopro
提出日時 2020-08-01 00:06:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,930 ms / 3,000 ms
コード長 3,639 bytes
コンパイル時間 2,732 ms
コンパイル使用メモリ 225,764 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 03:50:06
合計ジャッジ時間 27,247 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1,916 ms
4,376 KB
testcase_05 AC 1,919 ms
4,376 KB
testcase_06 AC 1,922 ms
4,376 KB
testcase_07 AC 1,930 ms
4,376 KB
testcase_08 AC 1,924 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1,773 ms
4,376 KB
testcase_15 AC 1,746 ms
4,376 KB
testcase_16 AC 1,864 ms
4,376 KB
testcase_17 AC 1,858 ms
4,380 KB
testcase_18 AC 1,854 ms
4,380 KB
testcase_19 AC 14 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1,794 ms
4,376 KB
testcase_23 AC 100 ms
4,376 KB
testcase_24 AC 1,762 ms
4,376 KB
testcase_25 AC 575 ms
4,376 KB
testcase_26 AC 56 ms
4,384 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 85 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: ラムダ関数内:
main.cpp:100:9: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
  100 |         };
      |         ^

ソースコード

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;
    map<pair<int,int>,int> mp;
    for(int i=0;i<N;i++){
        int x,y;
        cin >> x >> y;
        mp[{x,y}]++;
    }
    N = mp.size();
    vec<int> X(N),Y(N);
    vec<ll> Z(N);
    int c = 0;
    for(auto& x:mp){
        X[c] = x.first.first;
        Y[c] = x.first.second;
        Z[c] = x.second;
        c++;
    }
    mint ans = 0;

    auto solve = [&](vec<ll> A,vec<ll> B,mint cnt){
        int N = A.size();
        vec<int> idx(N);
        iota(idx.begin(),idx.end(),0);
        
        auto shogen = [](int x,int y){
            if(x<=0 && y<0) return 0;
            if(x>0 && y<=0) return 1;
            if(x>=0 && y>0) return 2;
            if(x<0 && y>=0) return 3;
        };
        
        sort(idx.begin(),idx.end(),[&](int i,int j){
            int a = shogen(A[i],B[i]),b = shogen(A[j],B[j]);
            if(a!=b) return a<b;
            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;
            }
            ans += (sy*A[idx[l]]-sx*B[idx[l]])*cnt;
            if(l!=N-1 && r!=l+1) sy -= B[idx[l+1]],sx -= A[idx[l+1]];
        }
    };

    for(int i=0;i<N;i++){
        vec<ll> A,B;
        map<pair<int,int>,pair<ll,ll>> mp;
        for(int j=0;j<N;j++) if(i!=j){
            int dx = X[j]-X[i],dy = Y[j]-Y[i];
            if(dx==0) dy /= abs(dy);
            else if(dy==0) dx /= abs(dx);
            else{
                int g = gcd(abs(dx),abs(dy));
                dx /= g,dy /= g;
            }
            mp[{dx,dy}].first += Z[j]*(X[j]-X[i]);
            mp[{dx,dy}].second += Z[j]*(Y[j]-Y[i]);
        }
        for(auto& x:mp){
            A.push_back(x.second.first);
            B.push_back(x.second.second);
        }
        solve(A,B,Z[i]);
    }

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