結果

問題 No.723 2つの数の和
ユーザー weizenweizen
提出日時 2018-08-04 20:29:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 805 bytes
コンパイル時間 475 ms
コンパイル使用メモリ 59,640 KB
実行使用メモリ 4,620 KB
最終ジャッジ日時 2023-10-19 21:57:04
合計ジャッジ時間 1,596 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
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 20 ms
4,612 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 13 ms
4,348 KB
testcase_17 AC 17 ms
4,476 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,348 KB
testcase_21 WA -
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 14 ms
4,620 KB
testcase_24 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%lld",&N);
      |         ~~~~~^~~~~~~~~~~
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%lld",&X);
      |         ~~~~~^~~~~~~~~~~
main.cpp:12:41: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         for(int i = 0; i < N; i++) scanf("%lld",a+i);
      |                                    ~~~~~^~~~~~~~~~~~

ソースコード

diff #

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

typedef long long ll;

ll a[100000];
int main(){
        ll N,X;
        scanf("%lld",&N);
        scanf("%lld",&X);
        for(int i = 0; i < N; i++) scanf("%lld",a+i);

        std::sort(a,a+N);
        int left = 0, right = N-1;
        int cnt = 0;

        while(1){
                while(a[left]+a[right]>X){
                        right--;
                        if(left >= right) break;
                }
                if(a[left]+a[right] == X){
                        if(left==right) cnt += 1;
                        else            cnt += 2;
                        right--;
                }else{
                        left++;
                }
                if(left > right) break;
        }
        printf("%d\n",cnt);
}
0