Submission #41124
ソースコード
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 45 46 47 48 49 50 | #include<bits/stdc++.h> #define REP(i, n) for(int i = 0; i < n; ++i) #define FOR(i, a, b) for(int i = a; i < b; ++i) #define F first #define S second #define OUT(x) cout << (x) << "\n" using namespace std; using point = pair< int , int >; using ll = long long ; int bitcnt( int n); int main() { int n; scanf ( "%d" , &n); queue< int > q; int visit[n + 1]; fill(visit, visit + (n + 1), -1); q.push(1); visit[1] = 1; while (!q.empty()) { int p = q.front(); q.pop(); int d = bitcnt(p); if (p + d <= n && !~visit[p + d]) { visit[p + d] = visit[p] + 1; q.push(p + d); } if (p - d > 0 && !~visit[p - d]) { visit[p - d] = visit[p] + 1; q.push(p - d); } } OUT(visit[n]); return 0; } int bitcnt( int n) { int ret = 0; while (n > 0) { ret += n & 1; n = n >> 1; } return ret; } |
ステータス
項目 | データ |
---|---|
問題 | 0288 - ビットすごろく |
ユーザー名 | Wonder /*ei1741*/ |
投稿日時 | 2018-08-10 11:26:56 |
言語 | C++17 |
状態 | Accepted |
得点 | 2 |
ソースコード長 | 989 Byte |
最大実行時間 | 31 ms |
最大メモリ使用量 | 752 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 2 / 2 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
1.txt | AC | 30 ms | 480 KB |
1
|
2.txt | AC | 31 ms | 460 KB |
1
|
3.txt | AC | 17 ms | 504 KB |
1
|
4.txt | AC | 21 ms | 612 KB |
1
|
5.txt | AC | 22 ms | 704 KB |
1
|
6.txt | AC | 21 ms | 540 KB |
1
|
7.txt | AC | 20 ms | 620 KB |
1
|
8.txt | AC | 28 ms | 584 KB |
1
|
9.txt | AC | 24 ms | 680 KB |
1
|
10.txt | AC | 22 ms | 460 KB |
1
|
11.txt | AC | 23 ms | 536 KB |
1
|
12.txt | AC | 24 ms | 480 KB |
1
|
13.txt | AC | 23 ms | 680 KB |
1
|
14.txt | AC | 18 ms | 636 KB |
1
|
15.txt | AC | 21 ms | 608 KB |
1
|
16.txt | AC | 18 ms | 672 KB |
1
|
17.txt | AC | 24 ms | 608 KB |
1
|
18.txt | AC | 28 ms | 544 KB |
1
|
19.txt | AC | 24 ms | 488 KB |
1
|
20.txt | AC | 21 ms | 568 KB |
1
|
challenge01.txt | AC | 26 ms | 644 KB |
1
|
challenge02.txt | AC | 17 ms | 464 KB |
1
|
challenge03.txt | AC | 29 ms | 532 KB |
1
|
system_test1.txt | AC | 25 ms | 604 KB |
1
|
system_test2.txt | AC | 24 ms | 676 KB |
1
|
system_test3.txt | AC | 19 ms | 656 KB |
1
|
system_test4.txt | AC | 20 ms | 752 KB |
1
|