<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>youngjin_kim2.log</title>
        <link>https://velog.io/</link>
        <description>개발하는 멍멍이</description>
        <lastBuildDate>Sun, 30 Oct 2022 03:53:28 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>youngjin_kim2.log</title>
            <url>https://images.velog.io/images/youngjin_kim2/profile/35c1596a-53fe-4ff1-9a40-29b291ddc29c/KakaoTalk_20200407_110803742.jpg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. youngjin_kim2.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/youngjin_kim2" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[Codility GenomicRangeQuery]]></title>
            <link>https://velog.io/@youngjin_kim2/Codility-GenomicRangeQuery</link>
            <guid>https://velog.io/@youngjin_kim2/Codility-GenomicRangeQuery</guid>
            <pubDate>Sun, 30 Oct 2022 03:53:28 GMT</pubDate>
            <description><![CDATA[<h2 id="문제">문제</h2>
<p>A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which correspond to the types of successive nucleotides in the sequence. Each nucleotide has an impact factor, which is an integer. Nucleotides of types A, C, G and T have impact factors of 1, 2, 3 and 4, respectively. You are going to answer several queries of the form: What is the minimal impact factor of nucleotides contained in a particular part of the given DNA sequence?</p>
<p>The DNA sequence is given as a non-empty string S = S[0]S[1]...S[N-1] consisting of N characters. There are M queries, which are given in non-empty arrays P and Q, each consisting of M integers. The K-th query (0 ≤ K &lt; M) requires you to find the minimal impact factor of nucleotides contained in the DNA sequence between positions P[K] and Q[K] (inclusive).</p>
<p>For example, consider string S = CAGCCTA and arrays P, Q such that:</p>
<pre><code>P[0] = 2    Q[0] = 4
P[1] = 5    Q[1] = 5
P[2] = 0    Q[2] = 6</code></pre><p>The answers to these M = 3 queries are as follows:</p>
<p>The part of the DNA between positions 2 and 4 contains nucleotides G and C (twice), whose impact factors are 3 and 2 respectively, so the answer is 2.
The part between positions 5 and 5 contains a single nucleotide T, whose impact factor is 4, so the answer is 4.
The part between positions 0 and 6 (the whole string) contains all nucleotides, in particular nucleotide A whose impact factor is 1, so the answer is 1.
Write a function:</p>
<p>def solution(S, P, Q)</p>
<p>that, given a non-empty string S consisting of N characters and two non-empty arrays P and Q consisting of M integers, returns an array consisting of M integers specifying the consecutive answers to all queries.</p>
<p>Result array should be returned as an array of integers.</p>
<p>For example, given the string S = CAGCCTA and arrays P, Q such that:</p>
<pre><code>P[0] = 2    Q[0] = 4
P[1] = 5    Q[1] = 5
P[2] = 0    Q[2] = 6</code></pre><p>the function should return the values [2, 4, 1], as explained above.</p>
<p>Write an efficient algorithm for the following assumptions:</p>
<p>N is an integer within the range [1..100,000];
M is an integer within the range [1..50,000];
each element of arrays P and Q is an integer within the range [0..N - 1];
P[K] ≤ Q[K], where 0 ≤ K &lt; M;
string S consists only of upper-case English letters A, C, G, T.</p>
<h2 id="처음-접근">처음 접근</h2>
<ul>
<li>전체 문자열 배열을 숫자로 치환하고 매번 min 값을 구하도록 함 </li>
<li>시간 복잡도 초과</li>
</ul>
<h2 id="최종-접근">최종 접근</h2>
<pre><code class="language-python">def solution(S, P, Q):
    # write your code in Python 3.8.10
    listA=[0]
    listC = [0]
    listG = [0]

    idxA = 0
    idxC = 0
    idxG = 0 

    for ch in S:
        if ch == &quot;A&quot;:
            idxA +=1
            listA.append(idxA)
            listC.append(idxC)
            listG.append(idxG)
        elif ch == &quot;C&quot;:
            idxC +=1
            listA.append(idxA)
            listC.append(idxC)
            listG.append(idxG)
        elif ch == &quot;G&quot;:
            idxG +=1
            listA.append(idxA)
            listC.append(idxC)
            listG.append(idxG)
        else:
            listA.append(idxA)
            listC.append(idxC)
            listG.append(idxG)

    #print(listA,listC,listG)

    total = []
    for i in range(len(P)):
        left = P[i]
        right = Q[i]+1
        num = 4
        if listA[right] - listA[left] &gt;0:
            num =1
        elif listC[right] -listC[left]&gt;0:
            num =2
        elif listG[right] - listG[left]&gt;0:
            num =3
        total.append(num)

    return total</code></pre>
<ul>
<li>A,C,G 에 대한 리스트를 만든다.</li>
<li>문자열에서 해당하는 문자 값이 나오면 list에 값을 추가해서 더한다. </li>
<li>최종적으로 검사할때는 해당 범위내에서 변화가 있는지만 감지하면 된다. </li>
<li>변화가 없으면 default인 4</li>
<li>시간 복잡도는 O(m*n)</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[codility MaxCounter]]></title>
            <link>https://velog.io/@youngjin_kim2/codility-MaxCounter</link>
            <guid>https://velog.io/@youngjin_kim2/codility-MaxCounter</guid>
            <pubDate>Thu, 20 Oct 2022 06:33:56 GMT</pubDate>
            <description><![CDATA[<ul>
<li>문제 
You are given N counters, initially set to 0, and you have two possible operations on them:</li>
</ul>
<p>increase(X) − counter X is increased by 1,
max counter − all counters are set to the maximum value of any counter.
A non-empty array A of M integers is given. This array represents consecutive operations:</p>
<p>if A[K] = X, such that 1 ≤ X ≤ N, then operation K is increase(X),
if A[K] = N + 1 then operation K is max counter.
For example, given integer N = 5 and array A such that:</p>
<pre><code>A[0] = 3
A[1] = 4
A[2] = 4
A[3] = 6
A[4] = 1
A[5] = 4
A[6] = 4</code></pre><p>the values of the counters after each consecutive operation will be:</p>
<pre><code>(0, 0, 1, 0, 0)
(0, 0, 1, 1, 0)
(0, 0, 1, 2, 0)
(2, 2, 2, 2, 2)
(3, 2, 2, 2, 2)
(3, 2, 2, 3, 2)
(3, 2, 2, 4, 2)</code></pre><p>The goal is to calculate the value of every counter after all operations.</p>
<p>Write a function:</p>
<p>def solution(N, A)</p>
<p>that, given an integer N and a non-empty array A consisting of M integers, returns a sequence of integers representing the values of the counters.</p>
<p>Result array should be returned as an array of integers.</p>
<p>For example, given:</p>
<pre><code>A[0] = 3
A[1] = 4
A[2] = 4
A[3] = 6
A[4] = 1
A[5] = 4
A[6] = 4</code></pre><p>the function should return [3, 2, 2, 4, 2], as explained above.</p>
<p>Write an efficient algorithm for the following assumptions:</p>
<p>N and M are integers within the range [1..100,000];
each element of array A is an integer within the range [1..N + 1].</p>
<ul>
<li>첫번째 풀이
문제 내용을 그대로 구현 
시간 초과 </li>
</ul>
<p>-두번째 풀이</p>
<pre><code class="language-python">def solution(N, A):
    # write your code in Python 3.8.10

    num_dic = {}
    max_num = 0
    for num in A:
        num-=1
        if num &gt;= N:
            max_num +=find_max(num_dic)
            num_dic={}
        elif num in num_dic:
            num_dic[num]+=1
        else:
            num_dic[num] = 1

    num_list= [max_num]*N

    for key in num_dic.keys():
        num_list[key] += num_dic[key]    

    return num_list

def find_max(num_dic):
    max_val = 0 
    for key in num_dic.keys():
        max_val = max(max_val,num_dic[key])
    return max_val</code></pre>
<ul>
<li>max 값을 찾는 것이 큰 오버헤드가 되는 것을 발견, </li>
<li>전체 배열에서 max값을 찾는것이 비효율적이라고 생각해서, count된것만 넣는 dict 생성 </li>
<li>dict에서 max값 찾아주는 함수 만듬 </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[653. Two Sum IV - Input is a BST]]></title>
            <link>https://velog.io/@youngjin_kim2/653.-Two-Sum-IV-Input-is-a-BST</link>
            <guid>https://velog.io/@youngjin_kim2/653.-Two-Sum-IV-Input-is-a-BST</guid>
            <pubDate>Sun, 09 Oct 2022 09:33:08 GMT</pubDate>
            <description><![CDATA[<h2 id="문제">문제</h2>
<p>Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the given target. </p>
<p>Example 1:</p>
<p>Input: root = [5,3,6,2,4,null,7], k = 9
Output: true
Example 2:
Input: root = [5,3,6,2,4,null,7], k = 28
Output: false</p>
<p>Constraints:</p>
<p>The number of nodes in the tree is in the range [1, 10^4].
-10^4 &lt;= Node.val &lt;= 10^4
root is guaranteed to be a valid binary search tree.
-10^5 &lt;= k &lt;= 10^5</p>
<h2 id="코드">코드</h2>
<pre><code class="language-python"># Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
from collections import deque
class Solution:
    def findTarget(self, root: Optional[TreeNode], k: int) -&gt; bool:

        q = deque()

        q.append([root,k])

        while q:
            node, k = q.popleft()                        
            now = node.val
            if k-now != now:
                now = k-now
                answer = self.find_tree(root,now)               

                if answer == True:
                    return answer
            if node.left !=None:
                q.append([node.left,k])
            if node.right !=None:
                q.append([node.right, k])


        return False


    def find_tree(self,root,val):
        #print(root.val, val)
        tmp = False
        if root.val == val:
            return True
        if root.left == None and root.right == None:
            return False 
        if root.val&gt;val and root.left !=None:
            tmp = self.find_tree(root.left,val)
        elif root.val &lt;val and root.right != None:
            tmp = self.find_tree(root.right,val)
        return tmp</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>root node부터 집어 넣어서 짝이되는 걸 찾는다.</li>
<li>자기 자신이 복제되지않도록 k-now != now 일때만 </li>
<li>q에다가 집어 넣어서 끝까지 찾아보도록 한다. </li>
</ul>
<h2 id="빠른-코드">빠른 코드</h2>
<pre><code class="language-python">mapp = set()
mapp.add(k-n.val)</code></pre>
<ul>
<li>set을 이용하여 node의 나머지 값을 찾는다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[3. Longest Substring Without Repeating Characters]]></title>
            <link>https://velog.io/@youngjin_kim2/3.-Longest-Substring-Without-Repeating-Characters</link>
            <guid>https://velog.io/@youngjin_kim2/3.-Longest-Substring-Without-Repeating-Characters</guid>
            <pubDate>Thu, 22 Sep 2022 08:06:11 GMT</pubDate>
            <description><![CDATA[<p>Given a string s, find the length of the longest substring without repeating characters.</p>
<p>Example 1:</p>
<p>Input: s = &quot;abcabcbb&quot;
Output: 3
Explanation: The answer is &quot;abc&quot;, with the length of 3.
Example 2:</p>
<p>Input: s = &quot;bbbbb&quot;
Output: 1
Explanation: The answer is &quot;b&quot;, with the length of 1.
Example 3:</p>
<p>Input: s = &quot;pwwkew&quot;
Output: 3
Explanation: The answer is &quot;wke&quot;, with the length of 3.
Notice that the answer must be a substring, &quot;pwke&quot; is a subsequence and not a substring.</p>
<p>Constraints:</p>
<p>0 &lt;= s.length &lt;= 5 * 10^4
s consists of English letters, digits, symbols and spaces.</p>
<ul>
<li>문제 코드</li>
</ul>
<pre><code class="language-python">class Solution:
    def lengthOfLongestSubstring(self, s: str) -&gt; int:

        if len(s)&lt;=1:
            return len(s)

        newChar = &quot;&quot;
        maxCount = 0
        nowCount = 0
        for i in range(len(s)):

            if s[i] in newChar:
                for j in range(len(newChar)):
                    if newChar[j]==s[i]:
                        break
                maxCount = max(maxCount, nowCount)

                newChar = newChar[j+1:]+s[i]
                nowCount=  len(newChar)
            else:
                newChar+=s[i]
                nowCount+=1
                maxCount = max(maxCount, nowCount)
        return maxCount</code></pre>
<ul>
<li>문제 풀이<ul>
<li>문자열의 맨 앞에서부터 새로운 문자열에 추가하고, 이미 있는 문자면 새로운 문자열에서 해당 문자의 위치를 찾는다. </li>
<li>문자를 찾으면 그 문자 다음부터 새로운 문자를 만든다. </li>
<li>아니면 문자열 길이 갱신</li>
<li>worst는 문자열의 <del>~</del>aa 이런경우일것 같은데, O(n^3)? 인듯</li>
</ul>
</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[1.TwoSum]]></title>
            <link>https://velog.io/@youngjin_kim2/1.TwoSum</link>
            <guid>https://velog.io/@youngjin_kim2/1.TwoSum</guid>
            <pubDate>Thu, 22 Sep 2022 07:45:25 GMT</pubDate>
            <description><![CDATA[<p>Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.</p>
<p>You may assume that each input would have exactly one solution, and you may not use the same element twice.</p>
<p>You can return the answer in any order.</p>
<p>Example 1:</p>
<p>Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
Example 2:</p>
<p>Input: nums = [3,2,4], target = 6
Output: [1,2]
Example 3:</p>
<p>Input: nums = [3,3], target = 6
Output: [0,1]</p>
<ul>
<li><p>문제 풀이 </p>
<pre><code class="language-python">class Solution:
  def twoSum(self, nums: List[int], target: int) -&gt; List[int]:
      n = len(nums)
      for i in range(n):
          for j in range(i+1,n):
              if target == nums[i]+nums[j]:
                  return[i,j]</code></pre>
</li>
<li><p>문제 분석</p>
<ul>
<li>간단하게 생각해서 Bruteforce로 구성했음 전체 개수가 10^4개라 brute force해도 된다고 생각</li>
<li>O(n^2)</li>
</ul>
</li>
<li><p>개선 코드</p>
<pre><code class="language-python">class Solution:    
  def twoSum(self, nums: List[int], target: int) -&gt; List[int]:

      numDict={}

      for i,n in enumerate(nums):
          if n in numDict.keys():
              return [i,numDict[n]]
          else:
              numDict[target-n] = i</code></pre>
</li>
<li><p>개선 방안</p>
<ul>
<li>두개의 합을 구하는 것이기 때문에 Dictionary의 key, value를 이용하면 구할 수 있다. </li>
<li>dictionary에 존재하지않으면 target에서 현재 value를 뺀 값을 key로 하고 index를 value로 넣는다.</li>
<li>dictionary에 존재할 경우, 내 index와 dictionary의 index를 return한다.<ul>
<li>순서는 상관 X </li>
<li>O(n)으로 개선</li>
</ul>
</li>
</ul>
</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[3184. 양]]></title>
            <link>https://velog.io/@youngjin_kim2/3184.-%EC%96%91</link>
            <guid>https://velog.io/@youngjin_kim2/3184.-%EC%96%91</guid>
            <pubDate>Thu, 15 Jul 2021 06:49:10 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-링크">문제 링크</h2>
<p><a href="https://www.acmicpc.net/problem/3184">3184. 양</a></p>
<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">from collections import deque

row, col = list(map(int, input().split()))

board = [[0 for c in range(col)] for r in range(row)]

wolf_list = []
lamb_list = []
death_wolf = 0
death_lamb = 0
for r in range(row):
    tmp_board = input()
    for c in range(col):
        board[r][c] = tmp_board[c]
        if tmp_board[c] == &#39;v&#39;:
            wolf_list.append([r, c])
        if tmp_board[c] == &#39;o&#39;:
            lamb_list.append([r,c])

visited = [[0 for c in range(col)] for r in range(row)]
for i in range(len(wolf_list)):

    x, y = wolf_list[i]

    if visited[x][y] == 1:
        continue
    que = deque()

    que.append([x, y])

    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]

    one_area = []
    one_area.append([x, y])
    visited[x][y] = 1
    while len(que) &gt; 0:
        x, y = que.popleft()

        for i in range(4):
            next_x = x + dx[i]
            next_y = y + dy[i]

            if 0 &lt;= next_x &lt; row and 0 &lt;= next_y &lt; col and visited[next_x][next_y] == 0 and board[next_x][
                next_y] != &#39;#&#39;:
                que.append([next_x, next_y])
                one_area.append([next_x, next_y])
                visited[next_x][next_y] = 1

    lamb_count = 0
    wolf_count = 0

    for x, y in one_area:

        if board[x][y] == &#39;o&#39;:
            lamb_count += 1
        if board[x][y] == &#39;v&#39;:
            wolf_count += 1

    if lamb_count &gt; wolf_count:
        death_wolf += wolf_count
    else:
        death_lamb += lamb_count

print(len(lamb_list) - death_lamb, len(wolf_list) - death_wolf)</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>영역을 나누면 되는 문제</li>
<li>영역을 먼저 나누고, 해당 영역의 wolf와 lamb 숫자를 센다.</li>
<li>lamb가 많으면 wolf가 죽고 , 반대면 lamb가 죽음</li>
<li>죽은만큼 처음 센 갯수에서 빼준다. </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[17135. 캐슬 디펜스]]></title>
            <link>https://velog.io/@youngjin_kim2/17135.-%EC%BA%90%EC%8A%AC-%EB%94%94%ED%8E%9C%EC%8A%A4</link>
            <guid>https://velog.io/@youngjin_kim2/17135.-%EC%BA%90%EC%8A%AC-%EB%94%94%ED%8E%9C%EC%8A%A4</guid>
            <pubDate>Wed, 14 Jul 2021 23:42:01 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-링크">문제 링크</h2>
<p><a href="https://www.acmicpc.net/problem/17135">17135. 캐슬 디펜스</a></p>
<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">from itertools import combinations
from collections import deque
import copy
row,col,D = list(map(int,input().split()))

original_board = [[0 for c in range(col)]for r in range(row)]

comb_list = []

for i in range(col):
    comb_list.append(i)

archor_list = list(combinations(comb_list,3))

#print(archor_list)

for i in range(row):
    num_list = list(map(int,input().split()))
    for j in range(col):
        original_board[i][j] = num_list[j]

#print(board)

max_count = 0

for archors in archor_list:
    board = copy.deepcopy(original_board)
    kill = []
    count = 0

    for tot in range(row):
        for archor in archors:
            start = [row-1,archor]

            que = deque()

            que.append([start[0],start[1],1])
            visited = [[0 for c in range(col)]for r in range(row)]
            while len(que)&gt;0:
                x,y,distance = que.popleft()

                if distance &gt; D:
                    break
                if board[x][y] == 1:
                    kill.append([x,y])
                    break
                visited[x][y] = 1

                dx = [0,-1,0]
                dy = [-1,0,1]

                for i in range(3):
                    next_x = x+dx[i]
                    next_y = y+dy[i]

                    if 0&lt;=next_x&lt;row and 0&lt;=next_y&lt;col and visited[next_x][next_y] == 0:
                        que.append([next_x,next_y,distance+1])

        #print(kill)
        for die in kill:
            x,y = die
            if board[x][y] == 1:
                count+=1
                board[x][y]=0
        kill =[]
        #print(board, count)

        for i in range(row-1,0,-1):
            for j in range(col):
                board[i][j] = board[i-1][j]

        for j in range(col):
            board[0][j] = 0

        #print(board)

    max_count = max(max_count,count)


print(max_count)</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li><p>첫번째 시도</p>
<ul>
<li>예제는 다 맞았으나 제출하자마자 틀림</li>
<li>반례 1번에서 답이 6이 나옴</li>
<li>Kill list를 초기화하지않아서 발생하는 문제임을 파악</li>
<li>해당 부분 해결하니 합격</li>
</ul>
</li>
</ul>
<h2 id="반례">반례</h2>
<blockquote>
<p>2 4 2
1 1 1 1
0 1 1 0
answer :5 </p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[11053. 가장 긴 증가하는 부분 수열]]></title>
            <link>https://velog.io/@youngjin_kim2/11053.-%EA%B0%80%EC%9E%A5-%EA%B8%B4-%EC%A6%9D%EA%B0%80%ED%95%98%EB%8A%94-%EB%B6%80%EB%B6%84-%EC%88%98%EC%97%B4</link>
            <guid>https://velog.io/@youngjin_kim2/11053.-%EA%B0%80%EC%9E%A5-%EA%B8%B4-%EC%A6%9D%EA%B0%80%ED%95%98%EB%8A%94-%EB%B6%80%EB%B6%84-%EC%88%98%EC%97%B4</guid>
            <pubDate>Wed, 14 Jul 2021 01:15:08 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-링크">문제 링크</h2>
<p><a href="https://www.acmicpc.net/problem/11053">11053. 가장 긴 증가하는 부분 수열</a></p>
<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">N = int(input())

num_list= list(map(int,input().split()))

arr  = [0]*1001

for i in range(len(num_list)):
    arr[num_list[i]] = max(arr[:num_list[i]]) + 1

print(max(arr))
</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>num_list의 새로운 값은 기존 arr의 값중에서 가장 큰 값보다 +1만큼 length 증가 </li>
<li>max(arr)의 값이 가장 긴 증가 부분 수열 </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[9205. 맥주 마시면서 걸어가기]]></title>
            <link>https://velog.io/@youngjin_kim2/9205.-%EB%A7%A5%EC%A3%BC-%EB%A7%88%EC%8B%9C%EB%A9%B4%EC%84%9C-%EA%B1%B8%EC%96%B4%EA%B0%80%EA%B8%B0</link>
            <guid>https://velog.io/@youngjin_kim2/9205.-%EB%A7%A5%EC%A3%BC-%EB%A7%88%EC%8B%9C%EB%A9%B4%EC%84%9C-%EA%B1%B8%EC%96%B4%EA%B0%80%EA%B8%B0</guid>
            <pubDate>Wed, 14 Jul 2021 00:31:52 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-링크">문제 링크</h2>
<p><a href="https://www.acmicpc.net/problem/9205">9205. 맥주 마시면서 걸어가기</a></p>
<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">from collections import deque

T = int(input())


for test in range(T):
    conv = int(input())

    start_x, start_y = list(map(int,input().split()))

    conv_list = []
    for c in range(conv):
        tmp_conv = list(map(int,input().split()))
        conv_list.append(tmp_conv)

    visited = [0]*(conv+1)

    end_x, end_y = list(map(int,input().split()))

    conv_list.append([end_x,end_y])
    que = deque()

    que.append([start_x,start_y])

    end_checker = False
    while len(que)&gt;0:
        now_x,now_y = que.popleft()

        if now_x == end_x and now_y == end_y:
            end_checker = True
            break
        for i in range(conv+1):
            if visited[i] ==0 and abs(now_x - conv_list[i][0]) + abs(now_y - conv_list[i][1]) &lt;= 1000 :
                que.append([conv_list[i][0],conv_list[i][1]])
                visited[i] = 1

    if end_checker:
        print(&#39;happy&#39;)
    else:
        print(&#39;sad&#39;)</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>처음 위치를 큐에 넣음</li>
<li>end 위치도 conv_list에 같이 넣음</li>
<li>현재 위치에서 아직 방문하지 않았거나, 거리가 1000이하인 편의점들을 큐에 넣음</li>
<li>end위치에 도착하면 break하고 출력 </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[1931. 회의실 배정]]></title>
            <link>https://velog.io/@youngjin_kim2/1931.-%ED%9A%8C%EC%9D%98%EC%8B%A4-%EB%B0%B0%EC%A0%95</link>
            <guid>https://velog.io/@youngjin_kim2/1931.-%ED%9A%8C%EC%9D%98%EC%8B%A4-%EB%B0%B0%EC%A0%95</guid>
            <pubDate>Tue, 13 Jul 2021 02:04:16 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-링크">문제 링크</h2>
<p><a href="https://www.acmicpc.net/problem/1931">1931. 회의실 배정</a></p>
<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">N = int(input())

total_list=[]
for i in range(N):
    num_list = list(map(int,input().split()))

    total_list.append(num_list)

total_list.sort(key=lambda x:(x[1],x[0]))

#print(total_list)
start =0
end = 0
count = 0
for i in range(N):
    now_start , now_end = total_list[i]

    if now_start &lt; end:
        continue

    else:
        end = now_end
        count+=1

print(count)</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li><p>첫번째 시도</p>
<ul>
<li>끝나는 시간을 기준으로 정렬하고 전체 회의 리스트를 순회</li>
<li>전타임 끝나는 시간 뒤에 시작하는 회의부터 다시 시작하도록 함 </li>
<li>반례 1번을 풀지 못하는 경우 발생 </li>
</ul>
</li>
<li><p>두번째 시도</p>
<ul>
<li>끝나는 시간으로 정렬하고, 시작하는 시간으로 한번더 정렬</li>
<li>두가지 조건으로 동시에 정렬하는 파이썬 기능 사용, 잘 알아둘것</li>
</ul>
</li>
</ul>
<h2 id="반례">반례</h2>
<blockquote>
<p>2
4 4
1 4
answer : 2</p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[8980. 택배 ]]></title>
            <link>https://velog.io/@youngjin_kim2/8980.-%ED%83%9D%EB%B0%B0</link>
            <guid>https://velog.io/@youngjin_kim2/8980.-%ED%83%9D%EB%B0%B0</guid>
            <pubDate>Wed, 07 Jul 2021 08:51:12 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">city, size = list(map(int,input().split()))

city_box_list = [[0 for k in range(city)]for l in range(city)]

box_num = int(input())

for b in range(box_num):
    start, end, weight = list(map(int, input().split()))
    city_box_list[start-1][end-1] = weight

#print(city_box_list)

tmp_weight = size
count = 0

end_box_list = [0]*(city)

for i in range(city):
    count+=end_box_list[i]
    end_box_list[i]=0
    for j in range(i,city):
        if city_box_list[i][j] != 0 :
            can_weight = min(tmp_weight,city_box_list[i][j])

            end_box_list[j] += can_weight

            tmp_size = size
            for k in range(city):
                tmp_size-=end_box_list[k]
                if tmp_size&lt;0:
                    end_box_list[k]+=tmp_size
                    for l in range(k+1,city):
                        end_box_list[l] =0
                    break


print(count)</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>마을에서 내릴 박스의 양을 들고다니는 배열 선언 </li>
<li>다음 마을에 갔을때 내릴께 있으면 내리고 count 증가</li>
<li>더 실을께 있는데 size를 넘으면 마을이 가까운 것부터 실음</li>
<li>이미 size를 초과했는데 마을이 더 가까운게 있으면 버리고 가까운거 실음 </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[10971. 외판원 순회 2]]></title>
            <link>https://velog.io/@youngjin_kim2/10971.-%EC%99%B8%ED%8C%90%EC%9B%90-%EC%88%9C%ED%9A%8C-2</link>
            <guid>https://velog.io/@youngjin_kim2/10971.-%EC%99%B8%ED%8C%90%EC%9B%90-%EC%88%9C%ED%9A%8C-2</guid>
            <pubDate>Fri, 02 Jul 2021 04:21:22 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">from itertools import permutations

