結果

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

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>

typedef long long ll;

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

        std::sort(a+1,a+N+1);
        a[0] = a[N+1] = X+1;
        int left = 1, 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