1
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?

ABC382Cをjavascriptで解いた

Posted at

今日の問題

↑押してください。

自分の回答(javascript)

function Main(input){
    min = 1e18
    max = -1e18
    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)))
    }
    //ここより上は定型文です。
   let [n,m] = input.shift()
   let alist = input.shift()
   let blist = input.shift()
   let junbi = new Array(200002).fill(-1)
   count = 0
   for(let i = 200001;i>=0;i--){
     while(alist[count]>i&&count != -2){
       
       count ++
       if(count>=n){
         count = -2
         break
       }
     }
     junbi[i] = count
   }
   res = []
   for(let i = 0;i<m;i++){
     res.push(junbi[blist[i]]+1)
   }
   console.log(res.join(" "))
   
   //console.log(junbi)
  }
  Main(require("fs").readFileSync(0, "utf8"));
  

工夫した点

あらかじめ表を作っておくことによって高速に求められます。美味しさが大きければ大きいほど、届く客はどんどん奥になっていくことを利用します。

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
1
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?