結果
問題 |
No.100 直列あみだくじ
|
ユーザー |
|
提出日時 | 2014-12-12 21:51:47 |
言語 | Ruby (3.4.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,614 bytes |
コンパイル時間 | 201 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 14,024 KB |
最終ジャッジ日時 | 2024-06-11 21:01:35 |
合計ジャッジ時間 | 11,322 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 TLE * 1 -- * 10 |
コンパイルメッセージ
Syntax OK
ソースコード
class Kumiawase @@checked_list = {} def initialize(start_list) start_list = start_list.dup start_list.delete(nil) sorted_list = start_list.sort @list = start_list.map do |i| sorted_list.index(i) end end def check if @@checked_list.include?(@list) return @@checked_list[@list] end @list.size.times do |s| nokori_list = @list.dup chukan_list = [] i = s nokori_list.delete(i) j = 0 nokori_list.delete(j) chukan_list[j] = i while true j = @list[j] nokori_list.delete(j) if chukan_list.include?(j) if chukan_list[i] == j flag = true else flag = false end break else chukan_list[i] = j end i = @list[i] nokori_list.delete(i) if chukan_list.include?(i) if chukan_list[j] == i flag = true else flag = false end break else chukan_list[j] = i end end if flag if nokori_list.empty? @@checked_list[@list] = true return true else if Kumiawase.new(nokori_list).check @@checked_list[@list] = true return true end end end end @@checked_list[@list] = false return false end end gets a = gets.split.map{|s|s.to_i-1} kumi = Kumiawase.new(a) if kumi.check puts "Yes" else puts "No" end