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?

今日の問題

↑押してください。

自分の回答(javascript)

function Main(input){
    min = 1e18
    max = -1e18
    let abc = "abcdefghijklmnopqrstuvwxyz".split("")
    let ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("")
    let f = 1
    if(f == 0){
      input = parseInt(input.trim())
    }
    if(f == 1){
      input = input.trim().split(" ").map((a)=>parseInt(a))
    }
    if(f == 2){
      input = input.trim().split("\n").map((a)=>a.split(" ").map((b)=>parseInt(b)))
    }
    //ここより上は定型文です。
   let [n,m] = input
   res = []
   for(let i = 1;i<11;i++){
     dfs(i,1,[i])
   }
   
   console.log(res.length)
   console.log(res.join("\n"))
   function dfs(a,depth,list){
     for(let i = 0;i<11;i++){
       list.push(a+10+i)
       
       //console.log(list.join(" "))
       if(((m-(a+10+i))/10)>=n-(depth+1)||((depth+1) == n&&m>=(a+10+i))){
         if(depth+1 == n){
           res.push(list.join(" "))
         }else{
          dfs(a+10+i,depth+1,list)
         }
       }
       list.pop()
     }
   }
  }
  Main(require("fs").readFileSync(0, "utf8"));
  

工夫した点

dfsによる全探索です。途中でありえない可能性は排除することによって、高速化し時間に間に合うようしています。D問題にしては簡単めかもしれないです。

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