結果
問題 | No.355 数当てゲーム(2) |
ユーザー | shi-mo |
提出日時 | 2016-04-02 15:18:06 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 121 ms / 2,000 ms |
コード長 | 1,582 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 29,128 KB |
平均クエリ数 | 20.67 |
最終ジャッジ日時 | 2024-07-16 23:26:25 |
合計ジャッジ時間 | 9,111 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 116 ms
28,632 KB |
testcase_01 | AC | 115 ms
28,888 KB |
testcase_02 | AC | 121 ms
28,760 KB |
testcase_03 | AC | 116 ms
28,248 KB |
testcase_04 | AC | 117 ms
29,016 KB |
testcase_05 | AC | 112 ms
28,632 KB |
testcase_06 | AC | 114 ms
28,880 KB |
testcase_07 | AC | 114 ms
28,888 KB |
testcase_08 | AC | 114 ms
28,760 KB |
testcase_09 | AC | 114 ms
28,760 KB |
testcase_10 | AC | 114 ms
28,632 KB |
testcase_11 | AC | 111 ms
28,888 KB |
testcase_12 | AC | 114 ms
28,632 KB |
testcase_13 | AC | 115 ms
28,504 KB |
testcase_14 | AC | 114 ms
28,760 KB |
testcase_15 | AC | 115 ms
28,888 KB |
testcase_16 | AC | 114 ms
28,376 KB |
testcase_17 | AC | 115 ms
28,120 KB |
testcase_18 | AC | 114 ms
28,632 KB |
testcase_19 | AC | 117 ms
28,888 KB |
testcase_20 | AC | 116 ms
28,624 KB |
testcase_21 | AC | 114 ms
29,008 KB |
testcase_22 | AC | 114 ms
28,880 KB |
testcase_23 | AC | 112 ms
28,624 KB |
testcase_24 | AC | 114 ms
28,240 KB |
testcase_25 | AC | 115 ms
28,624 KB |
testcase_26 | AC | 113 ms
28,496 KB |
testcase_27 | AC | 113 ms
28,624 KB |
testcase_28 | AC | 114 ms
28,624 KB |
testcase_29 | AC | 114 ms
28,624 KB |
testcase_30 | AC | 113 ms
28,752 KB |
testcase_31 | AC | 112 ms
28,368 KB |
testcase_32 | AC | 114 ms
28,880 KB |
testcase_33 | AC | 116 ms
28,880 KB |
testcase_34 | AC | 115 ms
28,880 KB |
testcase_35 | AC | 113 ms
28,872 KB |
testcase_36 | AC | 114 ms
28,488 KB |
testcase_37 | AC | 113 ms
29,128 KB |
testcase_38 | AC | 113 ms
28,648 KB |
testcase_39 | AC | 113 ms
28,872 KB |
testcase_40 | AC | 115 ms
28,488 KB |
testcase_41 | AC | 114 ms
28,872 KB |
testcase_42 | AC | 114 ms
28,744 KB |
testcase_43 | AC | 113 ms
28,872 KB |
testcase_44 | AC | 113 ms
28,360 KB |
testcase_45 | AC | 114 ms
28,104 KB |
testcase_46 | AC | 114 ms
28,744 KB |
testcase_47 | AC | 113 ms
28,488 KB |
testcase_48 | AC | 113 ms
29,000 KB |
testcase_49 | AC | 114 ms
28,488 KB |
testcase_50 | AC | 113 ms
28,488 KB |
testcase_51 | AC | 113 ms
28,744 KB |
コンパイルメッセージ
Syntax OK
ソースコード
$count = {} def try(n) return $count[n] if $count[n] puts n.join(' ') STDOUT.flush x, y = gets.split.map(&:to_i) $count[n] = x+y exit 0 if 4 == x x+y end def detect_combination count_for_pairs || choose_series_from_pairs end def count_for_pairs pairs = (0..7).each_slice(2).to_a pairs.each do |p| n1, n2 = divide_numbers(p) [n1, n2].each do |n| return n if 4 == try(n) end $count[p] = 4 - $count[n1] - $count[n2] end $count[[8, 9]] = 4 - pairs.map{|p| $count[p] }.inject(:+) n = [0, 1, 2, 3] return n if 4 == try(n) nil end def divide_numbers(exclude_pair) start = exclude_pair[1] + 1 a = (start...(start+8)).to_a.map{|i| (9 < i) ? i-10 : i } [ a[0..3], a[4..7] ] end def choose_series_from_pairs pairs = (0..9).each_slice(2).to_a c2_pairs = pairs.select{|p| 2 == $count[p] } c1_pairs = pairs.select{|p| 1 == $count[p] } case c2_pairs.size when 2 return c2_pairs.flatten! when 1 raise 'must not happen' if 2 != c1_pairs.size p2 = c2_pairs[0] p0 = c1_pairs[0] p1 = c1_pairs[1] p0.product(p1) do |p| n = p2 + p return n if 4 == try(n) end raise 'must not happen' when 0 raise 'must not happen' if 4 != c1_pairs.size 16.times do |i| n = c1_pairs.map.with_index{|p, j| p[(0 == i & (1<<j)) ? 0 : 1] } return n if 4 == try(n) end raise 'must not happen' else raise 'must not happen' end raise 'must not happen' end def detect_sequence(n) n.permutation do |n_| try(n_) end end detect_sequence(detect_combination)