結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
_yoshih_
|
| 提出日時 | 2018-09-30 23:18:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 800 bytes |
| コンパイル時間 | 684 ms |
| コンパイル使用メモリ | 71,460 KB |
| 実行使用メモリ | 10,020 KB |
| 最終ジャッジ日時 | 2024-10-12 09:20:12 |
| 合計ジャッジ時間 | 7,236 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 TLE * 1 -- * 29 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
using namespace std;
static int count_bits(int i)
{
auto b = 0;
while (i > 0) {
if (i & 0x01) ++b;
i >>= 1;
}
return b;
}
static int move(const vector<int>& bits, int n, int pos, int count)
{
if (n == pos) return count;
if (count > 1 && pos <= 1) return -1;
if (pos + bits[pos] > n) return move(bits, n, pos - bits[pos], count + 1);
return move(bits, n, pos + bits[pos], count + 1);
}
static void run()
{
int n;
cin >> n;
vector<int> bits;
bits.resize(n + 1);
for (auto i = 1; i <= n; ++i) {
bits[i] = count_bits(i);
}
const auto count = move(bits, n, 1, 1);
cout << count << endl;
}
int main(int argc, char **argv)
{
run();
return 0;
}
_yoshih_