結果

問題 No.1827 最長部分スーパーリッチ門松列列
コンテスト
ユーザー yudedako
提出日時 2022-01-30 17:59:51
言語 Scala(Beta)
(3.8.1)
コンパイル:
scalac _filename_
実行:
java -cp .:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala3-library_3/3.8.1/scala3-library_3-3.8.1.jar:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala-library/3.8.1/scala-library-3.8.1.jar _class_
結果
AC  
実行時間 985 ms / 2,000 ms
コード長 699 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,797 ms
コンパイル使用メモリ 276,136 KB
実行使用メモリ 119,124 KB
最終ジャッジ日時 2026-03-09 19:47:10
合計ジャッジ時間 29,190 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import scala.collection.mutable
import scala.io.StdIn.*
import scala.math.*
@main def main =
  val testCase = readLine().toInt
  for _ <- 0 until testCase do
    val n = readLine().toInt
    val permutation = readLine().split(' ').map(_.toInt)
    val isUpper = Array.fill(n){true}
    var count = 1
    var result = 0
    for i <- permutation.indices.sortBy(permutation) do
      if i > 0 then
        if isUpper(i - 1) == isUpper(i) then
          count += 1
        else
          count -= 1
      if i + 1 < n then
        if isUpper(i) == isUpper(i + 1) then
          count += 1
        else
          count -= 1
      isUpper(i) = false
      result = max(result, count)
    println(result)
0