結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2020-08-28 06:16:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 397 bytes |
コンパイル時間 | 1,645 ms |
コンパイル使用メモリ | 165,452 KB |
実行使用メモリ | 8,704 KB |
最終ジャッジ日時 | 2024-11-09 01:00:54 |
合計ジャッジ時間 | 8,656 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 TLE * 1 -- * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < n; ++i) using ll = long long; const int INF=1e9; int dp[10001]; int N; void f(int x=2,int y=2){ if(x<=0||x>N||dp[x]<y)return; dp[x]=y; int z=__builtin_popcount(x); f(x-z,y+1); f(x+z,y+1); } int main() { cin>>N; rep(i,10001)dp[i]=INF; dp[1]=0; f(); cout<<(dp[N]==INF?-1:dp[N])<<endl; }