結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー | yuppe19 😺 |
提出日時 | 2015-06-16 11:52:32 |
言語 | C++11 (gcc 11.4.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,040 bytes |
コンパイル時間 | 367 ms |
コンパイル使用メモリ | 51,456 KB |
最終ジャッジ日時 | 2023-08-10 07:34:06 |
合計ジャッジ時間 | 750 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:9:1: error: ‘vector’ does not name a type; did you mean ‘perror’? vector<i64> c; ^~~~~~ perror main.cpp: In function ‘i64 calc(i64)’: main.cpp:15:42: error: ‘c’ was not declared in this scope for(int i : range(n)) { res += abs(p - c[i]); } ^ main.cpp: In function ‘int main()’: main.cpp:21:3: error: ‘c’ was not declared in this scope c.assign(n, 0); ^
ソースコード
#include <iostream> #include <algorithm> using namespace std; using i64 = long long; class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n; public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}}; vector<i64> c; int n; const i64 inf = 987654321987654321; i64 calc(i64 p) { i64 res = 0; for(int i : range(n)) { res += abs(p - c[i]); } return res; } int main(void) { i64 b; scanf("%lld%d", &b, &n); c.assign(n, 0); i64 summa = b; for(int i : range(n)) { scanf("%lld", &c[i]); summa += c[i]; } sort(c.begin(), c.end()); i64 lo = 0, hi = summa / n; while(hi - lo > 10) { i64 m1 = (lo + lo + hi) / 3, m2 = (lo + hi + hi) / 3; i64 r1 = calc(m1), r2 = calc(m2); if(r1 > r2) { lo = m1; } else { hi = m2; } } i64 res = inf; for(i64 x : range(lo, hi+1)) { res = min(res, calc(x)); } printf("%lld\n", res); return 0; }