結果
問題 | No.1869 Doubling? |
ユーザー |
|
提出日時 | 2022-03-11 22:00:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 891 bytes |
コンパイル時間 | 1,563 ms |
コンパイル使用メモリ | 170,048 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-16 02:16:17 |
合計ジャッジ時間 | 2,458 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef _RUTHEN #include "debug.hpp" #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template <class T> using V = vector<T>; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N, M; cin >> N >> M; if (N <= 32) { if ((1LL << (N - 1)) <= M) { cout << ((1LL << N) - 1) << '\n'; return 0; } } V<ll> A = {M}; ll cm = M; while (cm != 1) { cm = (cm + 1) / 2; A.push_back(cm); } reverse(A.begin(), A.end()); show(A); if (A.size() >= N) { ll ans = 0; rep(i, N) ans += A[i]; cout << ans << '\n'; } else { ll ans = 0; for (auto &a : A) ans += a; N -= A.size(); ans += N; cout << ans << '\n'; } return 0; }