結果

問題 No.238 Mr. K's Another Gift
ユーザー ともきともき
提出日時 2015-07-06 01:09:30
言語 Scala(Beta)
(3.4.0)
結果
RE  
実行時間 -
コード長 1,465 bytes
コンパイル時間 11,554 ms
コンパイル使用メモリ 267,752 KB
実行使用メモリ 63,452 KB
最終ジャッジ日時 2023-09-11 11:35:02
合計ジャッジ時間 57,058 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 921 ms
61,520 KB
testcase_01 RE -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 940 ms
61,564 KB
testcase_05 AC 1,035 ms
62,060 KB
testcase_06 AC 989 ms
61,904 KB
testcase_07 AC 1,065 ms
62,308 KB
testcase_08 AC 1,060 ms
62,192 KB
testcase_09 AC 1,076 ms
62,336 KB
testcase_10 AC 967 ms
62,140 KB
testcase_11 AC 964 ms
61,976 KB
testcase_12 AC 986 ms
62,048 KB
testcase_13 AC 973 ms
62,032 KB
testcase_14 AC 1,005 ms
62,080 KB
testcase_15 AC 1,040 ms
62,192 KB
testcase_16 AC 1,041 ms
62,216 KB
testcase_17 AC 995 ms
62,508 KB
testcase_18 AC 1,001 ms
62,264 KB
testcase_19 AC 973 ms
62,408 KB
testcase_20 RE -
testcase_21 AC 972 ms
62,000 KB
testcase_22 AC 928 ms
61,532 KB
testcase_23 WA -
testcase_24 AC 985 ms
62,464 KB
testcase_25 WA -
testcase_26 AC 985 ms
61,700 KB
testcase_27 AC 1,051 ms
62,244 KB
testcase_28 AC 985 ms
61,452 KB
testcase_29 AC 1,069 ms
62,080 KB
testcase_30 AC 972 ms
62,004 KB
testcase_31 AC 986 ms
62,100 KB
testcase_32 AC 987 ms
62,000 KB
testcase_33 AC 992 ms
62,076 KB
testcase_34 AC 980 ms
62,368 KB
testcase_35 AC 1,020 ms
62,256 KB
testcase_36 AC 988 ms
62,224 KB
testcase_37 AC 993 ms
62,044 KB
testcase_38 AC 992 ms
62,056 KB
testcase_39 AC 982 ms
62,080 KB
testcase_40 AC 962 ms
61,968 KB
testcase_41 AC 919 ms
61,904 KB
testcase_42 AC 965 ms
61,976 KB
権限があれば一括ダウンロードができます

ソースコード

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)))
            checking.foreach((i) => if(check(i,'?')){
                               val r = i.indexOf('?')
                               ans = Some(i.updated(r,s(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