Submission #68351274


Source Code Expand

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }
    map<pair<ll, ll>, ll> mp;
    map<tuple<ll, ll, ll, ll>, ll> mp2;
    ll res = 0, res2 = 0;
    auto calc = [&](ll x1, ll y1, ll x2, ll y2) -> pair<ll, ll> {
        if (x1 == x2) return {0, 1};
        if (y1 == y2) return {1, 0};
        if (x1 > x2) {
            swap(x1, x2);
            swap(y1, y2);
        }
        ll dx = x2 - x1, dy = y2 - y1;
        ll g = __gcd(abs(dx), abs(dy));
        dx /= g, dy /= g;
        return {dx, dy};
    };
    vector<pair<ll, ll>> v1;
    vector<tuple<ll, ll, ll, ll>> v2;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            ll x1 = x[i], y1 = y[i];
            ll x2 = x[j], y2 = y[j];
            auto [dx, dy] = calc(x1, y1, x2, y2);
            //            cout << "(" << x1 << ", " << y1 << ") to (" << x2 << ", " << y2 << ") => " << dx << ", " << dy << endl;
            v1.emplace_back(dx, dy);
            v2.emplace_back(dx, dy, abs(x1 - x2), abs(y1 - y2));
            //            res += mp[{dx, dy}];
            //            res2 += mp2[{dx, dy, abs(x1 - x2), abs(y1 - y2)}];
            //            mp[{dx, dy}]++;
            //            mp2[{dx, dy, abs(x1 - x2), abs(y1 - y2)}]++;
        }
    }
    //    cout << res << endl;
    //    cout << res2 << endl;
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    for (int i = 0; i < v1.size();) {
        int cnt = 0;
        auto cp = v1[i];
        while (i < v1.size() && v1[i] == cp) {
            cnt++;
            i++;
        }
        res += (ll)cnt * (cnt - 1) / 2;
    }
    for (int i = 0; i < v2.size();) {
        int cnt = 0;
        auto cp = v2[i];
        while (i < v2.size() && v2[i] == cp) {
            cnt++;
            i++;
        }
        res2 += (ll)cnt * (cnt - 1) / 2;
    }
    cout << res - res2 / 2 << endl;
}

Submission Info

Submission Time
Task E - Trapezium
User KKT89
Language C++ 20 (gcc 12.2)
Score 475
Code Size 2339 Byte
Status AC
Exec Time 640 ms
Memory 97204 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:54:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   54 |     for (int i = 0; i < v1.size();) {
      |                     ~~^~~~~~~~~~~
Main.cpp:57:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   57 |         while (i < v1.size() && v1[i] == cp) {
      |                ~~^~~~~~~~~~~
Main.cpp:63:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::tuple<long long int, long long int, long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   63 |     for (int i = 0; i < v2.size();) {
      |                     ~~^~~~~~~~~~~
Main.cpp:66:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::tuple<long long int, long long int, long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   66 |         while (i < v2.size() && v2[i] == cp) {
      |                ~~^~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 2
AC × 28
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt
All 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 1 ms 3520 KiB
00-sample-02.txt AC 1 ms 3464 KiB
01-01.txt AC 1 ms 3484 KiB
01-02.txt AC 22 ms 8412 KiB
01-03.txt AC 504 ms 85392 KiB
01-04.txt AC 249 ms 44384 KiB
01-05.txt AC 616 ms 97088 KiB
01-06.txt AC 618 ms 97164 KiB
01-07.txt AC 439 ms 96984 KiB
01-08.txt AC 435 ms 95936 KiB
01-09.txt AC 425 ms 93788 KiB
01-10.txt AC 331 ms 85360 KiB
01-11.txt AC 294 ms 85404 KiB
01-12.txt AC 605 ms 97032 KiB
01-13.txt AC 601 ms 97108 KiB
01-14.txt AC 617 ms 97028 KiB
01-15.txt AC 632 ms 97000 KiB
01-16.txt AC 624 ms 97000 KiB
01-17.txt AC 639 ms 97012 KiB
01-18.txt AC 640 ms 97036 KiB
01-19.txt AC 627 ms 96960 KiB
01-20.txt AC 626 ms 97084 KiB
01-21.txt AC 621 ms 97092 KiB
01-22.txt AC 617 ms 97088 KiB
01-23.txt AC 629 ms 97156 KiB
01-24.txt AC 630 ms 97200 KiB
01-25.txt AC 629 ms 96956 KiB
01-26.txt AC 626 ms 97204 KiB