結果
| 問題 |
No.241 出席番号(1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-07-31 10:44:43 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 92 ms / 2,000 ms |
| コード長 | 442 bytes |
| コンパイル時間 | 112 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2024-11-30 21:31:43 |
| 合計ジャッジ時間 | 4,463 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
コンパイルメッセージ
Main.rb:17: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
# input
N = gets.to_i
A = N.times.map{
gets.to_i
}
def check_nums nums
nums.index.with_index{|num, i| num == A[i]}
end
def change_nums nums, index
i = ((0...nums.size).to_a - [index]).sample
nums[index], nums[i] = nums[i], nums[index]
end
if (!A.any?{|i| i >= N } && A.uniq.size == 1)
p -1
else
nums = (0...N).to_a.shuffle
while (ng = check_nums(nums)) != nil
change_nums nums, ng
end
nums.each{|i| p i }
end