Add tags

Add tags to the following comment

うーん、このコードをJavaに移植すると30倍速いんだけど…

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
object P2 extends Application {
  val s1 = readLine.toArray
  val s2 = readLine.toArray
  val len = new Array[Array[int]](s1.length, s2.length)
  
  var max = 0
  for(i <- 0 until s1.length) {
    val c1 = s1(i)
    for(j <- 0 until s2.length) {
      val prev = if(i > 0 && j > 0) len(i-1)(j-1) else 0
      len(i)(j) = if(c1 == s2(j)) prev + 1 else 0
      max = Math.max(max, len(i)(j))
    }
  }
  println(max)
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...