結果
問題 | No.837 Noelちゃんと星々2 |
ユーザー | ate |
提出日時 | 2019-11-21 20:20:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,418 bytes |
コンパイル時間 | 2,238 ms |
コンパイル使用メモリ | 215,740 KB |
実行使用メモリ | 10,368 KB |
最終ジャッジ日時 | 2024-10-11 00:12:12 |
合計ジャッジ時間 | 4,530 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
testcase_30 | AC | 2 ms
5,248 KB |
testcase_31 | AC | 2 ms
5,248 KB |
testcase_32 | AC | 2 ms
5,248 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<(n);++i) using ll = long long; using pll = pair<ll,ll>; constexpr ll INF = (1LL<<60); constexpr ll MOD = (1e9+7); //constexpr ll MOD = (998244353); template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;} void dump(){cout<<endl;} template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);} template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;} template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;} template<class T>vector<T> make_vector(size_t a){return vector<T>(a);} template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));} void solve1();void solve2(); int main(){ solve1(); return 0; } void solve1(){ ll n; cin>>n; vector<ll> a(n); cin>>a; sort(a.begin(),a.end()); ll base1 = a[n/3]; ll base2 = a[n/3*2]; ll ans = 0; rep(i,n){ ans += min(abs(base1-a[i]),abs(base2-a[i])); } base1 = a[n/3+1]; base2 = a[n/3*2+1]; ll tmp = 0; rep(i,n){ tmp += min(abs(base1-a[i]),abs(base2-a[i])); } chmin(ans,tmp); tmp=0; base1 = a[n/3-1]; base2 = a[n/3*2-1]; rep(i,n){ tmp += min(abs(base1-a[i]),abs(base2-a[i])); } chmin(ans,tmp); tmp=0; base1 = a[n/3+1]; base2 = a[n/3*2-1]; rep(i,n){ tmp += min(abs(base1-a[i]),abs(base2-a[i])); } chmin(ans,tmp); tmp=0; base1 = a[n/3-1]; base2 = a[n/3*2+1]; rep(i,n){ tmp += min(abs(base1-a[i]),abs(base2-a[i])); } chmin(ans,tmp); tmp=0; base1 = a[n/3]; base2 = a[n/3*2-1]; rep(i,n){ tmp += min(abs(base1-a[i]),abs(base2-a[i])); } chmin(ans,tmp); tmp=0; base1 = a[n/3-1]; base2 = a[n/3*2]; rep(i,n){ tmp += min(abs(base1-a[i]),abs(base2-a[i])); } chmin(ans,tmp); tmp=0; base1 = a[n/3+1]; base2 = a[n/3*2]; rep(i,n){ tmp += min(abs(base1-a[i]),abs(base2-a[i])); } chmin(ans,tmp); tmp=0; base1 = a[n/3]; base2 = a[n/3*2+1]; rep(i,n){ tmp += min(abs(base1-a[i]),abs(base2-a[i])); } chmin(ans,tmp); map<ll,ll>cnt; rep(i,n)cnt[a[i]]++; if(cnt.size()==1)cout<<1<<endl; else if(cnt.size()==2)cout<<0<<endl; else cout<<ans<<endl; }