結果
| 問題 |
No.355 数当てゲーム(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-02 16:34:44 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 119 ms / 2,000 ms |
| コード長 | 597 bytes |
| コンパイル時間 | 96 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 29,384 KB |
| 平均クエリ数 | 17.10 |
| 最終ジャッジ日時 | 2024-07-16 23:27:43 |
| 合計ジャッジ時間 | 8,923 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 52 |
コンパイルメッセージ
Syntax OK
ソースコード
def query(n)
puts n.join(' ')
STDOUT.flush
end
def reply
x, y = gets.split.map(&:to_i)
exit 0 if 4 == x
x + y
end
def detect_combination
candidates = (0..9).to_a.combination(4).to_a.shuffle!
while candidates
q = candidates.shift
query q
grouped = candidates.group_by{|c| num_common_elements(q, c) }
n = reply
return q if 4 == n
candidates = grouped[n]
end
raise 'must not happen'
end
def num_common_elements(q, c)
(c & q).size
end
def detect_sequence(n)
n.permutation do |n_|
query n_
reply
end
end
detect_sequence(detect_combination)