結果
問題 | No.1738 What's in the box? |
ユーザー |
|
提出日時 | 2022-01-25 13:25:40 |
言語 | Scala(Beta) (3.6.2) |
結果 |
AC
|
実行時間 | 1,115 ms / 2,000 ms |
コード長 | 472 bytes |
コンパイル時間 | 16,919 ms |
コンパイル使用メモリ | 260,464 KB |
実行使用メモリ | 65,248 KB |
最終ジャッジ日時 | 2024-12-16 02:02:52 |
合計ジャッジ時間 | 90,565 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
ソースコード
import scala.annotation.tailrecimport scala.io.StdIn.*@tailrec def gcd(a: Int, b: Int): Int =b matchcase 0 => acase _ => gcd(b, a % b)@main def main =val Array(n, m) = readLine().split(' ').map(_.toInt)val box = readLine().split(' ').map(_.toInt)if m > 0 thenval unit = box.reduce(gcd)val count = box.map(_ / unit).sumval ratio = m / countprintln(box.map(_ / unit * ratio).mkString(" "))elseprintln(box.mkString(" "))