結果
問題 | No.3 ビットすごろく |
ユーザー | 67oYG9nh2YMmIci |
提出日時 | 2020-07-14 17:10:32 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 51 ms / 5,000 ms |
コード長 | 1,016 bytes |
コンパイル時間 | 566 ms |
コンパイル使用メモリ | 10,932 KB |
実行使用メモリ | 9,840 KB |
最終ジャッジ日時 | 2023-09-14 01:48:17 |
合計ジャッジ時間 | 2,918 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
9,720 KB |
testcase_01 | AC | 24 ms
9,676 KB |
testcase_02 | AC | 24 ms
9,756 KB |
testcase_03 | AC | 30 ms
9,724 KB |
testcase_04 | AC | 27 ms
9,716 KB |
testcase_05 | AC | 38 ms
9,700 KB |
testcase_06 | AC | 31 ms
9,688 KB |
testcase_07 | AC | 28 ms
9,720 KB |
testcase_08 | AC | 35 ms
9,736 KB |
testcase_09 | AC | 43 ms
9,624 KB |
testcase_10 | AC | 46 ms
9,700 KB |
testcase_11 | AC | 41 ms
9,668 KB |
testcase_12 | AC | 38 ms
9,624 KB |
testcase_13 | AC | 29 ms
9,764 KB |
testcase_14 | AC | 45 ms
9,732 KB |
testcase_15 | AC | 49 ms
9,712 KB |
testcase_16 | AC | 48 ms
9,668 KB |
testcase_17 | AC | 50 ms
9,624 KB |
testcase_18 | AC | 29 ms
9,628 KB |
testcase_19 | AC | 50 ms
9,680 KB |
testcase_20 | AC | 25 ms
9,828 KB |
testcase_21 | AC | 24 ms
9,760 KB |
testcase_22 | AC | 46 ms
9,716 KB |
testcase_23 | AC | 51 ms
9,760 KB |
testcase_24 | AC | 50 ms
9,764 KB |
testcase_25 | AC | 50 ms
9,696 KB |
testcase_26 | AC | 24 ms
9,672 KB |
testcase_27 | AC | 30 ms
9,760 KB |
testcase_28 | AC | 47 ms
9,764 KB |
testcase_29 | AC | 41 ms
9,700 KB |
testcase_30 | AC | 24 ms
9,840 KB |
testcase_31 | AC | 24 ms
9,836 KB |
testcase_32 | AC | 41 ms
9,740 KB |
ソースコード
import queue N=int(input()) def calcpop(num): return bin(num).count("1") def bit(): q=queue.Queue() q.put(1) trout=[-1]*(10**5) trout[1]=1 while q.empty()==False: curpos=q.get() #現在のマス目 popcnt=calcpop(curpos) #現在のマス目を2進数に変換した時の1の数 if(trout[curpos-popcnt]==-1 and curpos-popcnt>0): #後ろのマスに移動するときの判定・処理 trout[curpos-popcnt]=trout[curpos]+1 #移動した先に移動数の最小値を記録 q.put(curpos-popcnt) #このマス目から次は探索を行うためキューに入れる if(trout[curpos+popcnt]==-1 and curpos+popcnt<=N): #前のマスに移動する時の判定・処理 trout[curpos+popcnt] = trout[curpos] + 1 #移動した先に移動数の最小値を記録 q.put(curpos+popcnt) #このマス目から次は探索を行うためキューに入れる print(trout[N]) if __name__ == "__main__": bit()