結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2018-01-06 14:35:51 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 822 bytes |
コンパイル時間 | 1,612 ms |
コンパイル使用メモリ | 158,332 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-12-23 08:34:42 |
合計ジャッジ時間 | 2,956 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 WA * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d", &n); | ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define FI(i,a,b) for(int i=(a);i<=(b);i++) #define FD(i,b,a) for(int i=(b);i>=(a);i--) #define len(a) int((a).size()) using namespace std; using LL = long long; using PII = pair<int, int>; const int N = 10005; int F[N]; int dfs(int x, int target, bitset<N> b) { if (F[x] != -1) return F[x]; if (x == target) return F[x] = 0; b.set(x); int t = __builtin_popcount(x); int ans = 1 << 30; if (x > t && !b.test(x-t)) { ans = 1 + dfs(x-t, target, b); } if (x + t <= target && !b.test(x+t)) { ans = min(ans, 1 + dfs(x+t, target, b)); } return F[x] = ans; } int main() { int n; scanf("%d", &n); memset(F, -1, sizeof F); bitset<N> b(0); int ans = dfs(1, n, b) + 1; if (ans >= 1 << 30) ans = -1; printf("%d\n", ans); }