N = int(input())

graph = [[0 for col in range(N)]for row in range(N)]

for i in range(N):
    num_list = list(map(int,input().split()))
    for j in range(N):
        graph[i][j] = num_list[j]
        if num_list[j] == 0 :
            graph[i][j] = float(&#39;INF&#39;)

max_count = float(&#39;INF&#39;)

move = []
for i in range(N):
    move.append(i)

move_list = list(permutations(move,N))

for move in move_list:
    count = 0
    continue_point = False
    for j in range(len(move)-1):
        count += graph[move[j]][move[j+1]]
        if count &gt; max_count:
            continue_point= True
            break
    if continue_point:
        continue

    count += graph[move[j+1]][move[0]]

    if count &lt; max_count:
        max_count = count

print(max_count)</code></pre>
<h2 id="문제풀이">문제풀이</h2>
<ul>
<li>주어진 도시의 개수가 충분히 적어 브루트포스가 가능할것으로 판단</li>
<li>도시의 순열을 구해서 길이값을 더하고 가장 길이가 작은것을 넣도록 함 </li>
<li>처음 제출시 시간초과 문제 발생 -&gt; Count를 계산할때 이미 max보다 큰경우는 프루닝 하도록함 </li>
<li>예시에서는 도시간 거리가 없는것이 0으로 나오므로 이부분을 inf로 바꿔서 수행 </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[10026. 적록색약]]></title>
            <link>https://velog.io/@youngjin_kim2/10026.-%EC%A0%81%EB%A1%9D%EC%83%89%EC%95%BD</link>
            <guid>https://velog.io/@youngjin_kim2/10026.-%EC%A0%81%EB%A1%9D%EC%83%89%EC%95%BD</guid>
            <pubDate>Fri, 02 Jul 2021 03:33:52 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">from collections import deque

N= int(input())

graph = [[0 for col in range(N)]for row in range(N)]

for i in range(N):
    graph_row = input()
    for j in range(N):
        graph[i][j] = graph_row[j]

visited = [[0 for col in range(N)]for row in range(N)]

count = 0

color_list =[&quot;R&quot;,&quot;G&quot;,&quot;B&quot;]
for color in range(3):
    while True:
        find = False
        for i in range(N):
            if find == True:
                break
            for j in range(N):
                if graph[i][j] == color_list[color] and visited[i][j] == 0 :
                    start = [i,j]
                    find = True
                    break

        if find == False:
            break

        que = deque()

        que.append(start)

        visited[start[0]][start[1]] = 1

        while len(que)&gt;0:
            x,y = que.popleft()


            dx = [-1,1,0,0]
            dy = [0,0,-1,1]

            for i in range(4):
                next_x = x+dx[i]
                next_y =y+dy[i]

                if 0&lt;=next_x&lt;N and 0&lt;=next_y&lt;N and visited[next_x][next_y] == 0 and graph[next_x][next_y] == color_list[color]:
                    que.append([next_x,next_y])
                    visited[next_x][next_y] = 1

        count+=1


for i in range(N):
    for j in range(N):
        if graph[i][j] == &#39;G&#39;:
            graph[i][j] = &#39;R&#39;

color_list =[&quot;R&quot;,&quot;B&quot;]

two_color_count = 0
visited = [[0 for col in range(N)]for row in range(N)]
for color in range(2):
    while True:
        find = False
        for i in range(N):
            if find == True:
                break
            for j in range(N):
                if graph[i][j] == color_list[color] and visited[i][j] == 0 :
                    start = [i,j]
                    find = True
                    break

        if find == False:
            break

        que = deque()

        que.append(start)

        visited[start[0]][start[1]] = 1

        while len(que)&gt;0:
            x,y = que.popleft()

            dx = [-1,1,0,0]
            dy = [0,0,-1,1]

            for i in range(4):
                next_x = x+dx[i]
                next_y =y+dy[i]

                if 0&lt;=next_x&lt;N and 0&lt;=next_y&lt;N and visited[next_x][next_y] == 0 and graph[next_x][next_y] == color_list[color]:
                    que.append([next_x,next_y])
                    visited[next_x][next_y] = 1

        two_color_count+=1

print(count, two_color_count)</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>R,G,B 3개의 값 순서대로 가장 처음 나오는 곳을 찾는다. </li>
<li>가장 처음 나온곳을 기준으로 4방향 이동하며 같은 값을 찾는다. </li>
<li>visited를 갱신하면서 가다가, 더이상 que가 없으면 count를 하나 증가시키고 다시 처음부터 그래프를 찾아서 다음 R,G,B 값을 찾는다. </li>
<li>최종 count의 개수가 구역의 개수</li>
<li>적록색약은 R을 G와 일치시켜주고 찾는다. </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[14659. 한조서열정리하고옴ㅋㅋ]]></title>
            <link>https://velog.io/@youngjin_kim2/14659.-%ED%95%9C%EC%A1%B0%EC%84%9C%EC%97%B4%EC%A0%95%EB%A6%AC%ED%95%98%EA%B3%A0%EC%98%B4%E3%85%8B%E3%85%8B</link>
            <guid>https://velog.io/@youngjin_kim2/14659.-%ED%95%9C%EC%A1%B0%EC%84%9C%EC%97%B4%EC%A0%95%EB%A6%AC%ED%95%98%EA%B3%A0%EC%98%B4%E3%85%8B%E3%85%8B</guid>
            <pubDate>Fri, 02 Jul 2021 00:40:39 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">man = int(input())

