結果

問題 No.275 中央値を求めよ
ユーザー miznimizni
提出日時 2020-05-02 16:13:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 325 bytes
コンパイル時間 2,469 ms
コンパイル使用メモリ 204,268 KB
実行使用メモリ 54,636 KB
最終ジャッジ日時 2023-08-28 20:55:23
合計ジャッジ時間 7,549 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 95 ms
52,556 KB
testcase_08 AC 96 ms
52,764 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 96 ms
52,600 KB
testcase_13 AC 94 ms
52,428 KB
testcase_14 AC 95 ms
52,964 KB
testcase_15 WA -
testcase_16 AC 96 ms
53,008 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 95 ms
52,720 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 95 ms
54,076 KB
testcase_28 AC 94 ms
52,764 KB
testcase_29 AC 96 ms
53,492 KB
testcase_30 AC 93 ms
53,076 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 94 ms
52,704 KB
testcase_36 AC 94 ms
53,352 KB
testcase_37 WA -
testcase_38 AC 97 ms
52,604 KB
testcase_39 AC 98 ms
52,476 KB
testcase_40 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:6:18: 警告: ‘n’ is used uninitialized [-Wuninitialized]
    6 |   vector<int> a(n);
      |                  ^
main.cpp:5:7: 備考: ‘n’ はここで宣言されています
    5 |   int n, b, ans;
      |       ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, b, ans;
  vector<int> a(n);

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b;
    a.push_back(b);
  }
  sort(a.begin(), a.end());
  if (n % 2 == 0) {
    cout << (a[n / 2 - 1] + a[n / 2]) / 2 << endl;
  } else {
    cout << a[n / 2] << endl;
  }
}
0