結果

問題 No.723 2つの数の和
ユーザー kaito_tateyamakaito_tateyama
提出日時 2019-03-06 07:33:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 917 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 75,412 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 19:02:54
合計ジャッジ時間 2,168 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 22 ms
4,376 KB
testcase_04 AC 31 ms
4,376 KB
testcase_05 AC 28 ms
4,380 KB
testcase_06 AC 28 ms
4,376 KB
testcase_07 AC 13 ms
4,380 KB
testcase_08 AC 15 ms
4,380 KB
testcase_09 AC 30 ms
4,376 KB
testcase_10 AC 12 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 31 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 14 ms
4,376 KB
testcase_16 AC 19 ms
4,376 KB
testcase_17 AC 27 ms
4,376 KB
testcase_18 AC 21 ms
4,380 KB
testcase_19 AC 26 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 27 ms
4,380 KB
testcase_24 AC 10 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0