結果
問題 | No.1632 Sorting Integers (GCD of M) |
ユーザー | yudedako |
提出日時 | 2022-03-01 16:45:19 |
言語 | Scala(Beta) (3.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,431 bytes |
コンパイル時間 | 13,826 ms |
コンパイル使用メモリ | 268,120 KB |
実行使用メモリ | 65,644 KB |
最終ジャッジ日時 | 2024-07-07 23:18:32 |
合計ジャッジ時間 | 79,154 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 985 ms
65,348 KB |
testcase_01 | AC | 979 ms
65,260 KB |
testcase_02 | AC | 996 ms
65,408 KB |
testcase_03 | AC | 994 ms
65,256 KB |
testcase_04 | AC | 988 ms
65,360 KB |
testcase_05 | WA | - |
testcase_06 | AC | 978 ms
65,328 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 980 ms
65,496 KB |
testcase_11 | WA | - |
testcase_12 | AC | 975 ms
65,352 KB |
testcase_13 | WA | - |
testcase_14 | AC | 979 ms
65,100 KB |
testcase_15 | WA | - |
testcase_16 | AC | 969 ms
65,308 KB |
testcase_17 | AC | 972 ms
65,252 KB |
testcase_18 | AC | 977 ms
65,344 KB |
testcase_19 | WA | - |
testcase_20 | AC | 984 ms
65,400 KB |
testcase_21 | WA | - |
testcase_22 | AC | 979 ms
65,452 KB |
testcase_23 | AC | 984 ms
65,180 KB |
testcase_24 | AC | 1,003 ms
65,344 KB |
testcase_25 | AC | 989 ms
65,432 KB |
testcase_26 | AC | 985 ms
65,432 KB |
testcase_27 | AC | 989 ms
65,324 KB |
testcase_28 | AC | 985 ms
65,324 KB |
testcase_29 | AC | 981 ms
65,228 KB |
testcase_30 | AC | 986 ms
65,312 KB |
testcase_31 | AC | 988 ms
65,416 KB |
testcase_32 | AC | 989 ms
65,396 KB |
testcase_33 | AC | 972 ms
65,296 KB |
testcase_34 | WA | - |
testcase_35 | AC | 990 ms
65,204 KB |
testcase_36 | AC | 999 ms
65,348 KB |
testcase_37 | AC | 983 ms
65,216 KB |
testcase_38 | AC | 977 ms
65,376 KB |
testcase_39 | AC | 984 ms
65,216 KB |
testcase_40 | WA | - |
testcase_41 | AC | 988 ms
65,288 KB |
testcase_42 | AC | 990 ms
65,308 KB |
testcase_43 | AC | 972 ms
65,104 KB |
testcase_44 | AC | 1,017 ms
65,212 KB |
testcase_45 | AC | 996 ms
65,400 KB |
testcase_46 | AC | 983 ms
65,420 KB |
testcase_47 | AC | 981 ms
65,240 KB |
testcase_48 | AC | 982 ms
65,084 KB |
testcase_49 | AC | 976 ms
65,268 KB |
testcase_50 | AC | 992 ms
65,232 KB |
testcase_51 | AC | 985 ms
65,340 KB |
testcase_52 | AC | 981 ms
65,280 KB |
testcase_53 | AC | 985 ms
65,224 KB |
testcase_54 | AC | 986 ms
65,508 KB |
testcase_55 | AC | 978 ms
65,244 KB |
testcase_56 | AC | 985 ms
65,332 KB |
testcase_57 | AC | 983 ms
65,224 KB |
testcase_58 | AC | 985 ms
65,284 KB |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
ソースコード
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, 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))