結果

問題 No.2835 Take and Flip
ユーザー kazuppakazuppa
提出日時 2024-08-09 21:23:04
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 1,575 bytes
コンパイル時間 6,506 ms
コンパイル使用メモリ 337,080 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-09 21:23:15
合計ジャッジ時間 8,271 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 88 ms
6,944 KB
testcase_04 AC 96 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 89 ms
6,944 KB
testcase_07 AC 91 ms
6,940 KB
testcase_08 AC 83 ms
6,944 KB
testcase_09 AC 101 ms
6,940 KB
testcase_10 AC 107 ms
6,940 KB
testcase_11 AC 96 ms
6,940 KB
testcase_12 AC 104 ms
6,940 KB
testcase_13 AC 99 ms
6,940 KB
testcase_14 AC 39 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 65 ms
6,944 KB
testcase_17 AC 8 ms
6,940 KB
testcase_18 AC 75 ms
6,940 KB
testcase_19 AC 93 ms
6,940 KB
testcase_20 AC 35 ms
6,940 KB
testcase_21 AC 92 ms
6,944 KB
testcase_22 AC 65 ms
6,940 KB
testcase_23 AC 30 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
#define rep(i,a,b) for(it i=(it)(a);i<=(it)b;i++)
#define nrep(i,a,b) for(it i=(it)(a);i>=(it)b;i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define moda 998244353LL
#define modb 1000000007LL
#define dai 2500000000000000000LL
#define tyu 2500000000
#define en 3.14159265358979
#define sho -dai
#define eps 1e-14
#define yn(x) cout<<(x ? "Yes":"No")<<endl;
#define YN(x) cout<<(x ? "YES":"NO")<<endl;
using it=long long;
using un=unsigned long long;
using db=long double;
using st=string;
using ch=char;
using bo=bool;
using P=pair<it,it>;
using mint=modint;
using mints=modint998244353;
using vi=vector<it>;
using vd=vector<db>;
using vs=vector<st>;
using vc=vector<ch>;
using vb=vector<bo>;
using vp=vector<P>;
using vm=vector<mint>;
using sp=set<P>;
using ss=set<st>;
using sc=set<ch>;
using si=set<it>;
using svi=set<vi>;
using vvi=vector<vi>;
using vvd=vector<vd>;
using vvs=vector<vs>;
using vvb=vector<vb>;
using vvc=vector<vc>;
using vvp=vector<vp>;
using vvm=vector<vm>;
using vsi=vector<si>;
using vsp=vector<sp>;
using vvsi=vector<vsi>;
using vvsp=vector<vsp>;
using vvvi=vector<vvi>;
using vvvd=vector<vvd>;
using vvvvi=vector<vvvi>;

int main(){
  it n,x=0,y=0;cin>>n;
  vi a(n);
  rep(i,0,n-1)cin>>a[i];
  sort(all(a));
  deque<it> de;
  rep(i,0,n-1)de.push_back(a[i]);
  while(de.size()){
    x+=de.back();de.pop_back();
    if(de.size()){
      y+=de.front()*-1;
      de.pop_front();
    }
  }
  cout<<x-y<<endl;
}
0