num_list = list(map(int,input().split()))

max_count = 0
now_count = 0
start_man = num_list[0]
for i in range(1,man):
    if start_man &lt; num_list[i]:
        if max_count &lt; now_count:
            max_count = now_count
        now_count = 0
        start_man = num_list[i]
    else:
        now_count+=1

if now_count &gt; max_count:
    max_count = now_count
print(max_count)</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>현재값보다 낮은 값이 많은 것들을 찾아나가는 간단한 문제 </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[15654. N과 M(5)]]></title>
            <link>https://velog.io/@youngjin_kim2/15654.-N%EA%B3%BC-M5</link>
            <guid>https://velog.io/@youngjin_kim2/15654.-N%EA%B3%BC-M5</guid>
            <pubDate>Fri, 02 Jul 2021 00:33:29 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">from itertools import permutations

N,M = list(map(int,input().split()))

num_list = list(map(int,input().split()))

num_list.sort()

result = list(permutations(num_list,M))

result_set = set(result)
result = list(result_set)
result.sort()
for tmp in result:
   tmp_string = &quot;&quot;
   for i in range(len(tmp)):
       tmp_string+=str(tmp[i])+&quot; &quot;

   print(tmp_string)
</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>순열을 물어보는 문제 </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[2751. 수 정렬하기2]]></title>
            <link>https://velog.io/@youngjin_kim2/2751.-%EC%88%98-%EC%A0%95%EB%A0%AC%ED%95%98%EA%B8%B02</link>
            <guid>https://velog.io/@youngjin_kim2/2751.-%EC%88%98-%EC%A0%95%EB%A0%AC%ED%95%98%EA%B8%B02</guid>
            <pubDate>Thu, 01 Jul 2021 23:35:49 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-링크">문제 링크</h2>
