結果
問題 | No.305 鍵(2) |
ユーザー | shi-mo |
提出日時 | 2016-10-21 20:11:46 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 102 ms / 2,000 ms |
コード長 | 755 bytes |
コンパイル時間 | 222 ms |
コンパイル使用メモリ | 11,488 KB |
実行使用メモリ | 31,412 KB |
平均クエリ数 | 28.62 |
最終ジャッジ日時 | 2023-09-24 00:39:26 |
合計ジャッジ時間 | 2,591 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 98 ms
30,844 KB |
testcase_01 | AC | 98 ms
30,912 KB |
testcase_02 | AC | 95 ms
30,828 KB |
testcase_03 | AC | 96 ms
31,192 KB |
testcase_04 | AC | 97 ms
31,088 KB |
testcase_05 | AC | 101 ms
31,068 KB |
testcase_06 | AC | 98 ms
31,048 KB |
testcase_07 | AC | 100 ms
31,412 KB |
testcase_08 | AC | 99 ms
30,880 KB |
testcase_09 | AC | 99 ms
30,960 KB |
testcase_10 | AC | 101 ms
31,112 KB |
testcase_11 | AC | 101 ms
30,916 KB |
testcase_12 | AC | 102 ms
31,112 KB |
コンパイルメッセージ
Syntax OK
ソースコード
def query(n) puts n.join('') STDOUT.flush end def reply x, y = gets.split x = x.to_i exit 0 if 'unlocked' == y x end def detect_counts counts = [] 0.upto(9) do |i| query [i] * 10 c = reply counts << [i, c] if 0 < c end counts end def detect_answer(counts) numbers = counts.sort_by{|i, c| c }.reverse min_i, min_c = numbers.pop answer = Array.new(10) numbers.each do |i, c| break unless answer.include?(nil) 10.times do |j| next if answer[j] q = Array.new(10){ min_i } q[j] = i query q n = reply next if n == min_c if n < min_c answer[j] = min_i next end answer[j] = i end end query answer end detect_answer(detect_counts)