結果
問題 | No.3 ビットすごろく |
ユーザー | 777yuuki12323 |
提出日時 | 2017-06-19 18:26:25 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,296 bytes |
コンパイル時間 | 570 ms |
コンパイル使用メモリ | 76,832 KB |
実行使用メモリ | 4,500 KB |
最終ジャッジ日時 | 2023-09-14 00:45:26 |
合計ジャッジ時間 | 1,924 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,376 KB |
testcase_12 | AC | 2 ms
4,500 KB |
testcase_13 | AC | 1 ms
4,380 KB |
testcase_14 | AC | 1 ms
4,380 KB |
testcase_15 | AC | 2 ms
4,376 KB |
testcase_16 | AC | 2 ms
4,380 KB |
testcase_17 | AC | 2 ms
4,376 KB |
testcase_18 | AC | 1 ms
4,380 KB |
testcase_19 | AC | 2 ms
4,380 KB |
testcase_20 | AC | 2 ms
4,376 KB |
testcase_21 | AC | 1 ms
4,376 KB |
testcase_22 | AC | 2 ms
4,380 KB |
testcase_23 | AC | 2 ms
4,376 KB |
testcase_24 | AC | 2 ms
4,380 KB |
testcase_25 | AC | 2 ms
4,376 KB |
testcase_26 | AC | 1 ms
4,380 KB |
testcase_27 | AC | 1 ms
4,376 KB |
testcase_28 | AC | 2 ms
4,380 KB |
testcase_29 | AC | 2 ms
4,380 KB |
testcase_30 | AC | 1 ms
4,376 KB |
testcase_31 | AC | 1 ms
4,376 KB |
testcase_32 | AC | 2 ms
4,376 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:79:8: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized] cout<<ans<<endl; ^~~
ソースコード
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <string> #include <map> #include <bitset> #include <vector> #include <queue> typedef long long ll; #define fi first #define se second const ll mod = 1000000007; // 123456789 using namespace std; /////////////////////////////////////////////// // // /////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////// queue<int> Q; int cost[11234]; int N; int main(){ fill(cost, cost+11234, mod); cost[1] = 1; Q.push( 1 ); cin>>N; int ans; int num; int next; int flag = 0; int j[2] = { 1, -1 }; int i; if( N > 1 ){ while( !Q.empty() ){ num = Q.front(); for( i = 0; i < 2; i++ ){ next = num + (j[i]*bitset<32>(num).count()); //cout<<num<<" "<<bitset<32>(num).count()<<endl; if( 0 < next && next <= N ){ if( cost[next] == (int)mod ){ cost[next] = cost[num]+1; Q.push( next ); //cout<<next<<endl; } if( next == N ) flag = 1; } } //cout<<num<<" "<<cost[num]<<endl; if( flag ){ ans = cost[N]; break; } Q.pop(); } } else{ ans = 1; } if( cost[N] == (int)mod ) ans = -1; cout<<ans<<endl; return 0; }