<p><a href="https://www.acmicpc.net/problem/2751">2751. 수 정렬하기2</a></p>
<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">import sys
N = int(input())

num_list = []
for i in range(N):

    num = int(sys.stdin.readline())
    num_list.append(num)

num_list.sort()

for i in range(N):
    sys.stdout.write(str(num_list[i])+&#39;\n&#39;)</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>단순히 int(input()), print() 로 하니 시간 초과</li>
<li>할께 많을땐 sys를 쓰자 </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[1525. 퍼즐]]></title>
            <link>https://velog.io/@youngjin_kim2/1525.-%ED%8D%BC%EC%A6%90</link>
            <guid>https://velog.io/@youngjin_kim2/1525.-%ED%8D%BC%EC%A6%90</guid>
            <pubDate>Thu, 01 Jul 2021 06:18:00 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-링크">문제 링크</h2>
<p><a href="https://www.acmicpc.net/problem/1525">1525. 퍼즐</a></p>
<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">from collections import deque
import copy

answer = &quot;123456780&quot;
graph = &quot;&quot;

for i in range(3):
    num_list = list(map(int,input().split()))
    for j in range(3):
        graph+=str(num_list[j])

visited_graph_list =set(graph)

que = deque()

que.append((graph,0))

print_idx = 0
result = -1
while len(que)&gt;0:
    tmp_graph,count = que.popleft()

    if tmp_graph == answer:
        result = count
        break

    blank = tmp_graph.find(&#39;0&#39;)

    dp = [-1,1,-3,3]

    for i in range(4):
        if (i == 0 and blank in [3,6]) or (i ==1 and blank in [2,5]):
            continue

        next_pos = blank+dp[i]

        if 0&lt;=next_pos&lt;9:
            new_graph=&quot;&quot;
            for j in range(9):
                if j == blank:
                    new_graph+=tmp_graph[next_pos]
                elif j == next_pos:
                    new_graph+=tmp_graph[blank]
                else:
                    new_graph+=tmp_graph[j]
            #print(new_graph)

            if new_graph not in visited_graph_list:
                que.append((new_graph,count+1))
                visited_graph_list.add(new_graph)
print(result)</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>처음에는 3*3 이차원배열로 풀려고 했다. </li>
<li>visited 비교하는데에 너무나 많은 시간이 걸림</li>
<li>문자열로 바꿔서 수행하고, 3 &lt;-&gt;4 , 6&lt;-&gt;7 swap 안하도록 조건 걸어줌 </li>
<li>que에 리스트 형태로 넣는것보다 set으로 넣는게 훨씬 시간 단축 해줌 </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[1449. 수리공 항승 ]]></title>
            <link>https://velog.io/@youngjin_kim2/1449.-%EC%88%98%EB%A6%AC%EA%B3%B5-%ED%95%AD%EC%8A%B9</link>
            <guid>https://velog.io/@youngjin_kim2/1449.-%EC%88%98%EB%A6%AC%EA%B3%B5-%ED%95%AD%EC%8A%B9</guid>
            <pubDate>Wed, 30 Jun 2021 13:58:52 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-링크">문제 링크</h2>
