結果
問題 | No.3 ビットすごろく |
ユーザー | tkzw_21 |
提出日時 | 2015-03-02 14:21:25 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 674 ms / 5,000 ms |
コード長 | 612 bytes |
コンパイル時間 | 1,349 ms |
コンパイル使用メモリ | 159,196 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 07:17:50 |
合計ジャッジ時間 | 10,404 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> P; typedef pair<int,pair<int,int>> PP; typedef long long ll; const double EPS = 1e-8; const int INF = 1e9; const int MOD = 1e9+7; int dy[] = {0,1,0,-1}; int dx[] = {1,0,-1,0}; int main(void) { int N;cin >> N; vector<int> dp(N+1,INF); dp[1] = 0; for(int l=0;l<N;l++) for(int i=1;i<N+1;i++){ int mv = __builtin_popcount(i); if(dp[i] != INF){ if(i+mv <= N)dp[i+mv] = min(dp[i+mv],dp[i]+1); if(i-mv >= 1)dp[i-mv] = min(dp[i-mv],dp[i]+1); } } if(dp[N]+1 >= INF)cout << -1 << endl; else cout << dp[N]+1 << endl; return 0; }