結果

問題 No.1370 置換門松列
ユーザー simansiman
提出日時 2022-05-13 15:06:29
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 674 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 35,268 KB
最終ジャッジ日時 2024-04-25 17:07:46
合計ジャッジ時間 7,588 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
12,416 KB
testcase_01 AC 90 ms
12,160 KB
testcase_02 AC 91 ms
12,160 KB
testcase_03 AC 91 ms
12,288 KB
testcase_04 AC 90 ms
12,288 KB
testcase_05 AC 90 ms
12,416 KB
testcase_06 AC 93 ms
12,416 KB
testcase_07 AC 93 ms
12,160 KB
testcase_08 AC 90 ms
12,288 KB
testcase_09 AC 90 ms
12,416 KB
testcase_10 AC 90 ms
12,288 KB
testcase_11 AC 92 ms
12,160 KB
testcase_12 AC 91 ms
12,160 KB
testcase_13 AC 89 ms
12,160 KB
testcase_14 AC 90 ms
12,288 KB
testcase_15 AC 91 ms
12,160 KB
testcase_16 AC 94 ms
12,288 KB
testcase_17 AC 91 ms
12,160 KB
testcase_18 AC 89 ms
12,288 KB
testcase_19 AC 89 ms
12,160 KB
testcase_20 AC 91 ms
12,288 KB
testcase_21 AC 672 ms
35,156 KB
testcase_22 RE -
testcase_23 AC 637 ms
34,984 KB
testcase_24 AC 187 ms
22,784 KB
testcase_25 AC 725 ms
35,192 KB
testcase_26 AC 722 ms
35,268 KB
testcase_27 AC 282 ms
33,240 KB
testcase_28 AC 283 ms
33,376 KB
testcase_29 AC 211 ms
28,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:48: warning: assigned but unused variable - e
Syntax OK

ソースコード

diff #

require 'tsort'

class Hash
  include TSort
  alias tsort_each_node each_key
  def tsort_each_child(node, &block)
    fetch(node).each(&block)
  end
end

N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
E = Hash.new { |h, k| h[k] = [] }

A.each_cons(3) do |a, _, c|
  if a == c
    puts "No"
    exit
  end
end

A.each_cons(2).with_index do |(u, v), i|
  if u == v
    puts "No"
    exit
  end

  if i.even?
    E[u] << v
  else
    E[v] << u
  end
end

1.upto(M) do |i|
  E[i] = E[i].uniq
end

ans = Array.new(M, -1)

begin
  E.tsort.each.with_index(1) do |u, a|
    ans[u - 1] = a
  end

  puts "Yes"
  puts ans.join(" ")
rescue TSort::Cyclic => e
  puts "No"
end
0