結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-10 02:07:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,178 bytes |
| コンパイル時間 | 1,509 ms |
| コンパイル使用メモリ | 172,856 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-07 10:44:22 |
| 合計ジャッジ時間 | 2,273 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 15 |
ソースコード
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
vector<bool>seen;
int dfs(int now, int target, int count) {
if (now == target) {
return count;
}
seen[now] = true;
int b_c = __builtin_popcount(now);
int s = seen.size();
int tmp = 100000;
bool can_do = false;
if (s > now+b_c && !seen[now+b_c]) {
tmp = min(tmp, dfs(now+b_c, target, count+1));
can_do = true;
}
if (now-b_c>0 && !seen[now-b_c]) {
int n = dfs(now-b_c, target, count+1);
if (tmp > 0 && n > 0) {
tmp = min(tmp, n);
} else {
if (can_do) {
tmp = max(tmp, n);
} else {
tmp = n;
}
}
can_do = true;
}
if (!can_do) {
tmp = -1;
}
return tmp;
}
int main()
{
int N;
cin >> N;
seen.resize(N+1);
int count = dfs(1, N, 1);
cout << count << endl;
return 0;
}