Submission #143642


Source Code Expand

Copy
import java.util.Scanner
import java.io.PrintWriter

/**
 * Created by hama_du on 2014/03/15.
 */
object Main extends App {
  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val line = in.nextLine().toCharArray
  val allPtn = line.length * 25
  val palindromePtn = countPalindromes()

  out.println(allPtn - palindromePtn)
  out.flush()

  def countPalindromes(): Int = {
    val differentPairs = countDifferentPairs(0, line.length-1, 0)
    if (differentPairs == 0) {
      if (line.length % 2 == 1) {
        25
      } else {
        0
      }
    } else if (differentPairs == 1) {
      2
    } else {
      0
    }
  }

  def countDifferentPairs(f: Int, t: Int, cnt: Int): Int = {
    if (f >= t) {
      cnt
    } else {
      val add = if (line(f) != line(t)) 1 else 0
      countDifferentPairs(f+1, t-1, cnt+add)
    }
  }
}

Submission Info

Submission Time
Task B - こだわりの名前
User hamadu
Language Scala (2.9.1)
Score 100
Code Size 899 Byte
Status
Exec Time 1281 ms
Memory 50288 KB

Test Cases

Set Name Score / Max Score Test Cases
All 100 / 100 hand_1.txt, hand_2.txt, hand_3.txt, hand_4.txt, hand_5.txt, hand_6.txt, palindrome_1.txt, palindrome_12345.txt, palindrome_2.txt, palindrome_299998.txt, palindrome_299999.txt, palindrome_3.txt, palindrome_300000.txt, palindrome_4.txt, palindrome_5.txt, palindrome_6789.txt, palindrome_67890.txt, palindrome_mod_1.txt, palindrome_mod_1000.txt, palindrome_mod_10000.txt, palindrome_mod_100001.txt, palindrome_mod_2.txt, palindrome_mod_200000.txt, palindrome_mod_299999.txt, palindrome_mod_3.txt, palindrome_mod_300000.txt, palindrome_mod_4.txt, palindrome_mod_5.txt, palindrome_mod_50001.txt, random_1.txt, random_10.txt, random_100001.txt, random_101.txt, random_3000.txt, random_300000.txt, random_50001.txt
Case Name Status Exec Time Memory
hand_1.txt 1261 ms 50164 KB
hand_2.txt 1206 ms 50288 KB
hand_3.txt 1209 ms 49940 KB
hand_4.txt 1281 ms 50072 KB
hand_5.txt 1193 ms 49992 KB
hand_6.txt 1209 ms 49792 KB
palindrome_1.txt 1074 ms 43016 KB
palindrome_12345.txt 1134 ms 44116 KB
palindrome_2.txt 1064 ms 43000 KB
palindrome_299998.txt 1217 ms 50128 KB
palindrome_299999.txt 1216 ms 50168 KB
palindrome_3.txt 1059 ms 43016 KB
palindrome_300000.txt 1200 ms 50032 KB
palindrome_4.txt 1099 ms 43016 KB
palindrome_5.txt 1131 ms 43004 KB
palindrome_6789.txt 1105 ms 43980 KB
palindrome_67890.txt 1160 ms 45636 KB
palindrome_mod_1.txt 1068 ms 43040 KB
palindrome_mod_1000.txt 1084 ms 43004 KB
palindrome_mod_10000.txt 1155 ms 44788 KB
palindrome_mod_100001.txt 1167 ms 46120 KB
palindrome_mod_2.txt 1073 ms 43012 KB
palindrome_mod_200000.txt 1168 ms 47708 KB
palindrome_mod_299999.txt 1217 ms 49796 KB
palindrome_mod_3.txt 1066 ms 43008 KB
palindrome_mod_300000.txt 1218 ms 50080 KB
palindrome_mod_4.txt 1071 ms 43092 KB
palindrome_mod_5.txt 1060 ms 42996 KB
palindrome_mod_50001.txt 1144 ms 45488 KB
random_1.txt 1075 ms 43028 KB
random_10.txt 1085 ms 43152 KB
random_100001.txt 1158 ms 46196 KB
random_101.txt 1064 ms 43068 KB
random_3000.txt 1107 ms 43516 KB
random_300000.txt 1210 ms 49976 KB
random_50001.txt 1142 ms 45632 KB
sample_1.txt 1073 ms 43140 KB
sample_2.txt 1073 ms 43016 KB
sample_3.txt 1117 ms 43012 KB