結果

問題 No.723 2つの数の和
ユーザー ajinoriajinori
提出日時 2018-08-04 16:06:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,157 bytes
コンパイル時間 1,574 ms
コンパイル使用メモリ 170,012 KB
実行使用メモリ 4,444 KB
最終ジャッジ日時 2023-10-19 21:50:03
合計ジャッジ時間 3,007 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 4 ms
4,348 KB
testcase_12 WA -
testcase_13 AC 37 ms
4,444 KB
testcase_14 AC 10 ms
4,348 KB
testcase_15 AC 16 ms
4,348 KB
testcase_16 AC 23 ms
4,348 KB
testcase_17 AC 30 ms
4,348 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 31 ms
4,444 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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{
            ans++;
            if(a[r]==a[r-1]) r--;
            else l++;
        }
    }
    ans *=2;
    if(a[l]+a[r]==x) ans+=1;
    cout << ans << endl;
    return 0;
}
0