結果
| 問題 |
No.723 2つの数の和
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-08-04 16:18:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,296 bytes |
| コンパイル時間 | 1,510 ms |
| コンパイル使用メモリ | 170,600 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-19 17:49:35 |
| 合計ジャッジ時間 | 2,755 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 3 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pcnt __builtin_popcount
typedef long long ll;
const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main(){
int n;
ll x;
cin >> n >> x;
ll a[100100];
rep(i,n) cin >> a[i];
sort(a,a+n);
int r = n-1;
int l = 0;
ll ans = 0;
while(l<r){
if(a[l]+a[r] > x){
r--;
}else if(a[l]+a[r]<x){
l++;
}else{
int t = 1;
int tb = 1;
while(a[r]==a[r-1]) t++,r--;
while(a[l]==a[l+1]) tb++,l++;
if(r>l) ans += t*tb;
else ans += t*(t-1)/2;
l++;
}
}
ans *=2;
if(a[l]+a[r]==x) ans+=1;
cout << ans << endl;
return 0;
}