結果

問題 No.642 Two Operations No.1
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2020-09-03 14:55:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 805 bytes
コンパイル時間 1,308 ms
コンパイル使用メモリ 86,428 KB
実行使用メモリ 600,860 KB
最終ジャッジ日時 2024-05-02 23:05:45
合計ジャッジ時間 4,893 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 15 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main(){
      | ^~~~

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<map>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
#define rep(i, n) for (i32 i = 0; i < (i32)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
map<i64,i64>mp;
i64 n;
void dfs(i64 x,i64 cnt){
    if(x != 1 && mp[x] != 0 && mp[x] < cnt){
        return;
    }else if(x == n){
        mp[x] = cnt;
        return ;
    }else if(x < 1){
        return ;
    }else if(x > 2 * n){
        return ;
    }
    mp[x] = cnt;
    dfs(2 * x,cnt + 1);
    dfs(x - 1,cnt + 1);
    return ;
}
main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> n;
dfs((i64)(1),(i64)(0));
cout << mp[n] << endl;
}
0