結果

問題 No.1374 Absolute Game
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-09-07 16:13:54
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 947 bytes
コンパイル時間 5,179 ms
コンパイル使用メモリ 309,288 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 16:14:04
合計ジャッジ時間 8,261 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 35 ms
4,376 KB
testcase_10 AC 41 ms
4,380 KB
testcase_11 AC 26 ms
4,380 KB
testcase_12 AC 16 ms
4,376 KB
testcase_13 AC 32 ms
4,376 KB
testcase_14 AC 49 ms
4,376 KB
testcase_15 AC 48 ms
4,376 KB
testcase_16 AC 48 ms
4,380 KB
testcase_17 AC 48 ms
4,376 KB
testcase_18 AC 48 ms
4,376 KB
testcase_19 AC 48 ms
4,384 KB
testcase_20 AC 19 ms
4,376 KB
testcase_21 AC 24 ms
4,380 KB
testcase_22 AC 48 ms
4,380 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 10 ms
4,376 KB
testcase_26 AC 16 ms
4,380 KB
testcase_27 AC 22 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<ll,ll>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
  int n;cin>>n;
  vc<ll>v(n); rep(i,n)cin>>v[i];
  sort(all(v));
  ll sa=0,sb=0; 
  rep(i,(n+1)/2)sa+=v[i]; for(int i=(n+1)/2;i<n;i++)sb+=v[i];
  ll res=abs(sa)-abs(sb);
  sa=0,sb=0;
  rep(i,n){
    if(i&1)sb+=v[i];
    else sa+=v[i];
  }
  res=min(res,abs(sa)-abs(sb));
  sa=0,sb=0;
  rep(i,n/2)sb+=v[i]; for(int i=n/2;i<n;i++)sa+=v[i];
  ll res2=abs(sa)-abs(sb);
  sa=0,sb=0; 
  for(int i=n-1;i>=0;i--){
    if((n-i)&1)sa+=v[i];
    else sb+=v[i];
  }
  res2=min(res2,abs(sa)-abs(sb));
  ll ans=max(res,res2);
  cout<<ans;
}
0