結果
| 問題 |
No.723 2つの数の和
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-29 10:13:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 928 bytes |
| コンパイル時間 | 826 ms |
| コンパイル使用メモリ | 66,436 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-10-12 08:09:35 |
| 合計ジャッジ時間 | 6,960 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 2 -- * 20 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;
template<typename T>
int binary_search_find_index(std::vector<T> v, int data) {
auto it = std::lower_bound(v.begin(), v.end(), data);
if (it == v.end() || *it != data) {
return -1;
} else {
std::size_t index = std::distance(v.begin(), it);
return index;
}
}
int main(void) {
ll x, n;
int idx;
int count = 0;
vector<ll> a;
cin >> n >> x;
for (int i = 0; i < n; ++i) {
ll temp;
cin >> temp;
a.push_back(temp);
}
sort(a.begin(), a.end());
for (int j = 0; j < n; ++j) {
if ((idx = binary_search_find_index(a, x - a[j])) >= 0) {
for (int i = idx; i < n; ++i) {
if (a[i] == x - a[j]) {
count++;
}
}
}
}
cout << count << endl;
}