結果
| 問題 |
No.642 Two Operations No.1
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2018-07-26 13:54:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 890 bytes |
| コンパイル時間 | 1,882 ms |
| コンパイル使用メモリ | 185,196 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-01 03:17:53 |
| 合計ジャッジ時間 | 2,572 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 9 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//INSERT ABOVE HERE
signed main(){
Int n;
cin>>n;
using P = pair<Int, Int>;
priority_queue<P, vector<P>, greater<P> > q;
auto dist=
[&](Int x){
Int res=n+(1<<15);
for(Int i=0;i<20;i++)
if((x<<i)>=n) chmin(res,(x<<i)-n);
return res;
};
map<Int, Int> dp;
dp[1]=0;
q.emplace(dist(1),1);
while(!q.empty()){
Int x=q.top().second;q.pop();
if(x==n) break;
if(!dp.count(x*2)||dp[x*2]>dp[x]+1){
dp[x*2]=dp[x]+1;
q.emplace(dp[x*2]+dist(x*2),x*2);
}
if(!dp.count(x-1)||dp[x-1]>dp[x]+1){
dp[x-1]=dp[x]+1;
q.emplace(dp[x-1]+dist(x-1),x-1);
}
}
cout<<dp[n]<<endl;
return 0;
}
beet