Submission #02479
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <algorithm> #include <iostream> #include <queue> using namespace std; #define INF 1<<25 int count1( int a){ int cnt=0; while (a){ if (a&1) cnt++; a>>=1; } return cnt; } int main(){ int n; cin>>n; int search[n+1]; int num[n]; for ( int i=0;i<n;i++){ search[i]=INF; num[i]=count1(i+1); } search[0]=1; queue< int > sta; sta.push(0); while (search[n-1]==INF&&sta.size()!=0){ int cur=sta.front(); sta.pop(); if (cur+num[cur]<n){ if (search[cur+num[cur]]>search[cur]+1){ search[cur+num[cur]]=search[cur]+1; sta.push(cur+num[cur]); } } if (cur-num[cur]>0){ if (search[cur-num[cur]]>search[cur]+1){ search[cur-num[cur]]=search[cur]+1; sta.push(cur-num[cur]); } } } if (search[n-1]==INF) search[n-1]=-1; cout<<search[n-1]<<endl; return 0; } ]]> |
ステータス
項目 | データ |
---|---|
問題 | 0288 - ビットすごろく |
ユーザー名 | ei1430 |
投稿日時 | 2015-12-21 13:17:31 |
言語 | C++11 |
状態 | Accepted |
得点 | 2 |
ソースコード長 | 1020 Byte |
最大実行時間 | 28 ms |
最大メモリ使用量 | 680 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 2 / 2 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
1.txt | AC | 22 ms | 476 KB |
1
|
2.txt | AC | 16 ms | 464 KB |
1
|
3.txt | AC | 20 ms | 596 KB |
1
|
4.txt | AC | 20 ms | 568 KB |
1
|
5.txt | AC | 14 ms | 524 KB |
1
|
6.txt | AC | 25 ms | 620 KB |
1
|
7.txt | AC | 18 ms | 556 KB |
1
|
8.txt | AC | 22 ms | 512 KB |
1
|
9.txt | AC | 21 ms | 608 KB |
1
|
10.txt | AC | 15 ms | 452 KB |
1
|
11.txt | AC | 16 ms | 500 KB |
1
|
12.txt | AC | 15 ms | 544 KB |
1
|
13.txt | AC | 28 ms | 600 KB |
1
|
14.txt | AC | 22 ms | 408 KB |
1
|
15.txt | AC | 16 ms | 628 KB |
1
|
16.txt | AC | 20 ms | 668 KB |
1
|
17.txt | AC | 19 ms | 568 KB |
1
|
18.txt | AC | 18 ms | 476 KB |
1
|
19.txt | AC | 23 ms | 500 KB |
1
|
20.txt | AC | 21 ms | 440 KB |
1
|
challenge01.txt | AC | 25 ms | 680 KB |
1
|
challenge02.txt | AC | 19 ms | 592 KB |
1
|
challenge03.txt | AC | 16 ms | 620 KB |
1
|
system_test1.txt | AC | 19 ms | 648 KB |
1
|
system_test2.txt | AC | 18 ms | 544 KB |
1
|
system_test3.txt | AC | 16 ms | 644 KB |
1
|
system_test4.txt | AC | 19 ms | 600 KB |
1
|