結果

問題 No.1130 Grid Numbers
ユーザー osyo-mangaosyo-manga
提出日時 2022-02-04 20:48:40
言語 Ruby
(3.3.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 644 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-06-11 11:22:35
合計ジャッジ時間 1,485 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
12,288 KB
testcase_01 AC 76 ms
12,160 KB
testcase_02 AC 77 ms
12,032 KB
testcase_03 AC 73 ms
12,288 KB
testcase_04 AC 74 ms
12,416 KB
testcase_05 AC 74 ms
12,288 KB
testcase_06 AC 74 ms
12,416 KB
testcase_07 AC 74 ms
12,416 KB
testcase_08 AC 74 ms
12,288 KB
testcase_09 AC 74 ms
12,288 KB
testcase_10 AC 73 ms
12,288 KB
testcase_11 AC 73 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# "4 5" => [4, 5] に変換
h, w = gets.split.map(&:to_i)

# gets で 4行読み込んで 1行ごとを
# "9 0 2 3 8\n" => [9, 0, 2, 3, 8]
# に変換
lines = (0...h).map { gets.split.map(&:to_i) }

# [[9, 0, 2, 3, 8], [1, 1, 4, 5, 1], [9, 8, 6, 4, 0], [1, 9, 7, 0, 9]]
# ↓
# ↓ flatten で平坦化
# ↓
# [9, 0, 2, 3, 8, 1, 1, 4, 5, 1, 9, 8, 6, 4, 0, 1, 9, 7, 0, 9]
# ↓
# ↓ sort で昇順
# ↓
# [0, 0, 0, 1, 1, 1, 1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 9, 9, 9]
# ↓
# ↓each_slice で 5個に分割
# ↓
# [[0, 0, 0, 1, 1], [1, 1, 2, 3, 4], [4, 5, 6, 7, 8], [8, 9, 9, 9, 9]]
puts lines.flatten.sort.each_slice(w).map { _1.join(" ") }
0