結果
| 問題 |
No.238 Mr. K's Another Gift
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-07-06 01:09:30 |
| 言語 | Scala(Beta) (3.6.2) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,465 bytes |
| コンパイル時間 | 9,806 ms |
| コンパイル使用メモリ | 252,536 KB |
| 実行使用メモリ | 63,592 KB |
| 最終ジャッジ日時 | 2024-06-29 02:11:38 |
| 合計ジャッジ時間 | 46,985 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 WA * 4 RE * 2 |
ソースコード
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)
}
}