<p><a href="https://www.acmicpc.net/problem/1449">1449. 수리공 항승 </a></p>
<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">hole_num, length= list(map(int,input().split()))


hole_list = list(map(int,input().split()))

hole_list.sort()

now_tape = 0
count = 0
while len(hole_list)&gt;0:
    new_hole = hole_list.pop(0)

    if new_hole+0.5 &lt;= now_tape:
        continue

    now_tape = new_hole-0.5+length
    count +=1

print(count)</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>어차피 모든 구멍은 막아야한다. </li>
<li>가장 작은 구멍에서 부터 시작해서 -0.5인 위치에 테이프를 붙인다.</li>
<li>다음 구멍+0.5의 위치보다 테이프의 길이가 더 길면, 해당 구멍은 막힌거라고 생각할 수 있다. </li>
<li>다음 구멍이 안막히면 그 구멍의 -0.5의 위치에서 다시 테이프를 붙인다. </li>
<li>모든 구멍이 막힐때 까지 반복 </li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[17163. 색종이 붙이기]]></title>
            <link>https://velog.io/@youngjin_kim2/17163.-%EC%83%89%EC%A2%85%EC%9D%B4-%EB%B6%99%EC%9D%B4%EA%B8%B0</link>
            <guid>https://velog.io/@youngjin_kim2/17163.-%EC%83%89%EC%A2%85%EC%9D%B4-%EB%B6%99%EC%9D%B4%EA%B8%B0</guid>
            <pubDate>Wed, 30 Jun 2021 11:12:55 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-링크">문제 링크</h2>
