結果

問題 No.672 最長AB列
ユーザー mijimemijime
提出日時 2018-04-15 23:14:11
言語 Scala(Beta)
(3.4.0)
結果
WA  
実行時間 -
コード長 636 bytes
コンパイル時間 8,139 ms
コンパイル使用メモリ 256,072 KB
実行使用メモリ 63,752 KB
最終ジャッジ日時 2023-09-12 18:20:46
合計ジャッジ時間 29,593 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 949 ms
62,580 KB
testcase_01 WA -
testcase_02 AC 955 ms
62,604 KB
testcase_03 AC 957 ms
62,500 KB
testcase_04 AC 947 ms
62,780 KB
testcase_05 AC 949 ms
62,616 KB
testcase_06 AC 937 ms
62,644 KB
testcase_07 AC 928 ms
62,732 KB
testcase_08 WA -
testcase_09 AC 1,081 ms
62,920 KB
testcase_10 AC 1,106 ms
62,832 KB
testcase_11 AC 1,085 ms
62,900 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner

object Main {
  def max(a: Int, b: Int): Int = {
    if (a < b) b else a
  }

  def min(a: Int, b: Int): Int = {
    if (a < b) a else b
  }

  def solve(sc: => Scanner): Unit = {
    val s = sc.next
    val (_, _, _, mn, _) = (s + ' ').foldLeft((0, 0, 0, 0, ' '))((acc, c) =>
      (acc, c) match {
        case ((cn, pn, p2n, mn, pc), c) if pc != c =>
          (1, cn, pn, max(mn, min(cn+p2n, pn)), c)
        case ((cn, pn, p2n, mn, pc), c) => (cn + 1, pn, p2n, mn, c)
    })
    println(mn*2)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}
0