結果

問題 No.355 数当てゲーム(2)
ユーザー shi-moshi-mo
提出日時 2016-04-02 16:34:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 597 bytes
コンパイル時間 38 ms
コンパイル使用メモリ 11,540 KB
実行使用メモリ 31,528 KB
平均クエリ数 17.04
最終ジャッジ日時 2023-09-23 23:37:18
合計ジャッジ時間 8,604 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
31,352 KB
testcase_01 AC 109 ms
31,044 KB
testcase_02 AC 108 ms
30,848 KB
testcase_03 AC 113 ms
31,364 KB
testcase_04 AC 110 ms
31,264 KB
testcase_05 AC 108 ms
30,896 KB
testcase_06 AC 110 ms
30,768 KB
testcase_07 AC 108 ms
30,736 KB
testcase_08 AC 108 ms
31,296 KB
testcase_09 AC 111 ms
31,464 KB
testcase_10 AC 109 ms
31,100 KB
testcase_11 AC 108 ms
30,816 KB
testcase_12 AC 108 ms
31,352 KB
testcase_13 AC 108 ms
30,868 KB
testcase_14 AC 107 ms
30,964 KB
testcase_15 AC 110 ms
30,824 KB
testcase_16 AC 106 ms
31,136 KB
testcase_17 AC 108 ms
31,336 KB
testcase_18 AC 107 ms
31,296 KB
testcase_19 AC 109 ms
30,824 KB
testcase_20 AC 109 ms
31,048 KB
testcase_21 AC 108 ms
30,680 KB
testcase_22 AC 107 ms
30,820 KB
testcase_23 AC 105 ms
31,528 KB
testcase_24 AC 109 ms
30,696 KB
testcase_25 AC 108 ms
30,968 KB
testcase_26 AC 108 ms
30,912 KB
testcase_27 AC 107 ms
31,024 KB
testcase_28 AC 108 ms
31,196 KB
testcase_29 AC 109 ms
30,948 KB
testcase_30 AC 108 ms
30,900 KB
testcase_31 AC 108 ms
30,728 KB
testcase_32 AC 108 ms
31,040 KB
testcase_33 AC 108 ms
31,284 KB
testcase_34 AC 106 ms
30,992 KB
testcase_35 AC 106 ms
30,928 KB
testcase_36 AC 107 ms
31,116 KB
testcase_37 AC 107 ms
30,920 KB
testcase_38 AC 109 ms
30,644 KB
testcase_39 AC 107 ms
30,764 KB
testcase_40 AC 111 ms
30,984 KB
testcase_41 AC 107 ms
31,316 KB
testcase_42 AC 108 ms
31,480 KB
testcase_43 AC 108 ms
30,772 KB
testcase_44 AC 108 ms
31,088 KB
testcase_45 AC 107 ms
31,056 KB
testcase_46 AC 107 ms
31,328 KB
testcase_47 AC 108 ms
30,836 KB
testcase_48 AC 109 ms
31,132 KB
testcase_49 AC 111 ms
31,164 KB
testcase_50 AC 109 ms
31,064 KB
testcase_51 AC 110 ms
30,996 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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)
0