<p><a href="https://www.acmicpc.net/problem/17136">17163. 색종이 붙이기</a></p>
<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">def paper(idx,count):
    global min_count,result

    if count &gt;= min_count:
        return
    #print_paper()

    if idx == len(one_list):
        min_count = min(min_count,count)
        return

    i, j = one_list[idx]

    if graph[i][j] == 0:
        paper(idx+1,count)
        return

    for size in range(5,0,-1):
        checker = True
        if i+size &lt; 11 and j+size &lt;11:
            for x in range(i,i+size):
                for y in range(j,j+size):
                    if graph[x][y] == 0:
                        checker = False
            if checker and paper_list[size-1]&gt;0:
                for x in range(i, i + size):
                    for y in range(j, j + size):
                        graph[x][y] = 0
                paper_list[size - 1] -= 1
                #print_paper()
                paper(idx+1,count+1)
                for x in range(i, i + size):
                    for y in range(j, j + size):
                        graph[x][y] = 1
                paper_list[size - 1] += 1


graph = [[0 for row in range(10)]for col in range(10)]
one_list = []
for i in range(10):
    num_list = list(map(int,input().split()))

    for j in range(10):
        graph[i][j] = num_list[j]
        if num_list[j] == 1:
            one_list.append([i,j])


paper_list = [5,5,5,5,5]
count = 0
result = 0
min_count = 26

