結果

問題 No.1374 Absolute Game
ユーザー Junyi ChenJunyi Chen
提出日時 2021-07-08 22:25:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,773 bytes
コンパイル時間 1,497 ms
コンパイル使用メモリ 170,052 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 05:04:09
合計ジャッジ時間 4,693 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/*
 * @Date         : 2021-06-13 23:59:15
 * @Author       : ssyze
 * @Description  : 
 */
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0) 
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r)
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}

int n;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    vi a(n);
    for (auto &x: a) cin >> x;
    sort(a.begin(), a.end());
    ll ans =  LONG_LONG_MIN, aa = 0, bb = 0;
    for (int i = 0; i < n; i++) {
        if (i & 1) bb += a[i];
        else aa += a[i];
    }
    ans = max(ans, abs(aa)-abs(bb));
    aa = 0, bb = 0;
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        if (i & 1) bb += a[i];
        else aa += a[i];
    }
    ans = max(ans, abs(aa)-abs(bb));
    cout << ans << '\n';
}
0