Submission #1370400

#TimeUsernameProblemLanguageResultExecution timeMemory
1370400dienhaidangRotating Lines (APIO25_rotate)C++17
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>
#include <map>

using namespace std;

// Tự viết hàm GCD để không phụ thuộc vào thư viện <numeric>
long long get_gcd(long long a, long long b) {
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

int main() {
    // Tối ưu hóa I/O để chống Time Limit Exceeded (TLE)
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    // Đọc số lượng đường thẳng
    if (!(cin >> n)) return 0;

    long long ans = 0;
    map<pair<long long, long long>, int> cnt;

    for (int i = 0; i < n; ++i) {
        long long x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        
        // Tính vector chỉ phương (a, b) từ 2 điểm
        long long a = x2 - x1;
        long long b = y2 - y1;

        // Bỏ qua trường hợp lỗi dữ liệu (2 điểm trùng nhau)
        if (a == 0 && b == 0) continue; 

        // Rút gọn vector bằng ước chung lớn nhất (GCD) tự viết
        long long g = get_gcd(a, b);
        long long norm_a = a / g;
        long long norm_b = b / g;

        // Chuẩn hóa dấu để các vector đối nhau cùng quy về một hướng
        if (norm_a < 0 || (norm_a == 0 && norm_b < 0)) {
            norm_a = -norm_a;
            norm_b = -norm_b;
        }

        // Dùng make_pair an toàn tuyệt đối cho mọi phiên bản C++
        ans += cnt[make_pair(norm_a, norm_b)]++; 
    }

    // In ra tổng số cặp thỏa mãn
    cout << ans << "\n";
    return 0;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccZh7YY8.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccvd25fC.o:rotate.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccZh7YY8.o: in function `main':
grader.cpp:(.text.startup+0x28f): undefined reference to `energy(int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status