結果
問題 | No.609 Noelちゃんと星々 |
ユーザー |
![]() |
提出日時 | 2020-07-24 21:23:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 709 bytes |
コンパイル時間 | 1,572 ms |
コンパイル使用メモリ | 169,616 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 20:24:02 |
合計ジャッジ時間 | 3,373 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=(0);i<(n);i++)using namespace std;typedef long long ll;typedef unsigned long long ull;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; }int main(){cin.tie(0);ios::sync_with_stdio(false);int n;cin >> n;vector<ll> y(n);rep(i, n) cin >> y[i];ll from = -1e10;ll to = 1e10;auto calc = [&y](ll x){ll ret = 0ll;for(ll z : y) ret += abs(z - x);return ret;};while(to - from > 1){ll mid = (from + to) / 2;(calc(mid) - calc(mid-1) > 0 ? to : from) = mid;}cout << calc(from) << endl;}