結果

問題 No.100 直列あみだくじ
ユーザー らっしー(raccy)らっしー(raccy)
提出日時 2014-12-12 21:51:47
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 1,614 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 11,356 KB
実行使用メモリ 28,792 KB
最終ジャッジ日時 2023-09-02 14:23:36
合計ジャッジ時間 11,911 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
15,072 KB
testcase_01 AC 83 ms
15,268 KB
testcase_02 AC 84 ms
15,036 KB
testcase_03 AC 86 ms
15,316 KB
testcase_04 AC 84 ms
15,240 KB
testcase_05 AC 85 ms
15,024 KB
testcase_06 AC 84 ms
15,308 KB
testcase_07 AC 83 ms
15,272 KB
testcase_08 AC 84 ms
15,200 KB
testcase_09 AC 86 ms
15,112 KB
testcase_10 AC 84 ms
15,032 KB
testcase_11 AC 84 ms
15,240 KB
testcase_12 AC 83 ms
15,300 KB
testcase_13 AC 84 ms
15,216 KB
testcase_14 AC 84 ms
15,324 KB
testcase_15 AC 85 ms
15,124 KB
testcase_16 AC 85 ms
15,076 KB
testcase_17 AC 84 ms
15,108 KB
testcase_18 AC 85 ms
15,236 KB
testcase_19 AC 84 ms
15,260 KB
testcase_20 AC 85 ms
15,040 KB
testcase_21 AC 81 ms
15,124 KB
testcase_22 AC 82 ms
15,268 KB
testcase_23 AC 82 ms
15,124 KB
testcase_24 AC 81 ms
15,120 KB
testcase_25 AC 82 ms
15,016 KB
testcase_26 AC 82 ms
15,264 KB
testcase_27 AC 84 ms
15,312 KB
testcase_28 AC 84 ms
15,060 KB
testcase_29 AC 83 ms
15,108 KB
testcase_30 AC 83 ms
15,260 KB
testcase_31 AC 81 ms
15,024 KB
testcase_32 AC 82 ms
15,120 KB
testcase_33 AC 82 ms
15,032 KB
testcase_34 AC 82 ms
15,020 KB
testcase_35 AC 83 ms
15,144 KB
testcase_36 AC 82 ms
15,216 KB
testcase_37 TLE -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
0