結果

問題 No.1779 Magical Swap
ユーザー simansiman
提出日時 2021-12-08 07:13:34
言語 Ruby
(3.2.2)
結果
AC  
実行時間 353 ms / 2,000 ms
コード長 540 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 11,212 KB
実行使用メモリ 29,792 KB
最終ジャッジ日時 2023-09-23 07:48:55
合計ジャッジ時間 4,931 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,124 KB
testcase_01 AC 79 ms
15,076 KB
testcase_02 AC 93 ms
15,368 KB
testcase_03 AC 84 ms
15,176 KB
testcase_04 AC 140 ms
21,964 KB
testcase_05 AC 107 ms
19,796 KB
testcase_06 AC 110 ms
20,536 KB
testcase_07 AC 133 ms
21,380 KB
testcase_08 AC 82 ms
15,184 KB
testcase_09 AC 105 ms
17,208 KB
testcase_10 AC 192 ms
23,632 KB
testcase_11 AC 138 ms
22,472 KB
testcase_12 AC 97 ms
16,800 KB
testcase_13 AC 167 ms
21,908 KB
testcase_14 AC 204 ms
29,792 KB
testcase_15 AC 353 ms
15,264 KB
testcase_16 AC 156 ms
28,668 KB
testcase_17 AC 167 ms
15,564 KB
testcase_18 AC 81 ms
15,292 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

T = gets.to_i

T.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  b = gets.split.map(&:to_i)

  if a[0] != b[0] || a.sort != b.sort
    puts 'No'
  else
    i = 3
    ok = true
    checked = Array.new(n + 1, false)

    while i <= n && ok
      if not checked[i]
        if 2 * i <= n
          i.step(n, i) do |j|
            checked[j] = true
          end
        end

        ok = false if !checked[i] && a[i - 1] != b[i - 1]
      end

      i += 2
    end

    if ok
      puts 'Yes'
    else
      puts 'No'
    end
  end
end
0