Submission #03450
ソースコード
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 | #include<bits/stdc++.h> #define fr first #define sc second using namespace std; typedef pair< int , int > P; int n; int bfs(){ int gmin = INT_MAX; bool used[11111] = {0}; queue<P> q; q.push(P(1, 1)); while (!q.empty()){ P p = q.front();q.pop(); int bsum = 0, bit = p.fr, now = p.sc; used[bit] = true ; if (bit == n){ gmin = min(gmin, now); continue ; } for ( int i = bit; i > 0; i = i>>1){ if (i & 1) bsum++; } //cout << now << endl; if (bit + bsum <= n && !used[bit + bsum]) q.push(P(bit + bsum, now+1)); if (bit - bsum > 0 && !used[bit - bsum]) q.push(P(bit - bsum, now+1)); } if (gmin == INT_MAX) gmin = -1; return gmin; } int main(){ cin >> n; cout << bfs() << endl; } |
ステータス
項目 | データ |
---|---|
問題 | 0288 - ビットすごろく |
ユーザー名 | ei1409 |
投稿日時 | 2016-04-22 17:58:19 |
言語 | C++11 |
状態 | Accepted |
得点 | 2 |
ソースコード長 | 780 Byte |
最大実行時間 | 226 ms |
最大メモリ使用量 | 3344 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 2 / 2 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
1.txt | AC | 26 ms | 476 KB |
1
|
2.txt | AC | 14 ms | 652 KB |
1
|
3.txt | AC | 27 ms | 572 KB |
1
|
4.txt | AC | 25 ms | 540 KB |
1
|
5.txt | AC | 12 ms | 632 KB |
1
|
6.txt | AC | 19 ms | 600 KB |
1
|
7.txt | AC | 14 ms | 764 KB |
1
|
8.txt | AC | 12 ms | 724 KB |
1
|
9.txt | AC | 17 ms | 692 KB |
1
|
10.txt | AC | 62 ms | 824 KB |
1
|
11.txt | AC | 94 ms | 1212 KB |
1
|
12.txt | AC | 40 ms | 716 KB |
1
|
13.txt | AC | 32 ms | 512 KB |
1
|
14.txt | AC | 14 ms | 548 KB |
1
|
15.txt | AC | 107 ms | 1172 KB |
1
|
16.txt | AC | 223 ms | 2708 KB |
1
|
17.txt | AC | 118 ms | 1232 KB |
1
|
18.txt | AC | 197 ms | 2636 KB |
1
|
19.txt | AC | 14 ms | 684 KB |
1
|
20.txt | AC | 222 ms | 3300 KB |
1
|
challenge01.txt | AC | 87 ms | 1292 KB |
1
|
challenge02.txt | AC | 226 ms | 3344 KB |
1
|
challenge03.txt | AC | 225 ms | 3304 KB |
1
|
system_test1.txt | AC | 198 ms | 2744 KB |
1
|
system_test2.txt | AC | 18 ms | 748 KB |
1
|
system_test3.txt | AC | 10 ms | 712 KB |
1
|
system_test4.txt | AC | 113 ms | 1324 KB |
1
|