結果

問題 No.972 選び方のスコア
ユーザー WarToksWarToks
提出日時 2020-01-17 22:23:30
言語 C++17(clang)
(14.0.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 3,251 bytes
コンパイル時間 1,179 ms
コンパイル使用メモリ 109,548 KB
実行使用メモリ 5,628 KB
最終ジャッジ日時 2023-08-20 13:43:30
合計ジャッジ時間 5,557 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
5,504 KB
testcase_01 AC 58 ms
5,628 KB
testcase_02 AC 56 ms
5,572 KB
testcase_03 AC 29 ms
4,512 KB
testcase_04 AC 58 ms
5,616 KB
testcase_05 AC 58 ms
5,608 KB
testcase_06 AC 58 ms
5,492 KB
testcase_07 AC 44 ms
4,980 KB
testcase_08 AC 41 ms
5,520 KB
testcase_09 AC 39 ms
5,512 KB
testcase_10 AC 41 ms
5,572 KB
testcase_11 AC 41 ms
5,484 KB
testcase_12 AC 42 ms
5,564 KB
testcase_13 AC 44 ms
5,540 KB
testcase_14 AC 42 ms
5,528 KB
testcase_15 AC 47 ms
5,532 KB
testcase_16 AC 46 ms
5,496 KB
testcase_17 AC 46 ms
5,504 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 58 ms
5,496 KB
testcase_20 AC 57 ms
5,552 KB
testcase_21 AC 56 ms
5,496 KB
testcase_22 AC 55 ms
5,496 KB
testcase_23 AC 57 ms
5,504 KB
testcase_24 AC 57 ms
5,496 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <deque>
#include <functional>
#include <initializer_list>
#include <math.h>
#include <map>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

// グリッド上の縦横移動
constexpr std::array<std::pair<int, int>, 4> dxdy = {
    std::pair<int, int>( 1,  0),
    std::pair<int, int>(-1,  0),
    std::pair<int, int>( 0,  1),
    std::pair<int, int>( 0, -1)
};

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

template <typename T>
inline bool chmin(T& a, T b){
    if(b < a){ a = b; return true;}
    return false;
}

template <typename T>
inline bool chmax(T& a, T b){
    if(a < b){ a = b; return true;}
    return false;
}

inline bool isIn(int x, int y, int H, int W){
    return 0 <= x and x < H and 0 <= y and y < W;
}
inline bool bitUP(int state, int k){ return (state >> k) & 1; }
inline bool bitUP(long long int state, int k){ return (state >> k) & 1;}

// z-algorithm
template <class T> std::vector<int> z_algorithm(const T &str) {
    const int n = str.size();
    std::vector<int> resOfCP(n); resOfCP[0] = n;
    int i = 1, j = 0;
    while (i < n) {
        while (i + j < n and str[j] == str[i + j]) ++j;
        resOfCP[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i + k < n and k + resOfCP[k] < j) resOfCP[i + k] = resOfCP[k], ++k;
        i += k; j -= k;
    }
    return resOfCP;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


std::vector<lli> S;
std::vector<int> A;

int main(void){
    int n; scanf("%d", &n);
    A.resize(n); REP(i, n) scanf("%d", &A[i]);
    std::sort(A.begin(), A.end());
    S.resize(n + 1); S[0] = 0; REP(i, n) S[i+1] = S[i] + A[i];

    lli res = 0;
    REP(center, n){
        int count = n - 1 - center; if(count > center) count = center;
        int ok = 0, ng = count + 1;
        while(ng - ok > 1){
            int mid = (ng + ok) / 2;
            if(A[n - mid] + A[center - mid] > 2 * A[center]) ok = mid;
            else ng = mid;
        }
        lli T = S[n] - S[n - ok] + S[center] - S[center - ok];
        T -= 2LL * ok * A[center];
        if(res < T) res = T;
    }
    printf("%lld\n", res);
    




    

    

    
    return 0;
}
0