Submission #68633


ソースコード

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>
using namespace std;
#define ll long long
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define P pair<int,int>
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int inf=INT_MAX;
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n; cin>>n;
vector<int> edge[n+1];
for(int i=1;i<n;i++){
int f=__builtin_popcount(i);
if(i+f<=n) edge[i].pb(i+f);
if(i-f>=1) edge[i].pb(i-f);
}
queue<int> q;
vector<int> cost(n+1,inf);
q.push(1);
cost[1]=1;
while(!q.empty()){
int x=q.front();
q.pop();
if(x==n) break;
for(auto to:edge[x]){
if(cost[to]==inf){
q.push(to);
cost[to]=cost[x]+1;
}
}
}
cout<<(cost[n]==inf ? -1:cost[n])<<"\n";
return 0;
}

ステータス

項目 データ
問題 0288 - ビットすごろく
ユーザー名 ei2005
投稿日時 2021-10-01 16:45:06
言語 C++17
状態 Accepted
得点 2
ソースコード長 958 Byte
最大実行時間 52 ms
最大メモリ使用量 1364 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
1.txt AC 52 ms 604 KB
1
2.txt AC 22 ms 584 KB
1
3.txt AC 21 ms 680 KB
1
4.txt AC 27 ms 760 KB
1
5.txt AC 29 ms 708 KB
1
6.txt AC 24 ms 1012 KB
1
7.txt AC 29 ms 788 KB
1
8.txt AC 23 ms 724 KB
1
9.txt AC 30 ms 976 KB
1
10.txt AC 21 ms 820 KB
1
11.txt AC 18 ms 888 KB
1
12.txt AC 24 ms 876 KB
1
13.txt AC 28 ms 980 KB
1
14.txt AC 18 ms 636 KB
1
15.txt AC 24 ms 1120 KB
1
16.txt AC 29 ms 1128 KB
1
17.txt AC 21 ms 1020 KB
1
18.txt AC 30 ms 1080 KB
1
19.txt AC 28 ms 596 KB
1
20.txt AC 27 ms 1056 KB
1
challenge01.txt AC 34 ms 1200 KB
1
challenge02.txt AC 36 ms 1324 KB
1
challenge03.txt AC 23 ms 1344 KB
1
system_test1.txt AC 23 ms 1364 KB
1
system_test2.txt AC 29 ms 744 KB
1
system_test3.txt AC 25 ms 956 KB
1
system_test4.txt AC 22 ms 1292 KB
1