diff --git "a/Limchaeyoung/[BOJ] \354\210\230 \353\254\266\352\270\260.py" "b/Limchaeyoung/[BOJ] \354\210\230 \353\254\266\352\270\260.py" new file mode 100644 index 0000000..533c95e --- /dev/null +++ "b/Limchaeyoung/[BOJ] \354\210\230 \353\254\266\352\270\260.py" @@ -0,0 +1,38 @@ +# https://www.acmicpc.net/problem/1744 +n = int(input()) +data = [int(input()) for i in range(n)] +data.sort(reverse=True) +idx, sum, num = len(data), 0, 0 + +for i, d in enumerate(data): + if d < 1: + idx = i + break + +data1, data2 = data[:idx], data[idx:] +data2.reverse() + +if data1: + for i, d in enumerate(data1): + if d == 1: + sum += 1 + continue + if i % 2 == 0: + num = d + else: + num *= d + sum += num + num = 0 + if num != 0: sum += num +if data2: + for i, d in enumerate(data2): + if i % 2 == 0: + num = d + else: + num *= d + sum += num + num = 0 + if num != 0: sum += num + +print(sum) + diff --git "a/Limchaeyoung/[BOJ] \354\210\250\353\260\224\352\274\255\354\247\210 3.py" "b/Limchaeyoung/[BOJ] \354\210\250\353\260\224\352\274\255\354\247\210 3.py" new file mode 100644 index 0000000..f750433 --- /dev/null +++ "b/Limchaeyoung/[BOJ] \354\210\250\353\260\224\352\274\255\354\247\210 3.py" @@ -0,0 +1,30 @@ +# https://www.acmicpc.net/status?user_id=hea_c&problem_id=13549&from_mine=1 +from collections import deque + +n, k = map(int, input().split()) +sec = [-1] * 100001 +s = [2, -1, 1] + +def bfs(n): + queue = deque([n]) + sec[n] = 0 + while queue: + q = queue.popleft() + for i in s: + if i == 2: + tp = 1 + x = q * 2 + else: + tp = 0 + x = q + i + if 0 <= x <= 100000 and sec[x] == -1: + if tp: + queue.append(x) + sec[x] = sec[q] + else: + queue.append(x) + sec[x] = sec[q]+1 + if x == k: + return sec[x] + +print(bfs(n)) \ No newline at end of file diff --git "a/Limchaeyoung/[BOJ] \354\210\250\353\260\224\352\274\255\354\247\210.py" "b/Limchaeyoung/[BOJ] \354\210\250\353\260\224\352\274\255\354\247\210.py" new file mode 100644 index 0000000..af71228 --- /dev/null +++ "b/Limchaeyoung/[BOJ] \354\210\250\353\260\224\352\274\255\354\247\210.py" @@ -0,0 +1,21 @@ +# https://www.acmicpc.net/problem/1697 +from collections import deque + +n, k = map(int, input().split()) +sec = [-1] * 100001 +s = [-1,1,2] + +def bfs(n): + queue = deque([n]) + sec[n] = 0 + while queue: + q = queue.popleft() + for i in s: + x = q * 2 if i == 2 else q + i + if 0 <= x <= 100000 and sec[x] == -1: + queue.append(x) + sec[x] = sec[q] + 1 + if x == k: + return sec[x] + +print(bfs(n)) \ No newline at end of file diff --git "a/Limchaeyoung/[BOJ] \354\236\203\354\226\264\353\262\204\353\246\260 \352\264\204\355\230\270.py" "b/Limchaeyoung/[BOJ] \354\236\203\354\226\264\353\262\204\353\246\260 \352\264\204\355\230\270.py" new file mode 100644 index 0000000..94736f9 --- /dev/null +++ "b/Limchaeyoung/[BOJ] \354\236\203\354\226\264\353\262\204\353\246\260 \352\264\204\355\230\270.py" @@ -0,0 +1,11 @@ +# https://www.acmicpc.net/problem/1541 +st = input().split('-') +num = [] +for s in st: + n = 0 + ii = s.split('+') + for i in ii: + n += int(i) + num.append(n) +answer = num[0] * 2 - sum(num) +print(answer) \ No newline at end of file diff --git "a/Limchaeyoung/[PGS] \353\204\244\355\212\270\354\233\214\355\201\254.py" "b/Limchaeyoung/[PGS] \353\204\244\355\212\270\354\233\214\355\201\254.py" new file mode 100644 index 0000000..60b0baf --- /dev/null +++ "b/Limchaeyoung/[PGS] \353\204\244\355\212\270\354\233\214\355\201\254.py" @@ -0,0 +1,15 @@ +# https://school.programmers.co.kr/learn/courses/30/lessons/43162# +def dfs(graph, visited, v): + visited[v] = True + for i in range(len(graph[v])): + if not visited[i] and graph[v][i]: + dfs(graph, visited, i) + +def solution(n, computers): + cnt = 0 + visited = [False] * n + for i in range(n): + if not visited[i]: + cnt += 1 + dfs(computers, visited, i) + return cnt \ No newline at end of file diff --git "a/Limchaeyoung/[PGS] \353\213\250\354\206\215\354\271\264\353\251\224\353\235\274.py" "b/Limchaeyoung/[PGS] \353\213\250\354\206\215\354\271\264\353\251\224\353\235\274.py" new file mode 100644 index 0000000..f2555f8 --- /dev/null +++ "b/Limchaeyoung/[PGS] \353\213\250\354\206\215\354\271\264\353\251\224\353\235\274.py" @@ -0,0 +1,13 @@ +# https://school.programmers.co.kr/learn/courses/30/lessons/42884 +def solution(routes): + routes = sorted(routes, key=lambda x: (x[1], x[0])) + k = routes[0][1] + print(routes) + cnt = 1 + for i in range(1, len(routes)): + if routes[i][0] <= k <= routes[i][0]: + continue + else: + cnt += 1 + k = routes[i][1] + return cnt \ No newline at end of file diff --git "a/Limchaeyoung/[PGS] \353\262\240\354\212\244\355\212\270 \354\225\250\353\262\224.py" "b/Limchaeyoung/[PGS] \353\262\240\354\212\244\355\212\270 \354\225\250\353\262\224.py" new file mode 100644 index 0000000..3b67fe7 --- /dev/null +++ "b/Limchaeyoung/[PGS] \353\262\240\354\212\244\355\212\270 \354\225\250\353\262\224.py" @@ -0,0 +1,22 @@ +# https://school.programmers.co.kr/learn/courses/30/lessons/42579 +def solution(genres, plays): + data = {} + cnt = {} + answer = [] + for i in range(len(genres)): + if genres[i] in data: + d = data[genres[i]] + d.append((i, plays[i])) + data[genres[i]] = d + cnt[genres[i]] += plays[i] + else: + data[genres[i]] = [(i, plays[i])] + cnt[genres[i]] = plays[i] + for i in data: + data[i] = sorted(data[i], key=lambda x: (-x[1], x[0])) + cnt = dict(sorted(cnt.items(), key=lambda x: -x[1])) + for c in cnt: + answer.append(data[c][0][0]) + if len(data[c]) > 1: + answer.append(data[c][1][0]) + return answer \ No newline at end of file diff --git "a/Limchaeyoung/[PGS] \354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" "b/Limchaeyoung/[PGS] \354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" new file mode 100644 index 0000000..4d526ab --- /dev/null +++ "b/Limchaeyoung/[PGS] \354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" @@ -0,0 +1,10 @@ +# https://school.programmers.co.kr/learn/courses/30/lessons/42577 +def solution(phone_book): + pre = dict() + for p in phone_book: + for i in range(1, len(p)): + pre[p[:i]] = 1 + for p in phone_book: + if p in pre: + return False + return True \ No newline at end of file diff --git "a/Limchaeyoung/[PGS] \354\271\264\355\216\253.py" "b/Limchaeyoung/[PGS] \354\271\264\355\216\253.py" new file mode 100644 index 0000000..c3992b5 --- /dev/null +++ "b/Limchaeyoung/[PGS] \354\271\264\355\216\253.py" @@ -0,0 +1,11 @@ +# https://school.programmers.co.kr/learn/courses/30/lessons/42842 +def solution(brown, yellow): + s = 0 + for i in range(1, int(yellow**0.5)+1): + if yellow % i == 0: + y = yellow // i + b = (y + 2) * (i + 2) - yellow + if b == brown: + s = y + break + return [s+2, yellow//s+2] \ No newline at end of file