結果

問題 No.1366 交換門松列・梅
コンテスト
ユーザー yumechi
提出日時 2021-02-24 01:12:34
言語 Scala(Beta)
(3.8.2)
コンパイル:
scalac _filename_
実行:
/usr/bin/scala_run _class_
結果
AC  
実行時間 381 ms / 1,000 ms
+ 893µs
コード長 719 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,529 ms
コンパイル使用メモリ 280,568 KB
実行使用メモリ 60,924 KB
最終ジャッジ日時 2026-07-28 16:49:06
合計ジャッジ時間 14,519 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.Scanner
import scala.annotation.tailrec

object Main extends App {

  val sc = new Scanner(System.in)

  val a = Array.fill(3)(sc.nextInt)
  val b = Array.fill(3)(sc.nextInt)

  def solve(a: Array[Int], b: Array[Int]): Boolean = {
    def isKadomatsu(c: Array[Int]): Boolean = {
      c.size == c.toSet.size && (c.min == c(1) || c.max == c(1))
    }

    for(i <- 0 to 2) {
      for(j <- 0 to 2) {
        var ca = a.clone()
        var cb = b.clone()
        val ta = a(i)
        val tb = b(j)
        ca.update(i, tb)
        cb.update(j, ta)
        if(isKadomatsu(ca) && isKadomatsu(cb)) {
          return true
        }
      }
    }
    false
  }

  println(if (solve(a, b)) "Yes" else "No")
}
0