結果
問題 | No.5014 セクスタプル (reactive) |
ユーザー | tomerun |
提出日時 | 2022-12-29 19:35:29 |
言語 | Crystal (1.11.2) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 3,452 bytes |
コンパイル時間 | 16,614 ms |
実行使用メモリ | 22,844 KB |
スコア | 616,469,907 |
平均クエリ数 | 35.00 |
最終ジャッジ日時 | 2022-12-29 19:35:53 |
合計ジャッジ時間 | 23,425 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
21,992 KB |
testcase_01 | AC | 20 ms
22,612 KB |
testcase_02 | AC | 19 ms
21,928 KB |
testcase_03 | AC | 21 ms
21,868 KB |
testcase_04 | AC | 21 ms
21,868 KB |
testcase_05 | AC | 20 ms
22,444 KB |
testcase_06 | AC | 19 ms
21,880 KB |
testcase_07 | AC | 20 ms
21,868 KB |
testcase_08 | AC | 19 ms
21,980 KB |
testcase_09 | AC | 20 ms
21,868 KB |
testcase_10 | AC | 20 ms
21,756 KB |
testcase_11 | AC | 19 ms
22,564 KB |
testcase_12 | AC | 20 ms
21,928 KB |
testcase_13 | AC | 20 ms
21,880 KB |
testcase_14 | AC | 20 ms
21,892 KB |
testcase_15 | AC | 22 ms
21,916 KB |
testcase_16 | AC | 24 ms
21,928 KB |
testcase_17 | AC | 23 ms
22,264 KB |
testcase_18 | AC | 21 ms
21,756 KB |
testcase_19 | AC | 19 ms
21,916 KB |
testcase_20 | AC | 20 ms
21,868 KB |
testcase_21 | AC | 20 ms
21,968 KB |
testcase_22 | AC | 20 ms
22,680 KB |
testcase_23 | AC | 19 ms
22,420 KB |
testcase_24 | AC | 19 ms
21,980 KB |
testcase_25 | AC | 19 ms
22,564 KB |
testcase_26 | AC | 19 ms
21,880 KB |
testcase_27 | AC | 21 ms
22,576 KB |
testcase_28 | AC | 20 ms
22,432 KB |
testcase_29 | AC | 20 ms
22,444 KB |
testcase_30 | AC | 21 ms
21,892 KB |
testcase_31 | AC | 22 ms
21,916 KB |
testcase_32 | AC | 23 ms
21,768 KB |
testcase_33 | AC | 23 ms
22,204 KB |
testcase_34 | AC | 20 ms
21,796 KB |
testcase_35 | AC | 21 ms
21,928 KB |
testcase_36 | AC | 19 ms
21,744 KB |
testcase_37 | AC | 20 ms
21,916 KB |
testcase_38 | AC | 20 ms
21,916 KB |
testcase_39 | AC | 22 ms
21,880 KB |
testcase_40 | AC | 23 ms
21,892 KB |
testcase_41 | AC | 22 ms
21,968 KB |
testcase_42 | AC | 22 ms
21,880 KB |
testcase_43 | AC | 22 ms
21,892 KB |
testcase_44 | AC | 20 ms
21,880 KB |
testcase_45 | AC | 20 ms
21,940 KB |
testcase_46 | AC | 20 ms
22,452 KB |
testcase_47 | AC | 21 ms
22,844 KB |
testcase_48 | AC | 21 ms
21,880 KB |
testcase_49 | AC | 21 ms
22,204 KB |
testcase_50 | AC | 21 ms
21,968 KB |
testcase_51 | AC | 22 ms
22,252 KB |
testcase_52 | AC | 21 ms
22,216 KB |
testcase_53 | AC | 19 ms
21,784 KB |
testcase_54 | AC | 21 ms
22,204 KB |
testcase_55 | AC | 19 ms
21,980 KB |
testcase_56 | AC | 21 ms
21,756 KB |
testcase_57 | AC | 19 ms
21,916 KB |
testcase_58 | AC | 19 ms
22,600 KB |
testcase_59 | AC | 21 ms
21,880 KB |
testcase_60 | AC | 20 ms
21,880 KB |
testcase_61 | AC | 20 ms
21,968 KB |
testcase_62 | AC | 23 ms
21,756 KB |
testcase_63 | AC | 22 ms
21,980 KB |
testcase_64 | AC | 21 ms
21,880 KB |
testcase_65 | AC | 21 ms
21,868 KB |
testcase_66 | AC | 22 ms
21,928 KB |
testcase_67 | AC | 23 ms
22,252 KB |
testcase_68 | AC | 26 ms
21,880 KB |
testcase_69 | AC | 25 ms
22,620 KB |
testcase_70 | AC | 22 ms
22,564 KB |
testcase_71 | AC | 22 ms
22,204 KB |
testcase_72 | AC | 20 ms
22,552 KB |
testcase_73 | AC | 20 ms
21,576 KB |
testcase_74 | AC | 20 ms
21,880 KB |
testcase_75 | AC | 21 ms
22,432 KB |
testcase_76 | AC | 20 ms
21,768 KB |
testcase_77 | AC | 23 ms
22,564 KB |
testcase_78 | AC | 23 ms
21,916 KB |
testcase_79 | AC | 23 ms
22,540 KB |
testcase_80 | AC | 24 ms
21,756 KB |
testcase_81 | AC | 19 ms
21,756 KB |
testcase_82 | AC | 20 ms
21,880 KB |
testcase_83 | AC | 20 ms
21,744 KB |
testcase_84 | AC | 21 ms
22,444 KB |
testcase_85 | AC | 19 ms
22,588 KB |
testcase_86 | AC | 19 ms
21,744 KB |
testcase_87 | AC | 20 ms
22,576 KB |
testcase_88 | AC | 20 ms
21,868 KB |
testcase_89 | AC | 20 ms
22,204 KB |
testcase_90 | AC | 21 ms
21,868 KB |
testcase_91 | AC | 19 ms
21,928 KB |
testcase_92 | AC | 23 ms
21,892 KB |
testcase_93 | AC | 24 ms
21,916 KB |
testcase_94 | AC | 23 ms
21,744 KB |
testcase_95 | AC | 23 ms
21,756 KB |
testcase_96 | AC | 20 ms
21,784 KB |
testcase_97 | AC | 20 ms
22,656 KB |
testcase_98 | AC | 20 ms
21,880 KB |
testcase_99 | AC | 21 ms
21,756 KB |
ソースコード
START_TIME = Time.utc.to_unix_ms TL = 900 RND = Random.new(2) macro debug(msg) {% if flag?(:local) %} STDERR.puts({{msg}}) {% end %} end macro debugf(format_string, *args) {% if flag?(:local) %} STDERR.printf({{format_string}}, {{*args}}) {% end %} end def crash(msg, caller_line = __LINE__) puts "[ERROR] line #{caller_line}: #{msg}" exit end macro assert(cond, msg = "", caller_line = __LINE__) {% if flag?(:local) %} if !({{cond}}) crash({{msg}}, {{caller_line}}) end {% end %} end class Solver def initialize @row_cnt = Array(Array(Int32)).new(6) { Array.new(6, 0) } @col_cnt = Array(Array(Int32)).new(6) { Array.new(6, 0) } @row_sum = Array(Array(Int32)).new(6) { Array.new(6, 0) } @col_sum = Array(Array(Int32)).new(6) { Array.new(6, 0) } @row_miss = Array(Array(Bool)).new(6) { Array.new(6, false) } @col_miss = Array(Array(Bool)).new(6) { Array.new(6, false) } @used = Array(Array(Bool)).new(6) { Array.new(6, false) } end def solve place = Array.new(36) { |i| i } 35.times do |i| dices = read_line.split.map(&.to_i) ds = Array.new(6) { |i| dices.count(i + 1) } best_r = 0 best_c = 0 best_v = -10000000 6.times do |r| 6.times do |c| next if @used[r][c] v = 0 6.times do |e| if ds[e] > 0 v += @row_miss[r][e] ? -ds[e] : ds[e] + @row_sum[r][e] v += @col_miss[c][e] ? -ds[e] : ds[e] + @col_sum[c][e] else v += @row_miss[r][e] ? 0 : -@row_sum[r][e] - @row_cnt[r][e] v += @col_miss[c][e] ? 0 : -@col_sum[c][e] - @col_cnt[r][e] end end if v > best_v best_r = r best_c = c best_v = v end end end @used[best_r][best_c] = true 6.times do |e| if ds[e] > 0 @row_cnt[best_r][e] += 1 @row_sum[best_r][e] += ds[e] @col_cnt[best_c][e] += 1 @col_sum[best_c][e] += ds[e] else @row_miss[best_r][e] = true @col_miss[best_c][e] = true end end puts "#{best_r + 1} #{best_c + 1}" STDOUT.flush end {% if flag?(:local) %} score = calc_score() debug("final_score=#{score}") {% end %} end def calc_score mr = 0 mc = 0 6.times do |i| 6.times do |j| if !@used[i][j] mr = i mc = j end end end calc_score_dfs(mr, mc, 0, Array.new(6, 0)) end def calc_score_dfs(mr, mc, i, cnt) ret = 0 if i == 6 6.times do |e| if cnt[e] > 0 @row_cnt[mr][e] += 1 @row_sum[mr][e] += cnt[e] @col_cnt[mc][e] += 1 @col_sum[mc][e] += cnt[e] end 6.times do |j| if @row_cnt[j][e] == 6 ret += @row_sum[j][e] - 3 end if @col_cnt[j][e] == 6 ret += @col_sum[j][e] - 3 end end if cnt[e] > 0 @row_cnt[mr][e] -= 1 @row_sum[mr][e] -= cnt[e] @col_cnt[mc][e] -= 1 @col_sum[mc][e] -= cnt[e] end end debug(ret) else 6.times do |e| cnt[e] += 1 ret += calc_score_dfs(mr, mc, i + 1, cnt) cnt[e] -= 1 end end return ret end end def main solver = Solver.new solver.solve end main