結果

問題 No.1144 Triangles
ユーザー chielochielo
提出日時 2020-07-31 23:26:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,551 bytes
コンパイル時間 1,612 ms
コンパイル使用メモリ 168,196 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-21 02:58:20
合計ジャッジ時間 5,056 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using ll = long long;
const int maxn = 2e3 + 3;
const ll mo = 1e9 + 7, tp = 5e8 + 4;

int n, m;
struct vec {
    ll x, y;
    vec operator-(const vec &k) const {
        return {x - k.x, y - k.y};
    }
    ll cross(const vec &k) const {
        return x * k.y - y * k.x;
    }
} a[maxn], b[maxn];

ll ans = 0, uxs, vxs, uys, vys;

void addU(int i, ll d) {
    uxs += b[i].x * d;
    uys += b[i].y * d;
}
void addV(int i, ll d) {
    vxs += b[i].x * d;
    vys += b[i].y * d;
}

void subsolve() {
    std::sort(b, b + m, [](const vec &u, const vec &v) {
        return u.cross(v) > 0;
    });
    uxs = vxs = uys = vys = 0;
    for(int i = 0; i < m; ++i)
        addV(i, 1);
    for(int i = 0, j = 0; i < m;) {
        while(j - i < m && b[i].cross(b[j % m]) >= 0) {
            addV(j % m, -1);
            addU(j % m, +1);
            j += 1;
        }
        vec us{uxs, uys};
        vec vs{vxs, vys};
        ans = (ans + std::abs(b[i].cross(us)) % mo + std::abs(b[i].cross(vs)) % mo) % mo;
        if(j > i) {
            addU(i, -1);
            addV(i, +1);
            i += 1;
        } else {
            i += 1;
            j += 1;
        }
    }
}

void solve(int s) {
    m = 0;
    for(int j = s + 1; j < n; ++j) {
        b[m++] = a[j] - a[s];
    }
    subsolve();
}

int main() {
    scanf("%d", &n);
    for(int i = 0; i < n; ++i) {
        scanf("%lld%lld", &a[i].x, &a[i].y);
    }
    for(int i = 0; i < n; ++i) {
        solve(i);
    }
    printf("%lld\n", (ans * tp % mo + mo) % mo);
    return 0;
}
0