結果

問題 No.1818 6 Operations
ユーザー yudedakoyudedako
提出日時 2022-01-30 23:19:47
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,302 ms / 2,500 ms
コード長 1,137 bytes
コンパイル時間 8,544 ms
コンパイル使用メモリ 262,292 KB
実行使用メモリ 63,536 KB
最終ジャッジ日時 2023-09-02 01:50:18
合計ジャッジ時間 47,591 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 900 ms
62,360 KB
testcase_01 AC 907 ms
62,448 KB
testcase_02 AC 892 ms
62,528 KB
testcase_03 AC 897 ms
62,092 KB
testcase_04 AC 895 ms
62,092 KB
testcase_05 AC 903 ms
62,348 KB
testcase_06 AC 900 ms
61,892 KB
testcase_07 AC 911 ms
62,384 KB
testcase_08 AC 1,022 ms
63,536 KB
testcase_09 AC 1,143 ms
62,668 KB
testcase_10 AC 1,031 ms
62,552 KB
testcase_11 AC 1,025 ms
62,416 KB
testcase_12 AC 1,103 ms
62,536 KB
testcase_13 AC 1,043 ms
62,528 KB
testcase_14 AC 1,095 ms
62,256 KB
testcase_15 AC 1,113 ms
62,488 KB
testcase_16 AC 1,067 ms
62,280 KB
testcase_17 AC 1,150 ms
62,704 KB
testcase_18 AC 1,241 ms
62,708 KB
testcase_19 AC 1,207 ms
62,500 KB
testcase_20 AC 1,252 ms
62,420 KB
testcase_21 AC 1,256 ms
62,660 KB
testcase_22 AC 1,182 ms
62,768 KB
testcase_23 AC 1,273 ms
62,532 KB
testcase_24 AC 1,218 ms
62,608 KB
testcase_25 AC 1,266 ms
62,520 KB
testcase_26 AC 1,233 ms
62,240 KB
testcase_27 AC 1,230 ms
62,416 KB
testcase_28 AC 1,027 ms
62,600 KB
testcase_29 AC 1,026 ms
62,192 KB
testcase_30 AC 1,239 ms
62,188 KB
testcase_31 AC 1,233 ms
62,548 KB
testcase_32 AC 1,302 ms
62,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.collection.mutable
import scala.io.StdIn.*
import scala.math.*
import scala.util.chaining.*

def distance(a: String, b: String): Int =
  val result = Array.fill(2){Array.tabulate(b.length + 1){i => i}}
  for
    i <- a.indices
  do
    val prev = i & 1
    val current = (i & 1) ^ 1
    result(current)(0) = i + 1
    for j <- b.indices do
      if a(i) == b(j) then
        result(current)(j + 1) = min(result(prev)(j), min(result(current)(j), result(prev)(j + 1)) + 1)
      else
        result(current)(j + 1) = min(result(prev)(j), min(result(current)(j), result(prev)(j + 1))) + 1
  result(a.length & 1).last

@main def main =
  val Array(n, m) = readLine().split(' ').map(_.toInt)
  val from = readLine().split(' ').map(_.toInt)
  val to = readLine().split(' ').map(_.toInt)
  val fromStr = mutable.StringBuilder()
  for a <- from do
    fromStr.append(' ')
    for _ <- 0 until a do
      fromStr.append('1')
  val toStr = mutable.StringBuilder()
  for b <- to do
    toStr.append(' ')
    for _ <- 0 until b do
      toStr.append('1')
  val result = distance(fromStr.toString(), toStr.toString())
  println(result)
0