paper(0,0)


if min_count == 26:
    print(-1)
else:
    print(min_count)</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li><p>처음 시도</p>
<ul>
<li>5*5짜리 종이를 붙이고 붙인 부분을 0으로 만들어서 몇개 붙이는지 확인해봄</li>
<li>5개가 넘는 종이를 붙이면 -1 출력</li>
</ul>
</li>
<li><p>시도 2</p>
<ul>
<li>예시 1번을 넣었을때 답이 4가 나와야 하나, 5*5부터 붙이므로 -1을 리턴하는것을 확인</li>
<li>5<em>5부터 붙여보고 안되면 4</em>4 3*3 순으로 내려가면서 붙여보도록 함 </li>
<li>가장 min을 찾아야 하므로 모든 케이스를 다해보고 가장 적은 종이를 붙이는 걸 출력하도록 함</li>
</ul>
</li>
<li><p>시도 3</p>
<ul>
<li>예시 2번을 넣었을때 답이 5가 나와야 하나, 지금 기준으로는 5*5를 만족하는 답이 그래프 상에 있으면 바로 붙여버림 </li>
<li>전부 다 붙이도록 해봐야함 </li>
</ul>
</li>
<li><p>시도 4 </p>
<ul>
<li>백트래킹으로 전환함</li>
<li>입력받을때 1이 위치하는 위치를 기록하도록 함 </li>
<li>백트래킹을 돌때 인덱스를 통해서 돌도록 함 </li>
</ul>
</li>
</ul>
<h2 id="추가-예시">추가 예시</h2>
<blockquote>
<p>예시 1번
0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 0 0 0
0 1 1 1 1 1 1 0 0 0
0 1 1 1 1 1 1 0 0 0
0 1 1 1 1 1 1 0 0 0
0 1 1 1 1 1 1 0 0 0
0 1 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
answer : 4 
예시 2번
1 1 1 1 1 1 1 0 0 0
1 1 1 1 1 1 1 0 0 0
1 1 1 1 1 1 1 0 0 0
1 1 1 1 1 1 1 0 0 0
1 1 1 1 1 1 1 0 0 0
1 1 1 1 1 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
answer : 5</p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[13305. 주유소 ]]></title>
            <link>https://velog.io/@youngjin_kim2/13305.-%EC%A3%BC%EC%9C%A0%EC%86%8C</link>
            <guid>https://velog.io/@youngjin_kim2/13305.-%EC%A3%BC%EC%9C%A0%EC%86%8C</guid>
            <pubDate>Wed, 30 Jun 2021 00:25:07 GMT</pubDate>
            <description><![CDATA[<h2 id="문제-링크">문제 링크</h2>
<p><a href="https://www.acmicpc.net/problem/13305">13305. 주유소</a></p>
<h2 id="문제-코드">문제 코드</h2>
<pre><code class="language-python">node = int(input())

road_list = list(map(int,input().split()))

price_list = list(map(int,input().split()))

total_price = 0

now_price = price_list[0]
for i in range(len(road_list)):
    total_price+=road_list[i]*now_price

    if now_price &gt; price_list[i+1]:
        now_price = price_list[i+1]

print(total_price)</code></pre>
<h2 id="문제-풀이">문제 풀이</h2>
<ul>
<li>현재까지 가장 가격이 저렴한 기름값으로 계속 간다. </li>
<li>새로운 노드에 갈때마다 가격 비교해서 업데이트 </li>
</ul>
]]></description>
        </item>
    </channel>
</rss>