結果

問題 No.837 Noelちゃんと星々2
ユーザー kk
提出日時 2020-07-29 01:50:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 807 bytes
コンパイル時間 2,238 ms
コンパイル使用メモリ 207,088 KB
実行使用メモリ 8,144 KB
最終ジャッジ日時 2023-09-11 06:58:27
合計ジャッジ時間 5,517 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
8,064 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 57 ms
8,012 KB
testcase_04 AC 63 ms
8,044 KB
testcase_05 AC 59 ms
8,144 KB
testcase_06 AC 59 ms
8,044 KB
testcase_07 AC 58 ms
8,020 KB
testcase_08 AC 57 ms
8,028 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;

  set<int> s;
  vector<int> x(n);
  REP (i, n) {
    cin >> x[i];
    s.insert(x[i]);
  }

  if (s.size() == 1)
    cout << 1 << endl;
  else if (s.size() == 2)
    cout << 0 << endl;
  else {
    sort(x.begin(), x.end());

    int m = -1;

    for (int i = 1; i < n-1; i++) {
      int l = i / 2;
      int r = n - 1 - (n - i - 1) / 2;
      if (x[i] - x[l] >= x[r] - x[i]) {
        m = i;
        break;
      }
    }

    long long ret = 0;
    REP (i, m)
      ret += abs(x[m/2] - x[i]);
    for (int i = m; i < n; i++)
      ret += abs(x[n - 1 - (n - m - 1) / 2] - x[i]);
    
    cout << ret << endl;
  }
  
  return 0;
}
0