結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
dazy
|
| 提出日時 | 2017-11-23 17:25:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,526 bytes |
| コンパイル時間 | 437 ms |
| コンパイル使用メモリ | 54,620 KB |
| 実行使用メモリ | 14,464 KB |
| 最終ジャッジ日時 | 2024-11-27 05:47:23 |
| 合計ジャッジ時間 | 60,873 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 4 RE * 11 TLE * 4 |
ソースコード
#include <iostream>
using namespace std;
#define fastcin {\
cin.tie(0);\
ios::sync_with_stdio(false);\
}
//#define rep(i, a, b) for(int i = a; i < b; i++)
#define REP(i, a) for(int i = 0; i < a; i++)
#define scan(x) cin >> n;
#define print(x) cout << x << "\n"
int countbit(int n) {
int count = 0;
for (int i = 1; i < n + 1; i <<= 1) if (n & i) count++;
return count;
}
int main() {
fastcin;
int n;
scan(n);
int masu[10001], turn[1000][1000];
REP(i, 10001) masu[i] = 10002;
int locate, count = 1, branch = 1, ans = -1;
turn[count][branch] = 1;
masu[1] = 1;
int i = 1, j, move, p ,m, next;
if (n != 1) {
do {
j = 1;
next = 0;
do {
locate = turn[i][j];
move = countbit(locate);
p = locate + move;
m = locate - move;
if (p == n || m == n) {
ans = i + 1;
break;
}
if (masu[p] == 10002 && p < n) {
next++;
masu[p] = i + 1;
turn[i+1][next] = p;
} else if (masu[m] == 10002 && m > 0) {
next++;
masu[m] = i + 1;
turn[i+1][next] = m;
}
} while (j++ <= branch);
if (next > 0) count++;
branch = next;
} while (i++ <= count);
} else ans = 1;
print(ans);
return 0;
}
dazy