結果
問題 | No.1869 Doubling? |
ユーザー |
|
提出日時 | 2022-03-11 21:36:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 882 bytes |
コンパイル時間 | 2,114 ms |
コンパイル使用メモリ | 192,312 KB |
最終ジャッジ日時 | 2025-01-28 08:19:24 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i = 0; i < (n); i++)using namespace std;typedef long long ll;int main(){cin.tie(0);ios::sync_with_stdio(0);ll N,M; cin >> N >> M;auto f = [&](ll N, ll M) {ll p2 = 1;for(int i = 0; i < N; i++) {if(p2 >= M) return true;p2 *= 2;}return false;};if(f(N, M)) {ll ans = 0;ll m = M;ll cnt = 0;while(m != 1) {ans += m;if(m % 2 == 0) {m /= 2;} else {m = (m + 1) / 2;}cnt++;}cout << ans + 1 * (N - cnt) << endl;} else {ll ans = 0;ll a = 1;for(int i = 0; i < N; i++) {ans += a;a *= 2;}cout << ans << endl;}}