結果
| 問題 | No.198 キャンディー・ボックス2 |
| コンテスト | |
| ユーザー |
oxyshower
|
| 提出日時 | 2019-08-24 17:59:34 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 919 bytes |
| 記録 | |
| コンパイル時間 | 1,605 ms |
| コンパイル使用メモリ | 168,540 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-14 13:07:18 |
| 合計ジャッジ時間 | 2,622 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 13 WA * 13 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
signed main(){
int b,n; cin >> b >> n;
vector<int> a(n);
bool check = true;
for(int i = 0; i < n; i++){
cin >> a[i];
if(i > 0 && a[i-1] != a[i]) check = false;
}
if(check){
cout << 0 << endl;
return 0;
}
auto f = [&](int t){
int cnt = 0;
for(int i = 0; i < n; i++){
cnt += abs(t - a[i]);
}
return cnt;
};
int left = 0,right = 1 << 30;
//[left , t1 , t2 , right]
for(int i = 0; i < 100; i++){
int t1 = (left * 2 + right) / 3;
int t2 = (left + right * 2) / 3;
t2 += 1;
if(f(t1) > f(t2)) left = t1;
else right = t2;
}
int ans = 1 << 30;
for(int i = left; i <= right; i++){
ans = min(ans,f(i));
if(ans == 0){
cout << i << endl;
return 0;
}
}
cout << ans << endl;
return 0;
}
oxyshower