結果

問題 No.2835 Take and Flip
ユーザー C++ C++
提出日時 2024-08-09 21:55:07
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 3,068 bytes
コンパイル時間 4,058 ms
コンパイル使用メモリ 276,588 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-08-09 21:55:14
合計ジャッジ時間 5,724 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 29 ms
5,376 KB
testcase_04 AC 29 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 38 ms
5,376 KB
testcase_07 AC 39 ms
5,376 KB
testcase_08 AC 35 ms
5,376 KB
testcase_09 AC 40 ms
5,376 KB
testcase_10 AC 40 ms
5,376 KB
testcase_11 AC 40 ms
5,376 KB
testcase_12 AC 40 ms
5,376 KB
testcase_13 AC 39 ms
5,376 KB
testcase_14 AC 17 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 26 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 30 ms
5,376 KB
testcase_19 AC 37 ms
5,376 KB
testcase_20 AC 15 ms
5,376 KB
testcase_21 AC 36 ms
5,376 KB
testcase_22 AC 27 ms
5,376 KB
testcase_23 AC 13 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#if __has_include("debug.h")
#include "debug.h"
#else
#define print__(...) 10
#endif
using ll = long long;
using ld = long double;
using cd = complex<double>;
#define _overload4(_1,_2,_3,_4,name,...) name
#define _overload3(_1,_2,_3,name,...) name
#define _rep1(n) for(ll i=0;i<n;++i)
#define _rep2(i,n) for(ll i=0;i<n;++i)
#define _rep3(i,a,b) for(ll i=a;i<b;++i)
#define _rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) _overload4(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(n) for(ll i=n-1;i>=0;i--)
#define _rrep2(i,n) for(ll i=n-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=b-1;i>=a;i--)
#define _rrep4(i,a,b,c) for(ll i=a+(b-a-1)/c*c;i>=a;i-=c)
#define rrep(...) _overload4(__VA_ARGS__,_rrep4,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
#define each(i,a) for(auto &i:a)
#define sum(...) accumulate(range(__VA_ARGS__),0LL)
#define dsum(...) accumulate(range(__VA_ARGS__),double(0))
#define _range(i) (i).begin(),(i).end()
#define _range2(i,k) (i).begin(),(i).begin()+k
#define _range3(i,a,b) (i).begin()+a,(i).begin()+b
#define range(...) _overload3(__VA_ARGS__,_range3,_range2,_range)(__VA_ARGS__)
#define _rrange(i) (i).rbegin(),(i).rend()
#define _rrange2(i,k) (i).rbegin(),(i).rbegin()+k
#define _rrange3(i,a,b) (i).rbegin()+a,(i).rbegin()+b
#define rrange(...) _overload3(__VA_ARGS__,_rrange3,_rrange2,_rrange)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define elif else if
#define unless(a) if(!(a))
#define mp make_pair
#define ook order_of_key // order_of_key (k) : Number of items strictly smaller than k .
#define fbo find_by_order // find_by_order(k) : K-th element in a set (counting from zero).
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using vc = vector<T>;
template<typename T> using vvc = vector<vc<T>>;
template<typename T> using vvvc = vector<vvc<T>>;
template<typename T> using vvvvc = vector<vvvc<T>>;
template<class T> bool chmin(T& a, const T& b){ if(a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, const T& b){ if(a < b) {a = b; return true;} return false;}  
template<typename T> static constexpr T inf = numeric_limits<T>::max() / 2;

void _solve(){
  int N; cin >> N; //print__(N);
  vc<ll> A(N);
  each(x, A) cin >> x;
  //print__(A);

  sort(rrange(A));
  ll X = 0, Y = 0;
  rep(N){
    if(i & 1) Y -= A[i];
    else X += A[i];
  }
  cout << X - Y;
} 

void solve(bool testcase = true, bool query = false){
  int T = 1;
  if(testcase) cin >> T;
  while(T--){
    _solve();
    if(!query) cout << endl;
  }
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
  #endif
  cout << setprecision(16) << fixed;
  // init();
  solve(false);
}
0