結果

問題 No.1144 Triangles
ユーザー fastmathfastmath
提出日時 2020-08-01 01:37:56
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,571 bytes
コンパイル時間 2,529 ms
コンパイル使用メモリ 134,320 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 05:53:03
合計ジャッジ時間 40,654 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
}   

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 atan2(a.y, a.x) < atan2(b.y, b.x); };
        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