結果

問題 No.642 Two Operations No.1
コンテスト
ユーザー beet
提出日時 2018-07-26 13:48:45
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
MLE  
実行時間 -
コード長 449 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,281 ms
コンパイル使用メモリ 192,980 KB
実行使用メモリ 694,912 KB
最終ジャッジ日時 2026-03-21 20:25:05
合計ジャッジ時間 31,118 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 TLE * 1 MLE * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  queue<Int> q;
  map<Int, Int> dp;
  dp[1]=0;
  q.emplace(1);
  while(!q.empty()){
    Int x=q.front();q.pop();
    if(x==n) break;
    if(x<n&&!dp.count(x*2)){
      dp[x*2]=dp[x]+1;
      q.emplace(x*2);
    }
    if(!dp.count(x-1)){
      dp[x-1]=dp[x]+1;
      q.emplace(x-1);
    }
  }
  cout<<dp[n]<<endl;
  return 0;
}
0