結果

問題 No.1512 作文
ユーザー pocaripocari
提出日時 2021-05-26 17:47:52
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 901 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 33,312 KB
最終ジャッジ日時 2024-04-23 13:49:08
合計ジャッジ時間 4,470 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
17,920 KB
testcase_01 AC 77 ms
12,416 KB
testcase_02 AC 78 ms
12,288 KB
testcase_03 AC 80 ms
12,288 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def read_data
  $stdin.read.lines(chomp: true).drop(1)
end

def ok?(prev, value)
  if prev
    prev[-1] <= value[0]
  else
    true
  end
end

def solve(n, list, used, acc, max)
  if max.join.size < acc.join.size
    max = acc
  end
  list.each_with_index do |v, i|
    unless used[i]
      if ok?(acc.last, v)
        used[i] = true
        val = solve(n + 1, list, used, acc + [v], max)
        if max.join.size < val.join.size
          max = val
        end
        used[i] = false
      end
    end
  end
  max
end

def remove_error_data(list)
  list.find_all do |v|
    if v.size == 1
      true
    else
      v.chars.each_cons(2).all? do |a, b|
        a.codepoints.first <= b.codepoints.first
      end
    end
  end
end

def main
  list = read_data
  valid_list = remove_error_data(list)
  pattern = solve(0, valid_list, [false] * valid_list.size, [], [])
  puts pattern.join.size
end

main
0