結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,540 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 18 ms
4,380 KB
testcase_04 AC 24 ms
4,560 KB
testcase_05 AC 21 ms
4,496 KB
testcase_06 AC 23 ms
4,528 KB
testcase_07 AC 10 ms
4,348 KB
testcase_08 AC 11 ms
4,348 KB
testcase_09 AC 22 ms
4,580 KB
testcase_10 AC 11 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 13 ms
4,348 KB
testcase_13 AC 23 ms
4,608 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 10 ms
4,348 KB
testcase_16 AC 14 ms
4,348 KB
testcase_17 AC 19 ms
4,472 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%lld",&N);
      |         ~~~~~^~~~~~~~~~~
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         scanf("%lld",&X);
      |         ~~~~~^~~~~~~~~~~
main.cpp:14:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |                  scanf("%lld",a+i+1);
      |                  ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#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 cnt = 0;


        for(int left = 1; left < N+1; left++){
                // X-a[left] <= a_right となる領域のうち左端を探索する
                int bl = 1, br = N+1;
                int b = bl;
                while(bl <= br){
                        b = (bl+br)/2;
                        if( X-a[left] < a[b]){
                                br = b-1;
                        }else if( X-a[left] > a[b]){
                                bl = b+1;
                        }else{ /* X-a[left] == a[b] */
                                while(X-a[left] == a[b-1]) b--;
                                break;
                        }
                }

                if(X-a[left] == a[b]){
                        while(X-a[left] == a[b]){
                                //printf("(%d,%d)\n",a[left],a[b]);
                                b++;
                                cnt++;
                        }
                }
        }

        printf("%d\n",cnt);
}
0