結果

問題 No.2517 Right Triangles on Circle
ユーザー mhal-teddy
提出日時 2023-10-27 21:46:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 740 ms
コンパイル使用メモリ 78,588 KB
最終ジャッジ日時 2025-02-17 14:49:39
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>

using ll = long long;

bool binary_search(ll x, const std::vector<ll> &a, int n) {
    int left = -1, right = n;
    while (right - left > 1) {
        int mid = (left + right) / 2;
        if (x > a.at(mid)) left = mid;
        else if (x < a.at(mid)) right = mid;
        else {
            return true;
        }
    }
    return false;
}

int main() {
    int n;
    ll m;
    std::cin >> n >> m;
    std::vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        ll x;
        std::cin >> x;
        a.at(i) = x * 2;
    }
    std::sort(a.begin(), a.end());

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (binary_search(a.at(i) + m, a, n)) {
            ans += static_cast<ll>(n - 2);
        }
    }
    std::cout << ans << std::endl;
}
0