結果

問題 No.1144 Triangles
ユーザー fastmathfastmath
提出日時 2020-07-31 22:32:53
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,310 bytes
コンパイル時間 5,758 ms
コンパイル使用メモリ 136,032 KB
実行使用メモリ 74,380 KB
最終ジャッジ日時 2023-09-21 00:59:42
合計ジャッジ時間 10,016 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define double long double
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
const int N = 2007, C = 1e4 + 7, 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)); }

int n, ans = 0;
struct Point { 
    int x, y; 
    bool operator < (Point p) { return (y < p.y) || (y == p.y && x > p.x); }
} a[N];
int cp(int x1, int y1, int x2, int y2) { return x1 * y2 - y1 * x2; }
struct Line {
    int x, y, i, j;
    bool operator < (Line l) { 
        int t = cp(x, y, l.x, l.y);
        return t > 0 || (t == 0 && i < l.i) || (t == 0 && i == l.i && j < l.j); 
    }
};  
int pos[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i].x >> a[i].y; a[i].x += C; a[i].y += C; }
    sort(a, a + n);
    vector <Line> l;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            l.app({a[j].x - a[i].x, a[j].y - a[i].y, i, j});
        }
    }
    for (int i = 0; i < n; ++i) pos[i] = i;
    sort(all(l));
    int ptr = 0;
    while (ptr < l.size()) {
        int t = ptr;
        vector <Line> mem;
        while (ptr < l.size() && cp(l[t].x, l[t].y, l[ptr].x, l[ptr].y) == 0) {
            auto &e = l[ptr];
            mem.app(e);
            swap(pos[e.i], pos[e.j]);
            ++ptr;
        }

        vector <Point> ord(n);
        for (int i = 0; i < n; ++i) {
            ord[pos[i]] = a[i];
        }   
        
        for (auto e : mem) {
            int j = e.i, k = e.j;
            int C = a[j].x * a[k].y - a[j].y * a[k].x;
            int A = (a[j].y - a[k].y);
            int B = (a[k].x - a[j].x);
            for (int i = 0; i < n; ++i) {
                ans += abs(C + ord[i].x * A + ord[i].y * B);
            }   
        }
    }
    cout << dv(ans, 3) << '\n';
} 
0