Submission #02629
ソースコード
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 | // lower_bound(dp,dp+n,5); @5以上の値がある最初の位置 // *lower_bound(dp,dp+n,5); @5以上の値がある最初の位置の値 /*struct data{ @構造体 int n; int k; bool operator<(const data& right)const{ @const忘れるな return n<right.v; @nでsort()できるようになる 小順 } }; data num[]; @data型の配列*/ #include<bits/stdc++.h> using namespace std; #define INF 0xfffffff int n; int mas[10002]; int forb[2]={1,-1}; int bfs(){ queue < int > que; //初期化、マス1からスタート、1は2進で1 fill(mas,mas+n+1,INF); mas[1]=1; que.push( 1 ); while (!que.empty()){ //キューから取り出す int v=que.front(); que.pop(); if (v==n) break ; bitset<16> bs(v); int bc=0; for ( int i=0;i<16;i++) if (bs[i]==1)bc++; for ( int i=0;i<2;i++){ //移動後のマス int vp=v+forb[i]*bc; if (vp<1 || vp>n) continue ; //範囲外ならとばす //訪れたことがないならキューにいれる if (mas[vp]==INF){ que.push( vp ); mas[vp]=mas[v]+1; //チェック } } } return mas[n]; } int main(){ cin>>n; int ans=bfs(); if (ans==INF)cout<<-1<<endl; else cout<<ans<<endl; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0288 - ビットすごろく |
ユーザー名 | ei1538 |
投稿日時 | 2016-01-14 17:13:13 |
言語 | C++11 |
状態 | Accepted |
得点 | 2 |
ソースコード長 | 1322 Byte |
最大実行時間 | 19 ms |
最大メモリ使用量 | 708 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 2 / 2 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
1.txt | AC | 19 ms | 476 KB |
1
|
2.txt | AC | 9 ms | 648 KB |
1
|
3.txt | AC | 14 ms | 676 KB |
1
|
4.txt | AC | 14 ms | 648 KB |
1
|
5.txt | AC | 10 ms | 596 KB |
1
|
6.txt | AC | 9 ms | 564 KB |
1
|
7.txt | AC | 10 ms | 512 KB |
1
|
8.txt | AC | 13 ms | 472 KB |
1
|
9.txt | AC | 9 ms | 556 KB |
1
|
10.txt | AC | 9 ms | 444 KB |
1
|
11.txt | AC | 13 ms | 388 KB |
1
|
12.txt | AC | 12 ms | 584 KB |
1
|
13.txt | AC | 10 ms | 524 KB |
1
|
14.txt | AC | 11 ms | 476 KB |
1
|
15.txt | AC | 14 ms | 568 KB |
1
|
16.txt | AC | 14 ms | 632 KB |
1
|
17.txt | AC | 13 ms | 696 KB |
1
|
18.txt | AC | 10 ms | 632 KB |
1
|
19.txt | AC | 11 ms | 692 KB |
1
|
20.txt | AC | 13 ms | 620 KB |
1
|
challenge01.txt | AC | 14 ms | 640 KB |
1
|
challenge02.txt | AC | 14 ms | 708 KB |
1
|
challenge03.txt | AC | 12 ms | 640 KB |
1
|
system_test1.txt | AC | 13 ms | 696 KB |
1
|
system_test2.txt | AC | 13 ms | 500 KB |
1
|
system_test3.txt | AC | 11 ms | 596 KB |
1
|
system_test4.txt | AC | 12 ms | 684 KB |
1
|