結果

問題 No.238 Mr. K's Another Gift
ユーザー ともきともき
提出日時 2015-07-06 01:17:22
言語 Scala(Beta)
(3.4.0)
結果
WA  
実行時間 -
コード長 1,495 bytes
コンパイル時間 13,616 ms
コンパイル使用メモリ 248,528 KB
実行使用メモリ 63,472 KB
最終ジャッジ日時 2023-09-26 22:58:22
合計ジャッジ時間 58,351 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 856 ms
61,396 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 868 ms
61,484 KB
testcase_05 WA -
testcase_06 AC 899 ms
62,468 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 838 ms
61,408 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 906 ms
61,560 KB
testcase_27 WA -
testcase_28 AC 922 ms
61,584 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 823 ms
61,364 KB
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.io.StdIn.readLine
import scala.collection.mutable.PriorityQueue
import scala.annotation.tailrec
import scala.util.control.Breaks

object Main {
  // def insert(s : String, c : Char, n : Int) : String = {
  //   val (head,tail) = s.splitAt(n)
  //   head + c + tail
  // }
  def solve(s : String) : Option[String] = {
    val n = s.length
    val b = new Breaks
    def check(s : String,c : Char) : Boolean = {
      val n = s.length
      (0 until s.length).forall((i) => {
                                  val j = n - i - 1
                                  s(i) == c || s(j) == c || s(i) == s(j)
                                })
    }
    if(check(s,'?')){
      Some(s.take(n/2) + s(n/2) + s.drop(n/2))
    }else{
      var ans : Option[String] = None
      b.breakable {
        for(i <- 0 until n){
          val j = n - i - 1
          if(s(i) != s(j)){
            val checking = Vector((s.take(i) + "?" + s.drop(i)),
                                  (s.take(j+1) + "?" + s.drop(j+1)))
            println(checking)
            checking.foreach((i) => if(check(i,'?')){
                               val r = i.indexOf('?')
                               ans = Some(i.updated(r,i(n-r)))
                             })
            b.break
          }
        }
      }
      ans
    }
  }
  def main(args : Array[String]) : Unit = {
    val s = readLine
    val ret = solve(s) match {
        case Some(j) => j
        case None    => "NA"
      }
    println(ret)
  }
}
0