結果
| 問題 |
No.723 2つの数の和
|
| コンテスト | |
| ユーザー |
kaito_tateyama
|
| 提出日時 | 2019-03-06 07:33:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 917 bytes |
| コンパイル時間 | 753 ms |
| コンパイル使用メモリ | 76,936 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-23 14:29:43 |
| 合計ジャッジ時間 | 2,458 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define P(x) cout << (x) << "\n"
#define D(x) cerr << (x) << "\n"
#define fcout cout << fixed << setprecision(18)
using i64=long long int; // 10^18
vector<i64> a;
bool isOK(i64 index, i64 key){
if(a[index] >= key) return true;
else return false;
}
i64 binary_search(i64 key) {
i64 ng = -1;
i64 ok = (int)a.size();
while(abs(ok - ng) > 1){
i64 mid = ng + (ok - ng) / 2;
if(isOK(mid, key))ok = mid;
else ng = mid;
}
return ok;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
i64 x;cin>>x;
REP(i,n){
i64 in;cin>>in;
a.push_back(in);
}
i64 sum=0;
sort(a.begin(), a.end());
for(auto xx:a){
sum += binary_search(x - xx + 1) - binary_search(x - xx);
}
P(sum);
return 0;
}
kaito_tateyama