Submission #36002


ソースコード

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
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
typedef struct{
int i;
int c;
} Pos;
int bit(int i){
int b = 0;
while(i != 1){
if(i % 2 == 1){
b++;
}
i /= 2;
}
b++;
return b;
}
int main(){
int n;
int memo[10001] = {};
queue<Pos> que;
cin >> n;
Pos pos,post;
pos.i = 1;
pos.c = 1;
que.push(pos);
int next;
while(!que.empty()){
pos = que.front();
que.pop();
if(memo[pos.i] == 0){
memo[pos.i] += pos.c;
next = bit(pos.i);
pos.c++;
if(pos.i + next <= n){
post = pos;
post.i += next;
que.push(post);
}
if(pos.i - next > 0){
post = pos;
post.i -= next;
que.push(post);
}
}
}
if(memo[n] != 0){
cout << memo[n] << endl;
}else{
cout << -1 << endl;
}
return 0;
}

ステータス

項目 データ
問題 0288 - ビットすごろく
ユーザー名 ei1719
投稿日時 2018-05-24 23:55:18
言語 C++11
状態 Accepted
得点 2
ソースコード長 898 Byte
最大実行時間 43 ms
最大メモリ使用量 940 KB

セット

セット 得点 Cases
1 ALL 2 / 2 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
1.txt AC 34 ms 476 KB
1
2.txt AC 24 ms 576 KB
1
3.txt AC 23 ms 592 KB
1
4.txt AC 33 ms 652 KB
1
5.txt AC 20 ms 592 KB
1
6.txt AC 21 ms 528 KB
1
7.txt AC 19 ms 596 KB
1
8.txt AC 22 ms 664 KB
1
9.txt AC 28 ms 732 KB
1
10.txt AC 23 ms 544 KB
1
11.txt AC 26 ms 612 KB
1
12.txt AC 23 ms 676 KB
1
13.txt AC 25 ms 616 KB
1
14.txt AC 25 ms 684 KB
1
15.txt AC 43 ms 624 KB
1
16.txt AC 23 ms 688 KB
1
17.txt AC 26 ms 624 KB
1
18.txt AC 28 ms 564 KB
1
19.txt AC 19 ms 636 KB
1
20.txt AC 25 ms 520 KB
1
challenge01.txt AC 25 ms 668 KB
1
challenge02.txt AC 23 ms 608 KB
1
challenge03.txt AC 22 ms 672 KB
1
system_test1.txt AC 24 ms 740 KB
1
system_test2.txt AC 23 ms 548 KB
1
system_test3.txt AC 25 ms 748 KB
1
system_test4.txt AC 30 ms 940 KB
1