結果
| 問題 | 
                            No.90 品物の並び替え
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2014-12-08 20:13:15 | 
| 言語 | Ruby  (3.4.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,182 bytes | 
| コンパイル時間 | 218 ms | 
| コンパイル使用メモリ | 7,552 KB | 
| 実行使用メモリ | 19,616 KB | 
| 最終ジャッジ日時 | 2024-06-11 18:29:06 | 
| 合計ジャッジ時間 | 6,892 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | TLE * 1 -- * 8 | 
コンパイルメッセージ
Syntax OK
ソースコード
class ListNumber
  attr_reader :list
  def initialize(n)
    @n = n
    @list = {}
    ((@n**(@n-2))..(@n**@n - 1)).each do |ls|
      flag = true
      @n.times do |i|
        unless num_index(ls, i)
          flag = false
          break
        end
      end
      if flag
        @list[ls] = 0
      end
    end
  end
  def num_index(ls, x)
    a = ls
    @n.times do |i|
      if x == a % @n
        return i
      else
        a = a / @n
      end
    end
    return nil
  end
  def match(ls, l, g)
    a = ls
    @n.times do |i|
      check = a % @n
      if check == l
        return true
      elsif check == g
        return false
      end
      a = a / @n
    end
    raise "ilegal #{ls.to_s(@n)}, #{l}, #{g}"
  end
  def add_score(l, g, s)
    @list.each do |ls, score|
      if match(ls, l, g)
        @list[ls] = score + s
      end
    end
  end
  def max_score
    @list.values.max
  end
end
n, m = gets.split.map(&:to_i)
list = []
m.times do
  list << gets.split.map(&:to_i)
end
lsnum = ListNumber.new(n)
list.each do |ss|
  lsnum.add_score(ss[0], ss[1], ss[2])
end
puts lsnum.max_score