結果

問題 No.1144 Triangles
ユーザー t33ft33f
提出日時 2020-08-01 00:00:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 411 ms / 3,000 ms
コード長 2,503 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 81,436 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 03:45:33
合計ジャッジ時間 6,991 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,380 KB
testcase_04 AC 402 ms
4,380 KB
testcase_05 AC 411 ms
4,376 KB
testcase_06 AC 405 ms
4,376 KB
testcase_07 AC 399 ms
4,380 KB
testcase_08 AC 411 ms
4,376 KB
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,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 379 ms
4,380 KB
testcase_15 AC 372 ms
4,376 KB
testcase_16 AC 400 ms
4,376 KB
testcase_17 AC 394 ms
4,380 KB
testcase_18 AC 386 ms
4,380 KB
testcase_19 AC 26 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 384 ms
4,376 KB
testcase_23 AC 23 ms
4,376 KB
testcase_24 AC 370 ms
4,376 KB
testcase_25 AC 119 ms
4,376 KB
testcase_26 AC 13 ms
4,376 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 73 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: ラムダ関数内:
main.cpp:34:22: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   34 |                 auto [a, b] = p;
      |                      ^
main.cpp:35:22: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   35 |                 auto [c, d] = q;
      |                      ^

ソースコード

diff #

#include <cassert>
#include <algorithm>
#include <vector>
#include <numeric>
#include <iostream>
using namespace std;

using P = pair<int, int>;

long long cp(P p, P q) {
    return (long long)p.first * q.second - (long long)p.second * q.first;
}
long long ip(P p, P q) {
    return (long long)p.first * q.first + (long long)p.second * q.second;
}
P operator+(P p, P q) { return { p.first + q.first, p.second + q.second}; }
P operator-(P p, P q) { return { p.first - q.first, p.second - q.second}; }

bool par(P p, P q) {
    return cp(p, q) == 0 && ip(p, q) > 0;
}

const int M = 1000000007;

int main() {
    int n; cin >> n;
    P p[n]; for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        vector<P> q;
        for (int j = 0; j < n; j++) if (p[i] != p[j]) q.push_back(p[j] - p[i]);
        sort(q.begin(), q.end(), [](P p, P q) {
                if (p == q) return false;
                auto [a, b] = p;
                auto [c, d] = q;
                if (b > 0) {
                    if (d < 0) return true;
                    else if (d == 0) return c < 0;
                    else return cp(p, q) > 0;
                } else if (b == 0) {
                    if (a > 0) return true;
                    else return d < 0;
                } else {
                    if (d >= 0) return false;
                    else return cp(p, q) > 0;
                }
            });
        if (q.empty() || q.front() == q.back()) continue;
        // cerr << "center = " << p[i].first << " " << p[i].second << endl;
        // for (P x : q) cerr << "(" << x.first << ", " << x.second << "); "; cerr << endl;
        P S = {0, 0};
        const int m = q.size();
        for (int i = 0; i < m; i++) q.push_back(q[i]);
        for (int i = 0, j = 0; i < m; i++) {
            if (i == j) while (j < i + m && par(q[i], q[j])) { S = S + q[j]; j++; }
            while (j < i + m && cp(q[i], q[j]) > 0) {
                S = S + q[j];
                j++;
            }
            ans += cp(q[i], S);
            // cerr << "S = " << S.first << " " << S.second << endl;
            // cerr << "q[i] = " << q[i].first << " " << q[i].second << ' ' << i << endl;
            // cerr << "q[j] = " << q[j].first << " " << q[j].second << ' ' << j << endl;
            // cerr << "area = " << cp(q[i], S) << endl;
            S = S - q[i];
        }
        // cerr << ans % M << endl;
    }
    cout << ans % M * 333333336 % M << endl;
}
0