結果
| 問題 |
No.429 CupShuffle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-19 09:06:29 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 471 ms / 2,000 ms |
| コード長 | 1,014 bytes |
| コンパイル時間 | 67 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 45,184 KB |
| 最終ジャッジ日時 | 2024-12-16 05:34:47 |
| 合計ジャッジ時間 | 4,586 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
Syntax OK
ソースコード
# frozen_string_literal: true
class Array
def swap!(a, b)
ia = a
ib = b
self[ia], self[ib] = self[ib], self[ia]
end
def divide_by_question
question_index = index { _1[0] == '?' }
if question_index.zero?
[[], to_integer]
else
[self[0..(question_index - 1)], self[(question_index + 1)..-1]]
.map { _1.to_integer }
end
end
def to_integer
map { _1.map(&:to_i) }
end
def move_cups(moves)
moves.each do |left, right|
swap!(left - 1, right - 1)
end
self
end
def detect_position(other)
zip(other)
.map
.with_index { |pair, index| [pair[0] != pair[1], index] }
.filter { |flag, _index| flag }
.map { |_flag, index| index + 1 }
.join(' ')
end
end
def solve
t, b = A.divide_by_question
ct = (1..N).to_a.move_cups(t)
cb = C.move_cups(b.reverse)
ct.detect_position(cb)
end
N, K, X = gets.split.map(&:to_i)
A = K.times.map { gets.chomp.split }
C = gets.chomp.split.map(&:to_i)
puts solve