結果

問題 No.1632 Sorting Integers (GCD of M)
ユーザー yudedakoyudedako
提出日時 2022-03-01 16:45:19
言語 Scala(Beta)
(3.4.0)
結果
WA  
実行時間 -
コード長 1,431 bytes
コンパイル時間 14,091 ms
コンパイル使用メモリ 248,468 KB
実行使用メモリ 63,664 KB
最終ジャッジ日時 2023-09-22 06:39:17
合計ジャッジ時間 81,544 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 977 ms
60,744 KB
testcase_01 AC 997 ms
62,140 KB
testcase_02 AC 1,002 ms
62,484 KB
testcase_03 AC 1,007 ms
62,276 KB
testcase_04 AC 1,011 ms
61,948 KB
testcase_05 WA -
testcase_06 AC 1,028 ms
62,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 993 ms
62,188 KB
testcase_11 WA -
testcase_12 AC 1,011 ms
62,504 KB
testcase_13 WA -
testcase_14 AC 1,018 ms
62,628 KB
testcase_15 WA -
testcase_16 AC 1,007 ms
62,420 KB
testcase_17 AC 1,018 ms
62,528 KB
testcase_18 AC 1,012 ms
62,544 KB
testcase_19 WA -
testcase_20 AC 992 ms
62,168 KB
testcase_21 WA -
testcase_22 AC 1,034 ms
62,408 KB
testcase_23 AC 1,018 ms
62,476 KB
testcase_24 AC 1,012 ms
62,556 KB
testcase_25 AC 1,001 ms
62,516 KB
testcase_26 AC 1,015 ms
63,312 KB
testcase_27 AC 1,008 ms
62,592 KB
testcase_28 AC 1,014 ms
62,532 KB
testcase_29 AC 1,009 ms
62,124 KB
testcase_30 AC 1,008 ms
62,412 KB
testcase_31 AC 1,004 ms
62,508 KB
testcase_32 AC 1,004 ms
62,656 KB
testcase_33 AC 995 ms
62,564 KB
testcase_34 WA -
testcase_35 AC 997 ms
62,568 KB
testcase_36 AC 1,000 ms
62,244 KB
testcase_37 AC 1,006 ms
62,540 KB
testcase_38 AC 999 ms
62,500 KB
testcase_39 AC 1,004 ms
62,720 KB
testcase_40 WA -
testcase_41 AC 1,013 ms
62,400 KB
testcase_42 AC 1,025 ms
62,728 KB
testcase_43 AC 1,018 ms
62,600 KB
testcase_44 AC 1,004 ms
62,540 KB
testcase_45 AC 1,009 ms
62,304 KB
testcase_46 AC 1,003 ms
62,524 KB
testcase_47 AC 995 ms
62,824 KB
testcase_48 AC 1,003 ms
62,148 KB
testcase_49 AC 1,013 ms
62,872 KB
testcase_50 AC 996 ms
62,420 KB
testcase_51 AC 1,010 ms
62,744 KB
testcase_52 AC 1,015 ms
62,724 KB
testcase_53 AC 1,023 ms
62,708 KB
testcase_54 AC 1,030 ms
62,516 KB
testcase_55 AC 1,026 ms
62,432 KB
testcase_56 AC 1,023 ms
62,512 KB
testcase_57 AC 1,011 ms
62,428 KB
testcase_58 AC 1,013 ms
62,500 KB
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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))


0