結果

問題 No.2517 Right Triangles on Circle
ユーザー ardririyardririy
提出日時 2023-10-27 22:26:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 2,412 bytes
コンパイル時間 2,283 ms
コンパイル使用メモリ 212,664 KB
実行使用メモリ 5,564 KB
最終ジャッジ日時 2023-10-27 22:26:20
合計ジャッジ時間 4,405 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 76 ms
5,564 KB
testcase_14 AC 53 ms
5,564 KB
testcase_15 AC 81 ms
5,564 KB
testcase_16 AC 75 ms
5,564 KB
testcase_17 AC 61 ms
5,036 KB
testcase_18 AC 59 ms
5,036 KB
testcase_19 AC 50 ms
4,772 KB
testcase_20 AC 52 ms
4,772 KB
testcase_21 AC 78 ms
5,564 KB
testcase_22 AC 17 ms
4,348 KB
testcase_23 AC 56 ms
4,772 KB
testcase_24 AC 26 ms
4,348 KB
testcase_25 AC 15 ms
4,348 KB
testcase_26 AC 67 ms
5,300 KB
testcase_27 AC 15 ms
4,348 KB
testcase_28 AC 12 ms
4,348 KB
testcase_29 AC 24 ms
4,348 KB
testcase_30 AC 16 ms
4,348 KB
testcase_31 AC 56 ms
4,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n); i >= 0; i--)
#define itrep(itr, stl) for (auto itr = stl.begin(); itr != stl.end(); itr++)
#define Vec2D(type, n, m, val) vector<vector<type>>(n, vector<type>(m, val))
#define print(x) cout << x << endl
#define all(a) a.begin(), a.end()
const int INF = LLONG_MAX;
const int N_INF = LLONG_MIN;
using namespace std;
class UnionFind {
   private:
    map<int, int> uf;

   public:
    int root(int n) {
        if (uf.find(n) == uf.end()) uf[n] = -1;
        if (uf[n] < 0)
            return n;
        else
            return uf[n] = root(uf[n]);
    }
    bool connected(int a, int b) { return root(a) == root(b); }
    void marge(int a, int b) {
        int root_a = root(a);
        int root_b = root(b);
        if (root_a != root_b) {
            if (uf[root_a] > uf[root_b]) swap(root_a, root_b);
            uf[root_a] += uf[root_b];
            uf[root_b] = root_a;
        }
    }
    int size(int n) { return -uf[root(n)]; }
};
bool chmin(int &a, int b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
bool chmax(int &a, int b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int power(int x, int n) {
    int result = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            result *= x;
        }
        x *= x;
        n >>= 1;
    }
    return result;
} /*x^nを計算*/
int b_search(vector<int> &v, int k) {
    int ng = -1, ok = v.size();
    while (abs(ng - ok) > 1) {
        int mid = ok + (ng - ok) / 2;
        if (v[mid] >= k)
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

void solve() {
    // hogehoge
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    sort(all(a));

    int ans = 0;

    rep(i, n) {
        int a_j = 2 * a[i] + m;
        if (a_j % 2 != 0) continue;
        a_j /= 2;
        int idx = b_search(a, a_j);
        if (idx >= n || a[idx] != a_j) continue;
        else {
            ans += n - 2;
            // print(i << " " << idx);
        }
    }

    print(ans);

}

signed main() {
    std::cout << std::fixed;
    std::cout << std::setprecision(20);
    std::cin.tie(0)->sync_with_stdio(0);
    int times = 1;
    // cin >> times;
    while (times--) solve();
    return 0;
}
0