結果

問題 No.3 ビットすごろく
ユーザー fushime2
提出日時 2016-09-15 01:55:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 773 bytes
コンパイル時間 1,233 ms
コンパイル使用メモリ 159,172 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-17 06:00:36
合計ジャッジ時間 2,208 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#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[10001];

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(n+2);
    rep(i,n+1) a[i] = calc(i);

    int ans = 0, pos = 1;
    while(1) {
        //cout << pos << endl;
        ans++;
        visited[pos] = 1;
        pos += (pos+a[pos] > n ? -a[pos] : a[pos]);
        if(visited[pos]) {
            cout << -1 << "\n";
            return 0;
        }
        if(pos == n) {
            ans++; break;
        }
    }

    cout << ans << "\n";

    return 0;
}
0