티스토리 뷰

https://www.acmicpc.net/problem/2529

 

2529번: 부등호

두 종류의 부등호 기호 ‘<’와 ‘>’가 k개 나열된 순서열 A가 있다. 우리는 이 부등호 기호 앞뒤에 서로 다른 한 자릿수 숫자를 넣어서 모든 부등호 관계를 만족시키려고 한다. 예를 들어, 제시

www.acmicpc.net

const fs = require('fs');
const input = fs.readFileSync("./dev/stdin").toString().trim().split('\n');
const N = +input[0]
const inequality  = input[1].split(' ')


const answer = [];

function check(str,cnt){
  if(cnt==N){
    answer.push(str);
    return;
  }else{
    const last = str[cnt];
    if(inequality[cnt]=='>'){
      for(let i = 0; i<10; i++){
        if(!str.includes(`${i}`) && last>i){
           check(str+`${i}`,cnt+1)
        }
      }
    }else{
      for(let i = 0; i<10; i++){
        if(!str.includes(`${i}`) && last<i){
           check(str+`${i}`,cnt+1)
        }
      }
    }
  }
}


for(let i = 0; i<10; i++){
  check(`${i}`,0);
}

console.log(answer.pop()+'\n'+answer.shift())
728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함