結果

問題 No.5014 セクスタプル (reactive)
ユーザー tomeruntomerun
提出日時 2022-12-29 20:23:38
言語 Crystal
(1.11.2)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 3,871 bytes
コンパイル時間 20,602 ms
実行使用メモリ 22,704 KB
スコア 629,682,905
平均クエリ数 35.00
最終ジャッジ日時 2022-12-29 20:24:06
合計ジャッジ時間 22,252 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
22,420 KB
testcase_01 AC 21 ms
21,780 KB
testcase_02 AC 22 ms
21,952 KB
testcase_03 AC 23 ms
21,772 KB
testcase_04 AC 22 ms
22,180 KB
testcase_05 AC 21 ms
21,880 KB
testcase_06 AC 25 ms
21,880 KB
testcase_07 AC 25 ms
21,980 KB
testcase_08 AC 23 ms
22,620 KB
testcase_09 AC 25 ms
21,880 KB
testcase_10 AC 20 ms
22,204 KB
testcase_11 AC 20 ms
22,444 KB
testcase_12 AC 21 ms
21,980 KB
testcase_13 AC 20 ms
22,228 KB
testcase_14 AC 19 ms
21,940 KB
testcase_15 AC 20 ms
21,916 KB
testcase_16 AC 20 ms
21,892 KB
testcase_17 AC 21 ms
22,216 KB
testcase_18 AC 20 ms
22,704 KB
testcase_19 AC 22 ms
21,880 KB
testcase_20 AC 21 ms
21,980 KB
testcase_21 AC 20 ms
22,252 KB
testcase_22 AC 22 ms
21,892 KB
testcase_23 AC 21 ms
22,228 KB
testcase_24 AC 23 ms
21,768 KB
testcase_25 AC 20 ms
22,216 KB
testcase_26 AC 21 ms
21,780 KB
testcase_27 AC 20 ms
21,992 KB
testcase_28 AC 19 ms
22,408 KB
testcase_29 AC 21 ms
22,444 KB
testcase_30 AC 21 ms
22,252 KB
testcase_31 AC 25 ms
22,552 KB
testcase_32 AC 24 ms
22,704 KB
testcase_33 AC 23 ms
22,216 KB
testcase_34 AC 25 ms
22,600 KB
testcase_35 AC 21 ms
22,192 KB
testcase_36 AC 21 ms
22,588 KB
testcase_37 AC 21 ms
22,600 KB
testcase_38 AC 21 ms
21,780 KB
testcase_39 AC 20 ms
21,892 KB
testcase_40 AC 21 ms
22,576 KB
testcase_41 AC 22 ms
22,004 KB
testcase_42 AC 21 ms
21,916 KB
testcase_43 AC 21 ms
21,760 KB
testcase_44 AC 20 ms
21,892 KB
testcase_45 AC 20 ms
21,916 KB
testcase_46 AC 19 ms
22,204 KB
testcase_47 AC 20 ms
21,904 KB
testcase_48 AC 20 ms
22,204 KB
testcase_49 AC 21 ms
21,928 KB
testcase_50 AC 21 ms
22,588 KB
testcase_51 AC 20 ms
21,928 KB
testcase_52 AC 21 ms
22,252 KB
testcase_53 AC 20 ms
21,928 KB
testcase_54 AC 21 ms
21,904 KB
testcase_55 AC 21 ms
21,892 KB
testcase_56 AC 24 ms
21,928 KB
testcase_57 AC 25 ms
21,928 KB
testcase_58 AC 25 ms
22,132 KB
testcase_59 AC 22 ms
21,928 KB
testcase_60 AC 22 ms
22,564 KB
testcase_61 AC 20 ms
21,756 KB
testcase_62 AC 21 ms
21,768 KB
testcase_63 AC 20 ms
21,868 KB
testcase_64 AC 19 ms
21,904 KB
testcase_65 AC 20 ms
21,756 KB
testcase_66 AC 20 ms
22,004 KB
testcase_67 AC 21 ms
21,928 KB
testcase_68 AC 21 ms
22,432 KB
testcase_69 AC 20 ms
22,420 KB
testcase_70 AC 21 ms
21,756 KB
testcase_71 AC 21 ms
22,456 KB
testcase_72 AC 20 ms
21,968 KB
testcase_73 AC 20 ms
22,240 KB
testcase_74 AC 20 ms
22,216 KB
testcase_75 AC 21 ms
21,940 KB
testcase_76 AC 20 ms
21,808 KB
testcase_77 AC 21 ms
21,928 KB
testcase_78 AC 19 ms
21,880 KB
testcase_79 AC 20 ms
22,548 KB
testcase_80 AC 21 ms
22,612 KB
testcase_81 AC 20 ms
22,516 KB
testcase_82 AC 20 ms
22,692 KB
testcase_83 AC 20 ms
22,620 KB
testcase_84 AC 20 ms
22,204 KB
testcase_85 AC 24 ms
22,216 KB
testcase_86 AC 22 ms
22,252 KB
testcase_87 AC 27 ms
21,768 KB
testcase_88 AC 21 ms
22,252 KB
testcase_89 AC 20 ms
21,892 KB
testcase_90 AC 20 ms
22,552 KB
testcase_91 AC 20 ms
22,432 KB
testcase_92 AC 19 ms
21,992 KB
testcase_93 AC 21 ms
21,916 KB
testcase_94 AC 20 ms
21,756 KB
testcase_95 AC 20 ms
21,992 KB
testcase_96 AC 20 ms
21,756 KB
testcase_97 AC 20 ms
21,892 KB
testcase_98 AC 21 ms
21,780 KB
testcase_99 AC 20 ms
22,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

START_TIME = Time.utc.to_unix_ms
TL         = 900
RND        = Random.new(2)
X0         = (ENV["X0"]? || 45).to_i * 0.1
X1         = (ENV["X1"]? || -21).to_i * 0.1
X2         = (ENV["X2"]? || 16).to_i * 0.1
X3         = (ENV["X3"]? || 49).to_i * 0.1
X4         = (ENV["X4"]? || 40).to_i * 0.1
X5         = (ENV["X5"]? || -6).to_i * 0.1

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.0
      if i < 1
        best_r = best_c = i
      else
        6.times do |r|
          6.times do |c|
            next if @used[r][c]
            v = 0.0
            6.times do |e|
              if ds[e] > 0
                v += @row_miss[r][e] ? -ds[e] * X0 : ds[e] * X1 + @row_sum[r][e] * X2
                v += @col_miss[c][e] ? -ds[e] * X0 : ds[e] * X1 + @col_sum[c][e] * X2
              else
                v += @row_miss[r][e] ? X3 : -@row_sum[r][e] * X4 - @row_cnt[r][e] * X5
                v += @col_miss[c][e] ? X3 : -@col_sum[c][e] * X4 - @col_cnt[r][e] * X5
              end
            end
            if v > best_v
              best_r = r
              best_c = c
              best_v = v
            end
          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
0