結果
問題 |
No.723 2つの数の和
|
ユーザー |
![]() |
提出日時 | 2018-08-03 23:04:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 775 bytes |
コンパイル時間 | 713 ms |
コンパイル使用メモリ | 79,452 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-19 17:38:17 |
合計ジャッジ時間 | 2,012 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 12 |
ソースコード
#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<stack> using namespace std; #define REP(i,n) for(int i=0;(i)<(n);(i)++) #define ll long long int N, X; int a[100005]; int ans; signed main() { cin >> N >> X; for (int i = 0;i < N;i++) { cin >> a[i]; } sort(a, a+N); ans = 0; int l = 0; int r = N - 1; while (l < r) { int tmp = a[l] + a[r]; //cout << tmp << endl; if (tmp < X) l++; else if (tmp > X) r--; else if (tmp == X) { ans++; while (a[l] == a[l + 1] && l < N-1) { l++; ans++; } while (a[r] == a[r - 1] && r > 0) { r--; ans++; } l++; } } ans *= 2; if (a[l] + a[r] == X)ans++; cout << ans << endl; return 0; }