結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-09-15 02:03:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 713 bytes |
コンパイル時間 | 1,282 ms |
コンパイル使用メモリ | 158,432 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 06:00:38 |
合計ジャッジ時間 | 2,164 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(int)(b);i++) #define rep(i,n) FOR(i,0,n) #define ZERO(a) memset(a,0,sizeof(a)) bool visited[10010]; int calc(int n) { int res = 0; while(n) { if(n & 1) res++; n >>= 1; } return res; } int main() { ZERO(visited); int n; cin>>n; vector<int> a(10010); rep(i,n+1) a[i] = calc(i); int ans = 0, pos = 1; while(1) { ans++; visited[pos] = 1; if(n == pos) break; pos += (pos+a[pos] <= n ? a[pos] : -a[pos]); if(visited[pos]) { cout << -1 << "\n"; return 0; } } cout << ans << "\n"; return 0; }