結果

問題 No.1144 Triangles
ユーザー chielochielo
提出日時 2020-08-01 00:12:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,949 bytes
コンパイル時間 1,557 ms
コンパイル使用メモリ 168,588 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-21 03:54:32
合計ジャッジ時間 5,985 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 5 ms
4,380 KB
testcase_28 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: メンバ関数 ‘double vec::arc()’ 内:
main.cpp:22:5: 警告: 非 void を戻す関数内に return 文がありません [-Wreturn-type]
   22 |     }
      |     ^

ソースコード

diff #

#include <bits/stdc++.h>

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

int n, m;
struct vec {
    ll x, y;
    double a;
    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;
    }
    ll dot(const vec &k) const {
        return x * k.x + y * k.y;
    }
    double arc() {
        a = atan2(y, 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;
    uxs %= mo;
    uys %= mo;
}
void addV(int i, ll d) {
    vxs += b[i].x * d;
    vys += b[i].y * d;
    vxs %= mo;
    vys %= mo;
}

bool check(int i, int j) {
    ll c = b[i].cross(b[j]);
    ll d = b[i].dot(b[j]);
    return c > 0 || c == 0 && d > 0;
}

void subsolve() {
    std::sort(b, b + m, [](const vec &u, const vec &v) {
        return u.a < v.a;
    });
    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 < m && j - i < m && check(i, j % m)) {
            addV(j % m, -1);
            addU(j % m, +1);
            j += 1;
        }
        vec us{uxs, uys};
        vec vs{vxs, vys};
        ans = (ans + b[i].cross(us) % mo - b[i].cross(vs) % mo) % mo;
        if(j > i) {
            addU(i, -1);
            i += 1;
        } else {
            addV(i, -1);
            i += 1;
            j += 1;
        }
    }
}

void solve(int s) {
    m = 0;
    for(int j = s + 1; j < n; ++j) {
        if(a[s].x != a[j].x || a[s].y != a[j].y) {
            b[m] = a[j] - a[s];
            b[m].arc();
            m += 1;
        }
    }
    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 % mo + mo) % mo);
    return 0;
}
0