結果

問題 No.972 選び方のスコア
ユーザー hotman78hotman78
提出日時 2020-01-17 22:27:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 3,166 bytes
コンパイル時間 4,401 ms
コンパイル使用メモリ 360,464 KB
実行使用メモリ 6,472 KB
最終ジャッジ日時 2023-09-08 04:31:54
合計ジャッジ時間 8,215 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
6,236 KB
testcase_01 AC 69 ms
6,284 KB
testcase_02 AC 65 ms
5,940 KB
testcase_03 AC 33 ms
4,568 KB
testcase_04 AC 68 ms
6,344 KB
testcase_05 AC 68 ms
6,280 KB
testcase_06 AC 67 ms
6,280 KB
testcase_07 AC 51 ms
5,416 KB
testcase_08 AC 52 ms
6,224 KB
testcase_09 AC 51 ms
6,032 KB
testcase_10 AC 52 ms
6,228 KB
testcase_11 AC 53 ms
6,192 KB
testcase_12 AC 54 ms
6,128 KB
testcase_13 AC 54 ms
6,340 KB
testcase_14 AC 55 ms
6,228 KB
testcase_15 AC 59 ms
6,276 KB
testcase_16 AC 59 ms
6,336 KB
testcase_17 AC 58 ms
6,232 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 67 ms
6,160 KB
testcase_20 AC 67 ms
6,348 KB
testcase_21 AC 67 ms
6,276 KB
testcase_22 AC 65 ms
5,928 KB
testcase_23 AC 67 ms
6,472 KB
testcase_24 AC 67 ms
6,292 KB
testcase_25 AC 2 ms
4,356 KB
testcase_26 AC 1 ms
4,356 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 2 ms
4,356 KB
testcase_29 AC 2 ms
4,356 KB
testcase_30 AC 2 ms
4,356 KB
testcase_31 AC 2 ms
4,360 KB
testcase_32 AC 1 ms
4,356 KB
testcase_33 AC 1 ms
4,352 KB
testcase_34 AC 1 ms
4,356 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:41:19: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   41 | inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
      |                   ^~~~
main.cpp:41:33: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   41 | inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
      |                                 ^~~~
main.cpp:42:19: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   42 | inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
      |                   ^~~~
main.cpp:42:33: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   42 | inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
      |                                 ^~~~

ソースコード

diff #

#pragma GCC optimize("Ofast","unroll-loops")
//#pragma GCC push_options
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, less<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define MOD 1000000007LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};

lint bs(lint ok,lint ng,function<bool(lint)> func) {
    if(ok>ng){ok++;ng--;}
    else {ok--;ng++;}
	while(abs(ok-ng)>1){
		lint mid=(ng+ok)/2;
		if(func(mid))ok=mid;
		else ng=mid;
	}
    return ok;
}
int main(){
    lint n;
    cin>>n;
    vec a(n),v(n+1);
    rep(i,n)cin>>a[i];
    sort(all(a));
    v[0]=1;
    rep(i,n)v[i+1]=v[i]+a[i];
    lint ans=0;
    rep(i,n){
        if(min(n-i-1,i)==0)continue;
        lint x=bs(1,min(n-i-1,i),[&](lint x){
            return a[n-x]+a[i-x]>=2*a[i];
        });
        if(x!=0)chmax(ans,v[n]-v[n-x]+v[i]-v[i-x]-x*2*a[i]);
    }
    cout<<ans<<endl;
}
0