結果

問題 No.238 Mr. K's Another Gift
ユーザー ともきともき
提出日時 2015-07-06 01:18:38
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,051 ms / 2,000 ms
コード長 1,465 bytes
コンパイル時間 9,566 ms
コンパイル使用メモリ 270,552 KB
実行使用メモリ 63,108 KB
最終ジャッジ日時 2023-09-11 11:36:28
合計ジャッジ時間 54,710 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 906 ms
61,440 KB
testcase_01 AC 945 ms
61,920 KB
testcase_02 AC 947 ms
62,040 KB
testcase_03 AC 960 ms
62,052 KB
testcase_04 AC 945 ms
61,636 KB
testcase_05 AC 1,018 ms
62,148 KB
testcase_06 AC 964 ms
61,456 KB
testcase_07 AC 1,035 ms
62,652 KB
testcase_08 AC 1,027 ms
62,208 KB
testcase_09 AC 1,051 ms
62,512 KB
testcase_10 AC 953 ms
62,004 KB
testcase_11 AC 952 ms
62,232 KB
testcase_12 AC 948 ms
61,944 KB
testcase_13 AC 950 ms
61,952 KB
testcase_14 AC 994 ms
62,088 KB
testcase_15 AC 1,043 ms
62,196 KB
testcase_16 AC 1,018 ms
62,064 KB
testcase_17 AC 993 ms
62,120 KB
testcase_18 AC 1,000 ms
61,900 KB
testcase_19 AC 960 ms
62,156 KB
testcase_20 AC 942 ms
61,824 KB
testcase_21 AC 961 ms
62,068 KB
testcase_22 AC 912 ms
61,336 KB
testcase_23 AC 962 ms
61,952 KB
testcase_24 AC 988 ms
62,080 KB
testcase_25 AC 986 ms
62,072 KB
testcase_26 AC 964 ms
61,440 KB
testcase_27 AC 1,043 ms
62,128 KB
testcase_28 AC 973 ms
61,720 KB
testcase_29 AC 1,043 ms
62,096 KB
testcase_30 AC 947 ms
61,828 KB
testcase_31 AC 985 ms
62,264 KB
testcase_32 AC 966 ms
62,132 KB
testcase_33 AC 975 ms
62,108 KB
testcase_34 AC 969 ms
62,056 KB
testcase_35 AC 1,007 ms
62,192 KB
testcase_36 AC 988 ms
63,108 KB
testcase_37 AC 985 ms
62,292 KB
testcase_38 AC 977 ms
61,932 KB
testcase_39 AC 965 ms
62,244 KB
testcase_40 AC 936 ms
62,012 KB
testcase_41 AC 935 ms
61,496 KB
testcase_42 AC 948 ms
63,088 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,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