結果
問題 | No.1632 Sorting Integers (GCD of M) |
ユーザー | yudedako |
提出日時 | 2022-03-01 16:48:11 |
言語 | Scala(Beta) (3.4.0) |
結果 |
AC
|
実行時間 | 850 ms / 2,000 ms |
コード長 | 1,437 bytes |
コンパイル時間 | 9,881 ms |
コンパイル使用メモリ | 255,624 KB |
実行使用メモリ | 63,876 KB |
最終ジャッジ日時 | 2024-07-07 23:23:47 |
合計ジャッジ時間 | 61,046 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 781 ms
63,532 KB |
testcase_01 | AC | 783 ms
63,756 KB |
testcase_02 | AC | 776 ms
63,616 KB |
testcase_03 | AC | 778 ms
63,732 KB |
testcase_04 | AC | 780 ms
63,428 KB |
testcase_05 | AC | 787 ms
63,560 KB |
testcase_06 | AC | 784 ms
63,516 KB |
testcase_07 | AC | 780 ms
63,264 KB |
testcase_08 | AC | 777 ms
63,748 KB |
testcase_09 | AC | 768 ms
63,524 KB |
testcase_10 | AC | 778 ms
63,648 KB |
testcase_11 | AC | 796 ms
63,676 KB |
testcase_12 | AC | 806 ms
63,520 KB |
testcase_13 | AC | 773 ms
63,772 KB |
testcase_14 | AC | 803 ms
63,772 KB |
testcase_15 | AC | 823 ms
63,440 KB |
testcase_16 | AC | 807 ms
63,564 KB |
testcase_17 | AC | 767 ms
63,520 KB |
testcase_18 | AC | 767 ms
63,380 KB |
testcase_19 | AC | 772 ms
63,876 KB |
testcase_20 | AC | 772 ms
63,352 KB |
testcase_21 | AC | 778 ms
63,784 KB |
testcase_22 | AC | 765 ms
63,332 KB |
testcase_23 | AC | 773 ms
63,824 KB |
testcase_24 | AC | 777 ms
63,808 KB |
testcase_25 | AC | 779 ms
63,684 KB |
testcase_26 | AC | 772 ms
63,660 KB |
testcase_27 | AC | 761 ms
63,728 KB |
testcase_28 | AC | 762 ms
63,820 KB |
testcase_29 | AC | 768 ms
63,756 KB |
testcase_30 | AC | 769 ms
63,492 KB |
testcase_31 | AC | 767 ms
63,448 KB |
testcase_32 | AC | 769 ms
63,568 KB |
testcase_33 | AC | 774 ms
63,536 KB |
testcase_34 | AC | 775 ms
63,568 KB |
testcase_35 | AC | 770 ms
63,576 KB |
testcase_36 | AC | 771 ms
63,472 KB |
testcase_37 | AC | 763 ms
63,632 KB |
testcase_38 | AC | 766 ms
63,684 KB |
testcase_39 | AC | 772 ms
63,584 KB |
testcase_40 | AC | 767 ms
63,684 KB |
testcase_41 | AC | 770 ms
63,600 KB |
testcase_42 | AC | 765 ms
63,712 KB |
testcase_43 | AC | 769 ms
63,520 KB |
testcase_44 | AC | 766 ms
63,520 KB |
testcase_45 | AC | 772 ms
63,520 KB |
testcase_46 | AC | 767 ms
63,352 KB |
testcase_47 | AC | 776 ms
63,184 KB |
testcase_48 | AC | 765 ms
63,692 KB |
testcase_49 | AC | 850 ms
63,520 KB |
testcase_50 | AC | 760 ms
63,568 KB |
testcase_51 | AC | 775 ms
63,532 KB |
testcase_52 | AC | 773 ms
63,748 KB |
testcase_53 | AC | 772 ms
63,580 KB |
testcase_54 | AC | 773 ms
63,484 KB |
testcase_55 | AC | 780 ms
63,660 KB |
testcase_56 | AC | 776 ms
63,728 KB |
testcase_57 | AC | 768 ms
63,568 KB |
testcase_58 | AC | 806 ms
63,596 KB |
testcase_59 | AC | 776 ms
63,476 KB |
testcase_60 | AC | 773 ms
63,592 KB |
testcase_61 | AC | 770 ms
63,476 KB |
testcase_62 | AC | 770 ms
63,604 KB |
ソースコード
import java.io.PrintWriter import scala.collection.mutable.* import scala.io.StdIn.* import scala.util.chaining.* import scala.math.* import scala.reflect.ClassTag import scala.util.* import scala.annotation.tailrec import scala.collection.mutable @tailrec def gcd(a: Int, b: Int): Int = b match case 0 => a case _ => gcd(b, a % b) def powMod(base: Int, exp: Int, mod: Int): Long = var result = 1L var b = base.toLong % mod var e = exp while e > 0 do if (e & 1) == 1 then result = result * b % mod b = b * b % mod e = e >> 1 result def calcRest(digitCount: Array[Int], mod: Int): Long = var r = 0L for i <- 1 to 9 if digitCount(i - 1) > 0 do val length = digitCount(i - 1) r = (r * powMod(10, length, mod)) % mod var value = 0L for d <- 29 to 0 by -1 do value = (value + value * powMod(10, length >> (d + 1), mod)) % mod if ((length >> d) & 1) == 1 then value = (value * 10 + i) % mod r = (r + value) % mod r @main def main = val n = readLine.toInt val digitCount = readLine.split(' ').map(_.toInt) val diff = for i <- 1 to 9 if digitCount(i - 1) > 0 j <- 1 until i if digitCount(j - 1) > 0 yield 9 * (i - j) val g = diff.fold(0)(gcd) val result = (1 to g).filter(g % _ == 0).findLast{ calcRest(digitCount, _) == 0 } result match case Some(d) => println(d) case None => println(calcRest(digitCount, 1000000007))