結果

問題 No.972 選び方のスコア
ユーザー milanis48663220milanis48663220
提出日時 2020-04-11 21:46:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,731 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 86,628 KB
実行使用メモリ 6,840 KB
最終ジャッジ日時 2023-10-19 17:23:46
合計ジャッジ時間 5,164 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
6,816 KB
testcase_01 AC 41 ms
6,816 KB
testcase_02 AC 39 ms
6,740 KB
testcase_03 AC 24 ms
6,412 KB
testcase_04 AC 49 ms
6,816 KB
testcase_05 AC 49 ms
6,816 KB
testcase_06 AC 49 ms
6,816 KB
testcase_07 AC 31 ms
6,428 KB
testcase_08 AC 27 ms
6,816 KB
testcase_09 AC 26 ms
6,764 KB
testcase_10 AC 28 ms
6,760 KB
testcase_11 AC 29 ms
6,756 KB
testcase_12 AC 28 ms
6,816 KB
testcase_13 AC 29 ms
6,816 KB
testcase_14 AC 28 ms
6,816 KB
testcase_15 AC 29 ms
6,816 KB
testcase_16 AC 30 ms
6,816 KB
testcase_17 AC 29 ms
6,816 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
5,684 KB
testcase_26 AC 3 ms
5,684 KB
testcase_27 AC 2 ms
5,740 KB
testcase_28 AC 3 ms
5,684 KB
testcase_29 AC 2 ms
5,684 KB
testcase_30 AC 2 ms
5,740 KB
testcase_31 AC 2 ms
5,740 KB
testcase_32 AC 2 ms
5,740 KB
testcase_33 AC 2 ms
5,744 KB
testcase_34 AC 3 ms
5,688 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:57:12: warning: 'tmp' may be used uninitialized [-Wmaybe-uninitialized]
   57 |         ll tmp;
      |            ^~~
main.cpp:36:12: warning: 'tmp' may be used uninitialized [-Wmaybe-uninitialized]
   36 |         ll tmp;
      |            ^~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N;
ll a[200000];
ll sum[200001];

ll calc(int l, int r){
    return sum[r+1]-sum[l];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll ans = 0;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        a[i] *= 2;
    }
    sort(a, a+N);
    for(int i = 0; i < N; i++) sum[i+1] = sum[i]+a[i];
    for(int i = 1; i <= N-2; i++){
        int n_left = i;
        int n_right = N-i-1;
        int l = 1;
        int r = min(n_left, n_right);
        ll tmp;
        if(a[N-1]+a[0]-2*a[i] < 0){

        }else if(a[N-r]+a[r-1]-2*a[i] >= 0){
            tmp = calc(0, r-1)+calc(N-r, N-1)-2*r*a[i]; 
        }else{
            while(r-l > 1){
                int c = (l+r)/2;
                if(a[N-c]+a[c-1]-2*a[i] >= 0) l = c;
                else r = c;
            }
            tmp = calc(0, l-1)+calc(N-l, N-1)-2*l*a[i];
        }
        ans = max(ans, tmp);
    }
    for(int i = 1; i <= N-3; i++){
        int n_left = i;
        int n_right = N-i-2;
        int l = 1;
        int r = min(n_left, n_right);
        ll m = (a[i]+a[i+1])/2;
        ll tmp;
        if(a[N-1]+a[0]-2*m < 0){

        }else if(a[N-r]+a[r-1]-2*m >= 0){
            tmp = calc(0, r-1)+calc(N-r, N-1)-2*r*m; 
        }else{
            while(r-l > 1){
                int c = (l+r)/2;
                if(a[N-c]+a[c-1]-2*m >= 0) l = c;
                else r = c;
            }
            tmp = calc(0, l-1)+calc(N-l, N-1)-2*l*m;
        }
        ans = max(ans, tmp);
    }
    cout << ans/2 << endl;
}
0