結果
| 問題 |
No.378 名声値を稼ごう
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-12 03:34:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 507 bytes |
| コンパイル時間 | 1,310 ms |
| コンパイル使用メモリ | 161,508 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-30 03:23:08 |
| 合計ジャッジ時間 | 1,835 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
ll n;
cin >> n;
vector<ll> a;
ll sum = 0;
while (n) {
a.push_back(n);
sum += n;
n >>= 1;
}
vector<ll> cum = a;
for (int i = cum.size() - 2; i >= 0; i--) {
cum[i] += cum[i + 1];
}
ll ans = 0;
for (int i = 0; i < a.size(); i++) {
if (2 * a[i] < cum[i]) {
ans += a[i];
} else {
ans += 2 * a[i];
break;
}
}
cout << ans - sum << endl;
return 0;
}