結果

問題 No.2517 Right Triangles on Circle
ユーザー mhal-teddymhal-teddy
提出日時 2023-10-27 21:46:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 851 ms
コンパイル使用メモリ 80,376 KB
実行使用メモリ 5,636 KB
最終ジャッジ日時 2023-10-27 21:46:55
合計ジャッジ時間 3,877 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 118 ms
5,636 KB
testcase_14 AC 116 ms
5,636 KB
testcase_15 AC 140 ms
5,636 KB
testcase_16 AC 136 ms
5,636 KB
testcase_17 AC 99 ms
5,108 KB
testcase_18 AC 93 ms
5,108 KB
testcase_19 AC 82 ms
4,844 KB
testcase_20 AC 84 ms
4,844 KB
testcase_21 AC 141 ms
5,636 KB
testcase_22 AC 39 ms
4,372 KB
testcase_23 AC 95 ms
4,844 KB
testcase_24 AC 48 ms
4,372 KB
testcase_25 AC 35 ms
4,372 KB
testcase_26 AC 128 ms
5,108 KB
testcase_27 AC 37 ms
4,372 KB
testcase_28 AC 21 ms
4,372 KB
testcase_29 AC 45 ms
4,372 KB
testcase_30 AC 26 ms
4,372 KB
testcase_31 AC 99 ms
4,844 KB
権限があれば一括ダウンロードができます

ソースコード

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