結果

問題 No.972 選び方のスコア
ユーザー asdf1asdf1
提出日時 2020-01-17 22:17:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,424 bytes
コンパイル時間 2,078 ms
コンパイル使用メモリ 204,464 KB
実行使用メモリ 9,304 KB
最終ジャッジ日時 2023-09-08 03:50:17
合計ジャッジ時間 6,646 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 42 ms
8,980 KB
testcase_02 AC 40 ms
8,904 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 41 ms
9,304 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 27 ms
9,000 KB
testcase_10 RE -
testcase_11 AC 29 ms
9,048 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 30 ms
9,080 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 RE -
testcase_20 WA -
testcase_21 WA -
testcase_22 RE -
testcase_23 WA -
testcase_24 RE -
testcase_25 AC 2 ms
5,472 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 2 ms
5,408 KB
testcase_29 AC 2 ms
5,380 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 2 ms
5,488 KB
testcase_33 RE -
testcase_34 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum[ohara], k, q;

int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  assert(n % 2 != 0);
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  rep(i, n) sum[i] = a[i];
  rrep(i, 1, n) sum[i] += sum[i - 1];

  rrep(i, 1, (n - 1) / 2 + 1) {
    ll add = sum[i - 1];
    add += sum[n - 1] - sum[n - i - 1];
    add -= a[i] * i * 2;
    ans = max(ans, add);
  }
  if (n % 2 == 0) {
    rep(i, n) { a[i] *= 2; }
    ll tyuu = (a[n / 2] + a[n / 2 - 1]) / 2;
    rep(i, n) { cnt += a[i] - tyuu; }
    cnt /= 2;
  }
  Cout(max(ans, cnt));
  return 0;
}
0