結果

問題 No.723 2つの数の和
ユーザー LaylaLayla
提出日時 2018-08-14 13:04:46
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 690 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 44,644 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 17:03:02
合計ジャッジ時間 3,698 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 1 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 WA -
testcase_12 WA -
testcase_13 AC 21 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 12 ms
4,348 KB
testcase_17 AC 17 ms
4,348 KB
testcase_18 RE -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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