結果
問題 |
No.723 2つの数の和
|
ユーザー |
|
提出日時 | 2020-11-07 16:16:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 969 bytes |
コンパイル時間 | 1,022 ms |
コンパイル使用メモリ | 88,364 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-22 14:31:52 |
合計ジャッジ時間 | 2,862 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define MOD 1000000007 int main() { int n, x; cin >> n >> x; vector<int> a(n + 2); for (int i = 1; i <= n; ++i) { cin >> a[i]; } a[0] = -1, a[n + 1] = 1e9 + 1; sort(a.begin(), a.end()); ll ans = 0; for (int i = 1; i <= n; ++i) { int ok = 0, ng = n + 1; while (1 < abs(ok - ng)) { int mid = (ok + ng) / 2; if (a[mid] <= x - a[i]) { ok = mid; } else { ng = mid; } } int u = ok; ok = 0, ng = n + 1; while (1 < abs(ok - ng)) { int mid = (ok + ng) / 2; if (a[mid] < x - a[i]) { ok = mid; } else { ng = mid; } } int d = ok; ans += u - d; } cout << ans << endl; return 0; }