0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ABC385Cをjavascriptで解いた

Posted at

今日の問題

↑押してください。

自分の回答(javascript)

function Main(input){
  min = 1e18
  max = 1
  let abc = "abcdefghijklmnopqrstuvwxyz".split("")
  let ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("")
  let f = 2
  if(f == 0){
    input = parseInt(input.trim())
  }
  if(f == 1){
    input = input.trim().split("\n").map((a)=>parseInt(a))
  }
  if(f == 2){
    input = input.trim().split("\n").map((a)=>a.split(" ").map((b)=>parseInt(b)))
  }
  if(f == 3){
    input = input.trim().split("\n")
  }
  n = input.shift()[0]
  let hlist = input.shift()
  for(let i = 0;i<n;i++){
    
    a = hlist[i]
    for(let j = 1;j<n;j++){
      count = 0
      
      for(let k = i;k<n;k += j){
        
        
        if(hlist[k] != a){
          break
        }else{
          count ++
          max = Math.max(max,count)
        }
      }
    }
  }
  console.log(max)
}
Main(require("fs").readFileSync(0, "utf8"));
//ここより上は定型文です。

工夫した点

Nが3000以下であるという制約であるため、全探索が可能である。どこから始めるかと、何個おきであるかを2重ループで解く。何個おきであるかは素数しか可能性がないためそっちでやったほうがより効率は良いが、今回はそこまでやらなくても時間制限に間に合う。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?