結果

問題 No.723 2つの数の和
ユーザー Layla
提出日時 2018-08-14 13:04:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 690 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 44,612 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-24 08:41:20
合計ジャッジ時間 3,544 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 7 WA * 14 RE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |     scanf("%d%lld", &array_len, &x);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:15:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         scanf("%d", &temp);
      |         ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <vector>

typedef long long int ll;

int main(void) {
    int array_len;
    ll x;
    scanf("%d%lld", &array_len, &x);
    std::vector<int> a;

    for (int i = 0; i < array_len; ++i) {
        int temp = 0;
        scanf("%d", &temp);
        a.push_back(temp);
    }

    std::sort(a.begin(), a.end());

    int count = 0;
    for (int i = 0; i < array_len; i++) {
        int tgt = x - a[i];
        if (std::binary_search(a.begin(), a.end(), tgt)) {
            int j = 1;
            count++;
            while (a[i + j] == tgt) {
                j++;
                count++;
            }
        }
    }
    printf("%d\n", count);
}
0