結果

問題 No.1144 Triangles
ユーザー fastmathfastmath
提出日時 2020-08-01 01:42:19
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 387 ms / 3,000 ms
コード長 2,731 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 164,292 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-07 00:23:22
合計ジャッジ時間 7,729 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int MOD = 1000 * 1000 * 1000 + 7;
int mod(int n) {
    n %= MOD;
    if (n < 0) return n + MOD;
    else return n;
}   
int fp(int a, int p) {
    int ans = 1, c = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = mod(ans * c);
        c = mod(c * c);
    }   
    return ans;
}   
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }

struct Point {
    int x, y;
    Point operator - (Point p) {
        return {x - p.x, y - p.y};  
    }  
    Point operator + (Point p) {
        return {x + p.x, y + p.y};
    };  
    int operator * (Point p) {
        return x * p.y - y * p.x;
    }   
    int operator % (Point p) {
        return x * p.x + y * p.y;
    }
    bool operator == (Point p) {
        return x == p.x && y == p.y;
    }   
};  

bool col(Point a, Point b) {
    return a % b > 0 && a * b == 0;
}   

bool half(Point a) {
    if (a.y == 0)
        return a.x < 0;
    else
        return a.y < 0;                
}   

Point v[4007];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif    
    int n;
    cin >> n;
    vector <Point> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].x >> a[i].y;
    }   
    int ans = 0;
    for (int s = 0; s < n; ++s) {
        int sz = 0;
        for (int i = 0; i < n; ++i) 
            if (!(a[s] == a[i]))
                v[sz++] = a[i] - a[s];
        auto comp = [] (Point a, Point b) { 
            return half(a) < half(b) || (half(a) == half(b) && a * b > 0);
        };
        sort(v, v + sz, comp);
        for (int i = sz; i < 2 * sz; ++i)
            v[i] = v[i - sz];
        int j = -1; Point sum = {0, 0};
        for (int i = 0; i < sz; ++i) {
            if (i > j) {
                assert(i == j + 1);
                j = i;
                sum = v[i];
            }   
            else {
                sum = sum - v[i-1];
            }
            while (j + 1 < i + sz && col(v[i], v[j]) && col(v[i], v[j+1])) {
                ++j;
                sum = sum + v[j];
            }
            while (j + 1 < i + sz && v[i] * v[j+1] > 0) {
                ++j;                    
                sum = sum + v[j];
            }
            ans += v[i] * sum;
            ans %= MOD;
        }   
    }
    cout << dv(ans, 3) << endl;
}
0