結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
y_mazun
|
| 提出日時 | 2015-04-17 02:19:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 569 bytes |
| コンパイル時間 | 364 ms |
| コンパイル使用メモリ | 46,976 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 07:18:57 |
| 合計ジャッジ時間 | 1,329 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:3:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
3 | inline int getInt(){ int s; scanf("%d", &s); return s; }
| ~~~~~^~~~~~~~~~
ソースコード
#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }
#include <set>
using namespace std;
int main(){
const int n = getInt();
vector<int> dp(n);
dp[0] = 1;
queue<int> q; q.push(0);
while(q.size()){
const int m = q.front(); q.pop();
const int k = __builtin_popcount(m + 1);
auto f = [&](int pos){
if(0 <= pos && pos < n && dp[pos] == 0){
dp[pos] = dp[m] + 1;
q.push(pos);
}
};
f(m - k); f(m + k);
}
printf("%d\n", dp[n - 1] == 0 ? -1 : dp[n - 1]);
return 0;
}
y_mazun