diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index fc773fb..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 4bc3d2a..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.vscode - -HanTaegyu/.idea \ No newline at end of file diff --git "a/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/17352/17352.py" "b/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/17352/17352.py" deleted file mode 100644 index 731528e..0000000 --- "a/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/17352/17352.py" +++ /dev/null @@ -1,46 +0,0 @@ -""" - Solution code for "BaekJoon 여러분의 다리가 되어 드리겠습니다!". - - - Problem link: https://www.acmicpc.net/problem/17352 - - 입력 - - 섬의 개수 : (2 ≤ N ≤ 300,000) - - 다리의 개수 : N - 2 - - 출력 - - 연결해야하는 1개의 다리 -""" -from sys import stdin as input -# input = open('./test4.txt') - -island_count = int(input.readline()) -parent = [i for i in range(island_count + 1)] - - -def find(node: int) -> int: - if parent[node] == node: - return parent[node] - - parent[node] = find(parent[node]) - return parent[node] - - -def union(node1: int, node2: int) -> None: - parent1, parent2 = find(node1), find(node2) - if parent1 > parent2: - parent[parent1] = parent[parent2] - else: - parent[parent2] = parent[parent1] - - -def main() -> None: - for _ in range(island_count - 2): - node1, node2 = map(int, input.readline().split()) - union(node1, node2) - - answer = {find(parent[node]) for node in range(1, len(parent))} - print(*answer) - - -if __name__ == '__main__': - main() \ No newline at end of file diff --git "a/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/17352/test1.txt" "b/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/17352/test1.txt" deleted file mode 100644 index 1df7fea..0000000 --- "a/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/17352/test1.txt" +++ /dev/null @@ -1,4 +0,0 @@ -5 -1 2 -2 3 -4 5 \ No newline at end of file diff --git "a/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/17352/test2.txt" "b/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/17352/test2.txt" deleted file mode 100644 index d8263ee..0000000 --- "a/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/17352/test2.txt" +++ /dev/null @@ -1 +0,0 @@ -2 \ No newline at end of file diff --git "a/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/17352/test3.txt" "b/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/17352/test3.txt" deleted file mode 100644 index 1df7fea..0000000 --- "a/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/17352/test3.txt" +++ /dev/null @@ -1,4 +0,0 @@ -5 -1 2 -2 3 -4 5 \ No newline at end of file diff --git "a/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/1744/1744.py" "b/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/1744/1744.py" deleted file mode 100644 index e7f93f1..0000000 --- "a/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/1744/1744.py" +++ /dev/null @@ -1,66 +0,0 @@ -""" - Solution code for "BaekJoon 수 묶기". - - - Problem link: https://www.acmicpc.net/problem/1744 - - 입력 - - N : (1 <= N <= 49) - - N개의 수 : (-1_000 ~ +1_000) - - 출력 - 총합을 출력 - -""" -from sys import stdin as input -from typing import List - -# input = open('./test1.txt') - -plus = [] -other = [] - - -def tie(data: List[int], answer: int) -> int: - while 1 < len(data): - num1, num2 = data.pop(), data.pop() - answer += max(num1 + num2, num1 * num2) - return answer - - -def remain_number() -> None: - if other: - if plus: - return plus.pop() + other.pop() - else: - return other.pop() - else: - if plus: - return plus.pop() - else: - return 0 - - -def main() -> None: - N = int(input.readline()) - for _ in range(N): - num = int(input.readline()) - - if 0 < num: - plus.append(num) - else: - other.append(num) - - answer = 0 - - plus.sort() - answer = tie(plus, answer) - - other.sort(reverse=True) - answer = tie(other, answer) - - answer += remain_number() - print(answer, end="") - - -if __name__ == '__main__': - main() \ No newline at end of file diff --git "a/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/1744/test1.txt" "b/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/1744/test1.txt" deleted file mode 100644 index 06add6e..0000000 --- "a/HanTaegyu/8\354\233\2243\354\243\274\354\260\250/1744/test1.txt" +++ /dev/null @@ -1,12 +0,0 @@ -11 -5 -4 -3 -2 -1 -0 --1 --2 --3 --4 --5 \ No newline at end of file diff --git a/HanTaegyu/README.md b/HanTaegyu/README.md deleted file mode 100644 index 21959ab..0000000 --- a/HanTaegyu/README.md +++ /dev/null @@ -1 +0,0 @@ -# 코딩테스트 연습 정리집 \ No newline at end of file diff --git "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/.DS_Store" "b/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/.DS_Store" deleted file mode 100644 index 5008ddf..0000000 Binary files "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/.DS_Store" and /dev/null differ diff --git "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/.cph/.\352\262\275\354\237\201\354\240\201_\354\240\204\354\227\274.py_de013fe5f7f1228181fcfdb3b1c2a52f.prob" "b/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/.cph/.\352\262\275\354\237\201\354\240\201_\354\240\204\354\227\274.py_de013fe5f7f1228181fcfdb3b1c2a52f.prob" deleted file mode 100644 index e5947c0..0000000 --- "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/.cph/.\352\262\275\354\237\201\354\240\201_\354\240\204\354\227\274.py_de013fe5f7f1228181fcfdb3b1c2a52f.prob" +++ /dev/null @@ -1 +0,0 @@ -{"name":"Local: 경쟁적_전염","url":"/Users/cycrpto/Desktop/BOJ/_study_ps/ParkJunHa/9월 4주차/경쟁적_전염.py","tests":[{"id":1695047341238,"input":"3 3\n1 0 2\n0 0 0\n3 0 0\n2 3 2","output":"3"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"/Users/cycrpto/Desktop/BOJ/_study_ps/ParkJunHa/9월 4주차/경쟁적_전염.py","group":"local","local":true} \ No newline at end of file diff --git "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/.cph/.\354\206\214\354\210\230\354\235\230_\354\227\260\354\206\215\355\225\251.py_ce2afa4000ff32f725fd2475ba7c9a95.prob" "b/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/.cph/.\354\206\214\354\210\230\354\235\230_\354\227\260\354\206\215\355\225\251.py_ce2afa4000ff32f725fd2475ba7c9a95.prob" deleted file mode 100644 index cd9cc5c..0000000 --- "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/.cph/.\354\206\214\354\210\230\354\235\230_\354\227\260\354\206\215\355\225\251.py_ce2afa4000ff32f725fd2475ba7c9a95.prob" +++ /dev/null @@ -1 +0,0 @@ -{"name":"소수의 연속합","group":"Baekjoon Online Judge","url":"https://www.acmicpc.net/problem/1644#","interactive":false,"memoryLimit":128,"timeLimit":2000,"tests":[{"input":"20","output":"0","id":1695031357071},{"input":"3\n","output":"1\n","id":1695031357016},{"input":"41\n","output":"3\n","id":1695031357008},{"id":1695031357080,"input":"53","output":"2"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"Task"}},"batch":{"id":"ae856268-1eec-4e8e-bcc8-28f79093169f","size":1},"srcPath":"/Users/cycrpto/Desktop/BOJ/_study_ps/ParkJunHa/9월 4주차/소수의_연속합.py"} \ No newline at end of file diff --git "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\352\260\220\354\213\234_\355\224\274\355\225\230\352\270\260.py" "b/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\352\260\220\354\213\234_\355\224\274\355\225\230\352\270\260.py" deleted file mode 100644 index 1cd385b..0000000 --- "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\352\260\220\354\213\234_\355\224\274\355\225\230\352\270\260.py" +++ /dev/null @@ -1,59 +0,0 @@ -import sys -from collections import deque -input = sys.stdin.readline - -n = int(input()) -graph = [list(input().split()) for _ in range(n)] -is_possible = False - -# T : 선생님 -# S : 학생 -# O : 장애물 -# X : 빈공간 -def obstacle(k=3): - global is_possible, graph - if k == 0: - import pprint - # pprint.pprint(graph) - if bfs(): - is_possible = True - # print("=============================") - return - - for i in range(n): - for j in range(n): - if graph[i][j] == 'X': - graph[i][j] = 'O' - obstacle(k-1) - graph[i][j] = 'X' - - - -def bfs(): - from copy import deepcopy - g = deepcopy(graph) - q = deque() - for i in range(n): - for j in range(n): - if g[i][j] == 'T': - q.append([i, j]) - - dx, dy = [-1, 1, 0, 0], [0, 0, -1, 1] - while q: - # print(graph) - # print() - cx, cy = q.pop() - for i in range(4): - nx, ny = cx + dx[i], cy + dy[i] - while nx in range(n) and ny in range(n): - if graph[nx][ny] == 'O': - break - if graph[nx][ny] == 'S': - return False - nx, ny = nx + dx[i], ny + dy[i] - - return True - - -obstacle() -print("YES" if is_possible else "NO") \ No newline at end of file diff --git "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\352\260\225\354\235\230\354\213\244_\353\260\260\354\240\225.py" "b/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\352\260\225\354\235\230\354\213\244_\353\260\260\354\240\225.py" deleted file mode 100644 index 7cf530d..0000000 --- "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\352\260\225\354\235\230\354\213\244_\353\260\260\354\240\225.py" +++ /dev/null @@ -1,18 +0,0 @@ -import heapq - -n = int(input()) -timeline = list(list(map(int, input().split())) for _ in range(n)) -timeline.sort() - -pq = [] -heapq.heappush(pq, timeline[0][1]) - -for i in range(1, n): - if timeline[i][0] < pq[0]: - heapq.heappush(pq, timeline[i][1]) - - else: - heapq.heappop(pq) - heapq.heappush(pq, timeline[i][1]) - -print(len(pq)) \ No newline at end of file diff --git "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\352\262\275\354\237\201\354\240\201_\354\240\204\354\227\274.py" "b/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\352\262\275\354\237\201\354\240\201_\354\240\204\354\227\274.py" deleted file mode 100644 index 7f25504..0000000 --- "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\352\262\275\354\237\201\354\240\201_\354\240\204\354\227\274.py" +++ /dev/null @@ -1,29 +0,0 @@ -from collections import deque -n, k = map(int, input().split()) -graph = [list(map(int, input().split())) for _ in range(n)] -time, x, y = map(int, input().split()) -q = deque() - -for i in range(1, k+1): - for col in range(n): - for row in range(n): - if graph[col][row] == i: - q.append([col, row, 0]) - -dx, dy = [1, -1, 0, 0], [0, 0, 1, -1] - -while q: - cx, cy, t = q.popleft() - if t == time: - continue - - for i in range(4): - nx, ny = cx + dx[i], cy + dy[i] - if nx in range(n) and ny in range(n) and graph[nx][ny] == 0: - q.append([nx, ny, t+1]) - graph[nx][ny] = graph[cx][cy] - - -print(graph[x - 1][y - 1]) - -print() \ No newline at end of file diff --git "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\354\206\214\354\210\230\354\235\230_\354\227\260\354\206\215\355\225\251.py" "b/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\354\206\214\354\210\230\354\235\230_\354\227\260\354\206\215\355\225\251.py" deleted file mode 100644 index 0021fc4..0000000 --- "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\354\206\214\354\210\230\354\235\230_\354\227\260\354\206\215\355\225\251.py" +++ /dev/null @@ -1,56 +0,0 @@ -# 에라토스테네스의 채 -# import math -# n = 0 -# is_prime = [1 for _ in range(n+1)] -# is_prime[0], is_prime[1] = 0, 0 - -# for i in range(2, int(math.sqrt(n) + 1)): -# if is_prime[i]: -# for j in range(2, n // i+1): -# is_prime[i*j] = 0 - -import sys -import math - -sys.setrecursionlimit(10 ** 8) -input = lambda: sys.stdin.readline().rstrip() - -n = int(input()) -if n == 1: - print(0) - exit() - -# 2 3 5 7 11 13 17 19 23 29 31 37 ... -# 4,000,000 == 2000^2 -MAX = 4000000 -is_prime = [1 for _ in range(n + 1)] -is_prime[0], is_prime[1] = 0, 0 - -for i in range(2, int(math.sqrt(n)) + 1): - if is_prime[i]: - for j in range(2, n // i + 1): - is_prime[i * j] = 0 # 소수의 배수들은 다 소수가 아니므로 0으로 만듦 - -p = [] -for i in range(2, n + 1): - if is_prime[i]: - p.append(i) - -cnt = 0 -i, j = len(p) - 1, len(p) - 1 -cur = p[-1] -while 0 <= i <= j and 0 <= j < len(p): - if cur > n: - cur -= p[j] - j -= 1 - - else: - if cur == n: - cnt += 1 - i -= 1 - if i < 0: - break - cur += p[i] - - -print(cnt) \ No newline at end of file diff --git "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\354\244\204\354\204\270\354\232\260\352\270\260.py" "b/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\354\244\204\354\204\270\354\232\260\352\270\260.py" deleted file mode 100644 index 0f2478c..0000000 --- "a/ParkJunHa/9\354\233\224 4\354\243\274\354\260\250/\354\244\204\354\204\270\354\232\260\352\270\260.py" +++ /dev/null @@ -1,14 +0,0 @@ -from bisect import bisect_left -res = [-1] -s = list() -for i in range(k:=int(input())): - s.append(int(input())) - -for i in range(k): - if s[i] < res[-1]: - res[bisect_left(res, s[i])] = s[i] - - else: - res.append(s[i]) - -print(k - (len(res) - 1)) \ No newline at end of file diff --git "a/ParkJunHa/9\354\233\224 5\354\243\274\354\260\250/\353\252\251\354\236\245_\352\261\264\354\204\244\355\225\230\352\270\260.py" "b/ParkJunHa/9\354\233\224 5\354\243\274\354\260\250/\353\252\251\354\236\245_\352\261\264\354\204\244\355\225\230\352\270\260.py" deleted file mode 100644 index 0c1842a..0000000 --- "a/ParkJunHa/9\354\233\224 5\354\243\274\354\260\250/\353\252\251\354\236\245_\352\261\264\354\204\244\355\225\230\352\270\260.py" +++ /dev/null @@ -1,29 +0,0 @@ -M, N = map(int, input().split()) -matrix = [] -for _ in range(M): - row = list(map(int, input().split())) - matrix.append(row) - -# 다이나믹 프로그래밍 배열 초기화 -dp = [[-1] * N for _ in range(M)] - -# 재귀 함수를 사용하여 가장 큰 정사각형의 한 변의 길이를 계산 -def findLargestSquare(x, y): - if x < 0 or y < 0: - return 0 - if matrix[x][y] == 0: - if dp[x][y] == -1: - top = findLargestSquare(x-1, y) - left = findLargestSquare(x, y-1) - topLeft = findLargestSquare(x-1, y-1) - dp[x][y] = min(top, left, topLeft) + 1 - return dp[x][y] - return 0 - -L = 0 -for i in range(M): - for j in range(N): - if matrix[i][j] == 0: - L = max(L, findLargestSquare(i, j)) - -print(L) \ No newline at end of file diff --git "a/ParkJunHa/note/11000-\352\260\225\354\235\230\354\213\244 \353\260\260\354\240\225.md" "b/ParkJunHa/note/11000-\352\260\225\354\235\230\354\213\244 \353\260\260\354\240\225.md" deleted file mode 100644 index d37f9b5..0000000 --- "a/ParkJunHa/note/11000-\352\260\225\354\235\230\354\213\244 \353\260\260\354\240\225.md" +++ /dev/null @@ -1,51 +0,0 @@ - - -### 풀이 -#### 아이디어 -회의실 예약? 암튼 그런 문제랑 비슷하게 끝나는 시간대로 정렬한 뒤 세는 문제인줄 알았다. -문제 이해를 잘 못해서 이상한 방법으로 풀었는데, 겹쳐도 상관없다! 강의실을 여러개 빌리면 되니까.. - -강의 시간이 끝나고나서 들어오는 수업은 그대로 강의실을 사용하면 되지만 만약 그렇지 않다면 새로운 강의실을 빌려야 한다. - -이 과정에서 시간 문제 때문에 우선순위 큐를 사용하게 된다. 이 자료구조를 써먹어 본 경험이 적어서 애를 먹었고, 문제를 이해 못해서 애를 먹었던 문제 - -#### 코드 -```python -import heapq - - - -n = int(input()) - -timeline = list(list(map(int, input().split())) for _ in range(n)) - -timeline.sort() - - - -pq = [] - -heapq.heappush(pq, timeline[0][1]) - - - -for i in range(1, n): - -if timeline[i][0] < pq[0]: - -heapq.heappush(pq, timeline[i][1]) - -else: - -heapq.heappop(pq) - -heapq.heappush(pq, timeline[i][1]) - - - -print(len(pq)) -``` - ---- -### 회고 -그리디 연습이 적었고, 자료구조 연습이 적었다. 아이디어 도출도 어려웠다. 이번에 공부하는 최단거리 끝나면 그리디를 DP처럼 한번 파보자. \ No newline at end of file diff --git "a/ParkJunHa/note/18405-\352\262\275\354\237\201\354\240\201 \354\240\204\354\227\274.md" "b/ParkJunHa/note/18405-\352\262\275\354\237\201\354\240\201 \354\240\204\354\227\274.md" deleted file mode 100644 index 7026885..0000000 --- "a/ParkJunHa/note/18405-\352\262\275\354\237\201\354\240\201 \354\240\204\354\227\274.md" +++ /dev/null @@ -1,63 +0,0 @@ - -### 풀이 -#### 아이디어 -기본적인 그래프탐색에서 visit대신 그래프 자체 업데이트를 사용해도 됨 -하지만 큐에 집어넣는 데이터에 지난 시간까지 표시한다. - -#### 코드 -```python -from collections import deque - -n, k = map(int, input().split()) - -graph = [list(map(int, input().split())) for _ in range(n)] - -time, x, y = map(int, input().split()) - -q = deque() - - - -for i in range(1, k+1): - -for col in range(n): - -for row in range(n): - -if graph[col][row] == i: - -q.append([col, row, 0]) - - - -dx, dy = [1, -1, 0, 0], [0, 0, 1, -1] - - - -while q: - -cx, cy, t = q.popleft() - -if t == time: - -continue - - - -for i in range(4): - -nx, ny = cx + dx[i], cy + dy[i] - -if nx in range(n) and ny in range(n) and graph[nx][ny] == 0: - -q.append([nx, ny, t+1]) - -graph[nx][ny] = graph[cx][cy] - -print(graph[x - 1][y - 1]) - -``` - -### 회고 -쓸데없는 부분을 놓쳐서 시간을 허비한 문제.. -시간복잡도를 개선하기 위해서는 우선순위 큐를 사용하는 방법도 있으나, 파이썬으로도 돌아가는걸 보니 일단은 괜찮다. \ No newline at end of file diff --git "a/ParkJunHa/note/18428-\352\260\220\354\213\234 \355\224\274\355\225\230\352\270\260.md" "b/ParkJunHa/note/18428-\352\260\220\354\213\234 \355\224\274\355\225\230\352\270\260.md" deleted file mode 100644 index fbc8e3a..0000000 --- "a/ParkJunHa/note/18428-\352\260\220\354\213\234 \355\224\274\355\225\230\352\270\260.md" +++ /dev/null @@ -1,128 +0,0 @@ -### 풀이 -#### 아이디어 - -1. 선생님이 볼 수 있는 구간을 모두 큐에 넣는다. -2. 그 구간에 학생이 걸린다면 바로 이전 칸에 장애물을 넣는다. -3. 만약 장애물을 모두 썼다면 피할 수 없음. (나머지 큐를 모두 돌아봄.) - -그러면 선생 2명이 학생을 하나 바라보는 경우 반례 가능성 - - -1. 장애물을 설치한다 (백트래킹으로 모든 곳에 3개씩) -2. 설치가 끝나면 선생님 위치에서 학생이 보이는지 bfs탐색 -3. 만약 탐색에 성공했다면 True리턴 - - -```python -import sys - -from collections import deque - -input = sys.stdin.readline - - - -n = int(input()) - -graph = [list(input().split()) for _ in range(n)] - -is_possible = False - - - -# T : 선생님 - -# S : 학생 - -# O : 장애물 - -# X : 빈공간 - -def obstacle(k=3): - -global is_possible, graph - -if k == 0: - -import pprint - -# pprint.pprint(graph) - -if bfs(): - -is_possible = True - -# print("=============================") - -return - - - -for i in range(n): - -for j in range(n): - -if graph[i][j] == 'X': - -graph[i][j] = 'O' - -obstacle(k-1) - -graph[i][j] = 'X' - - - - -def bfs(): - -from copy import deepcopy - -g = deepcopy(graph) - -q = deque() - -for i in range(n): - -for j in range(n): - -if g[i][j] == 'T': - -q.append([i, j]) - - - -dx, dy = [-1, 1, 0, 0], [0, 0, -1, 1] - -while q: - -# print(graph) - -# print() - -cx, cy = q.pop() - -for i in range(4): - -nx, ny = cx + dx[i], cy + dy[i] - -while nx in range(n) and ny in range(n): - -if graph[nx][ny] == 'O': - -break - -if graph[nx][ny] == 'S': - -return False - -nx, ny = nx + dx[i], ny + dy[i] - -return True - - - - -obstacle() - -print("YES" if is_possible else "NO") -``` \ No newline at end of file diff --git "a/ParkJunHa/note/2631-\354\244\204\354\204\270\354\232\260\352\270\260.md" "b/ParkJunHa/note/2631-\354\244\204\354\204\270\354\232\260\352\270\260.md" deleted file mode 100644 index 24d5121..0000000 --- "a/ParkJunHa/note/2631-\354\244\204\354\204\270\354\232\260\352\270\260.md" +++ /dev/null @@ -1,56 +0,0 @@ ---- -platform: BOJ -tags: - - dp -difficulty: g4 -스터디 문제: true -week-date: - - 9월 - - 4주차 ---- - -### 풀이 - -#### 아이디어 -문제를 읽으면서 직접 아이들을 옮기는 과정을 따라가다보니 맨 처음 생각했던 것은 인덱스와 아이 번호가 같지 않은것들만 옮기면 된다. 라는 생각을 하게 되었었다. 하지만 아이를 빼서 옮기는 과정에 인덱스 번호가 전체적으로 달라지게되고, 그러면 너무 복잡하므로 다른 아이디어를 떠올렸다. - -위 과정을 따라가다보니 우선 오름차순으로 정렬된다 라는것이 생각났고, 설마 LIS인가? 라는 생각이 들어 최장 증가 부분수열을 제외한 나머지를 확인해보았다. 그랬더니 최장 증가부분수열이 아닌 나머지들이 움직인다는 것을보고 이 아이디어를 쓰기로 하였다. - -코드는 아래와 같다. LI를 구하는 알고리즘으로는 $O(n \log n)$ 방식을 이용하였다. (제일 간단하다고 느끼기 때문..) - -#### 코드 - -```python -from bisect import bisect_left - -res = [-1] - -s = list() - -for i in range(k:=int(input())): - -s.append(int(input())) - - - -for i in range(k): - -if s[i] < res[-1]: - -res[bisect_left(res, s[i])] = s[i] - -else: - -res.append(s[i]) - - - -print(k - (len(res) - 1)) - - -``` - ---- - -### 회고 -별 테크닉 없이 금방 풀이한 문제. \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 5dc789c..0000000 --- a/README.md +++ /dev/null @@ -1,66 +0,0 @@ -# 🚀 python_codingTest - -- **활동기간** : 2023.04.13 ~ -- **언어** : Python -- **문제출처** : [백준](https://www.acmicpc.net/), [프로그래머스](https://school.programmers.co.kr/learn/challenges?order=recent&page=1) - -### 목표 -- 백준 플레티넘 -- 코테 합격 -- 카카오 문제 다 풀기 -- 하반기 취뽀하기🔥 - ---- - -### 🤼‍♀️ 진행 방식 -#### 스터디 준비사항 -1. 각자 문제 3개씩 정해오기(스터디 전까지) - - 난이도 : - - 백준 :골드2 ~ 5, 실버1 ~ 2 - - 프로그래머스 : 레벨2,3 - -2. 월,목 각 3개씩 지정 - - 안 풀어본 문제를 우선함 - -#### 스터디 진행 -1. 자신이 가지고 온 문제 풀이 - - 못 풀거나, 다른 풀이가 있을 경우 다른 사람이 풀이 -2. 다른 사람의 코드 리뷰(최소 한명) - -### 👨‍👨‍👧‍👧 스터디 인원 - -[@easyhoon](https://github.com/easyhooon), [@JUNYOUNG31](https://github.com/JUNYOUNG31), [@jihyuk](https://github.com/hyukji), [@Cycrypto](https://github.com/Cycrypto) - -### 👨‍👨‍👧‍👧 past member -[@baekeunsun](https://github.com/baekeunsun), [@makie082](https://github.com/makie082), [@mildsalmon](https://github.com/mildsalmon), [@ksyint](https://github.com/ksyint), [@rappire](https://github.com/rappire), [@Taegyu](https://github.com/TaegyuHan) - - -### 📑 문제 리스트 -| 날짜 | 문제 | -| :---- | :------------------: | -| 4월 3주차 |[주사위](https://www.acmicpc.net/problem/1041), [펠린드롬?](https://www.acmicpc.net/problem/10942) / [빗물](https://www.acmicpc.net/problem/14719), [퇴사2](https://www.acmicpc.net/problem/15486),[이모티콘 할인행사](https://school.programmers.co.kr/learn/courses/30/lessons/150368) | -| 4월 4주차 |[퍼즐조각채우기](https://school.programmers.co.kr/learn/courses/30/lessons/84021), [플로이드](https://www.acmicpc.net/problem/11404), [문자열 폭발](https://www.acmicpc.net/problem/9935) / [토마토](https://www.acmicpc.net/problem/7576), [Dance Dance Revolution](https://www.acmicpc.net/problem/2342), [트리](https://www.acmicpc.net/problem/1068)| -| 5월 1주차 |[영훈이의 색칠공부](https://www.acmicpc.net/problem/14578), [거짓말](https://www.acmicpc.net/problem/1043), [피리 부는 사나이](https://www.acmicpc.net/problem/16724) / [호텔](https://www.acmicpc.net/problem/1106), [보석 도둑](https://www.acmicpc.net/problem/1202), [우체국](https://www.acmicpc.net/problem/2141)| -| 5월 2주차 |[물병](https://www.acmicpc.net/problem/1052), [카드섞기](https://www.acmicpc.net/problem/1091), [외벽점검](https://school.programmers.co.kr/learn/courses/30/lessons/60062) / [가지 산사태](https://www.acmicpc.net/problem/27940), [파괴되지않은 건물](https://school.programmers.co.kr/learn/courses/30/lessons/92344), [곡예비행](https://www.acmicpc.net/problem/21923)| -| 5월 3주차 |[암호 만들기](https://www.acmicpc.net/problem/1759), [벽 부수고 이동하기 4](https://www.acmicpc.net/problem/16946), [숫자 야구](https://www.acmicpc.net/problem/2503) / [개똥벌레](https://www.acmicpc.net/problem/3020), [택배 배달과 수거하기](https://school.programmers.co.kr/learn/courses/30/lessons/150369), [2+1 세일](https://www.acmicpc.net/problem/11508)| -| 5월 4주차 |[순위검색](https://school.programmers.co.kr/learn/courses/30/lessons/72412), [신규 아이디 추천](https://school.programmers.co.kr/learn/courses/30/lessons/72410), [행운의 문자열](https://www.acmicpc.net/problem/1342) / [기둥과 보 설치](https://school.programmers.co.kr/learn/courses/30/lessons/60061), [도로의 개수](https://www.acmicpc.net/problem/1577), [꽃길](https://www.acmicpc.net/problem/14620)| -| 5월 5주차 |[양과 늑대](https://school.programmers.co.kr/learn/courses/30/lessons/92343), [체스판 다시 칠하기 2](https://www.acmicpc.net/problem/25682), [행복 유치원](https://www.acmicpc.net/problem/13164) / [벽 부수고 이동하기 3](https://www.acmicpc.net/problem/16933), [센서](https://www.acmicpc.net/problem/2212), [신기한 소수](https://www.acmicpc.net/problem/2023)| -| 6월 2주차 |[RGB 거리](https://www.acmicpc.net/problem/1149), [뮤탈리스크](https://www.acmicpc.net/problem/12869), [벽 타기](https://www.acmicpc.net/problem/23563) / [죽음의 비](https://www.acmicpc.net/problem/22944), [아이들과 선물 상자](https://www.acmicpc.net/problem/23757), [여행](https://www.acmicpc.net/problem/2157)| -| 6월 3주차 |[길찾기 게임](https://school.programmers.co.kr/learn/courses/30/lessons/42892), [코딩 테스트 공부](https://school.programmers.co.kr/learn/courses/30/lessons/118668), [양궁대회](https://school.programmers.co.kr/learn/courses/30/lessons/92342) / [거리두기 확인하기](https://school.programmers.co.kr/learn/courses/30/lessons/81302), [Two Dots](https://www.acmicpc.net/problem/16929), [치킨배달](https://www.acmicpc.net/problem/15686) -| 6월 4주차 |[조 짜기](https://www.acmicpc.net/problem/2229),[문자열과 점수](https://www.acmicpc.net/problem/2216),[표 병합](https://school.programmers.co.kr/learn/courses/30/lessons/150366) / [주차 요금 계산](https://school.programmers.co.kr/learn/courses/30/lessons/92341),[보석 쇼핑](https://school.programmers.co.kr/learn/courses/30/lessons/67258),[음악프로그램](https://www.acmicpc.net/problem/2623) -| 6월 5주차 |[잠수함식별](https://www.acmicpc.net/problem/2671), [트리의 지름](https://www.acmicpc.net/problem/1167),[매칭 점수](https://school.programmers.co.kr/learn/courses/30/lessons/42893)/[무인도 여행](https://school.programmers.co.kr/learn/courses/30/lessons/154540),[괄호 제거](https://www.acmicpc.net/problem/2800),[두 배열의 합](https://www.acmicpc.net/problem/2143) -| 7월 1주차 |[개인정보 수집 유효기간](https://school.programmers.co.kr/learn/courses/30/lessons/150370),[꿀따기](https://www.acmicpc.net/problem/21758),[빛의 경로 사이클](https://school.programmers.co.kr/learn/courses/30/lessons/86052)/[이중우선순위큐](https://school.programmers.co.kr/learn/courses/30/lessons/42628),[다리 만들기](https://www.acmicpc.net/problem/2146),[파이프 옮기기1](https://www.acmicpc.net/problem/17070) -| 7월 2주차 |[사이클 게임](https://www.acmicpc.net/problem/20040),[다단계 칫솔 판매](https://school.programmers.co.kr/learn/courses/30/lessons/77486),[별자리 만들기](https://www.acmicpc.net/problem/4386)/[등산코스 정하기](https://school.programmers.co.kr/learn/courses/30/lessons/118669),[자물쇠와 열쇠](https://school.programmers.co.kr/learn/courses/30/lessons/60059),[정육점](https://www.acmicpc.net/problem/2258) -| 7월 3주차 |[내려가기](https://www.acmicpc.net/problem/2096),[알파벳](https://www.acmicpc.net/problem/1987),[전화번호 목록](https://school.programmers.co.kr/learn/courses/30/lessons/42577)/[학부 연구생 민상](https://www.acmicpc.net/problem/21922),[통나무 건너뛰기](https://www.acmicpc.net/problem/11497),[표현 가능한 이진트리](https://school.programmers.co.kr/learn/courses/30/lessons/150367) -| 7월 4주차 |[연구소3](https://www.acmicpc.net/problem/17142),[이진 검색 트리](https://www.acmicpc.net/problem/5639),[최소직사각형](https://school.programmers.co.kr/learn/courses/30/lessons/86491)/[뒤집기3](https://www.acmicpc.net/problem/1464),[최소비용 구하기2](https://www.acmicpc.net/problem/11779),[소수 찾기](https://school.programmers.co.kr/learn/courses/30/lessons/42839) -| 8월 1주차 |[가장 큰 정사각형](https://www.acmicpc.net/problem/1915),[소형기관차](https://www.acmicpc.net/problem/2616),[미세먼지 안녕!](https://www.acmicpc.net/problem/17144)/[캐슬 디펜스](https://www.acmicpc.net/problem/17135), [⚾](https://www.acmicpc.net/problem/17281), [숨바꼭질2](https://www.acmicpc.net/problem/12851) -| 8월 3주차 |[LCS 2](https://www.acmicpc.net/problem/9252),[게리맨더링 2](https://www.acmicpc.net/problem/17779),[어두운 건 무서워](https://www.acmicpc.net/problem/16507)/[여러분의 다리가 되어 드리겠습니다!](https://www.acmicpc.net/problem/17352), [수 묶기](https://www.acmicpc.net/problem/1744), [새로운 게임 2](https://www.acmicpc.net/problem/17837) -| 8월 4주차 |[원판 돌리기](https://www.acmicpc.net/problem/17822),[할로윈의 양아치](https://www.acmicpc.net/problem/20303),[스도쿠](https://www.acmicpc.net/problem/2239)/[이모티콘](https://www.acmicpc.net/problem/14226), [전구와 스위치](https://www.acmicpc.net/problem/2138), [주사위 윷놀이](https://www.acmicpc.net/problem/17825) -| 8월 5주차 |[가스관](https://www.acmicpc.net/problem/2931),[빙산](https://www.acmicpc.net/problem/2573),[마법사 상어와 파이어볼](https://www.acmicpc.net/problem/20056)/[두 로봇](https://www.acmicpc.net/problem/15971), [괄호 추가하기](https://www.acmicpc.net/problem/16637), [매직 스타](https://www.acmicpc.net/problem/3967) -| 9월 2주차 | [매직 스타](https://www.acmicpc.net/problem/3967),[마법사 상어와 토네이도](https://www.acmicpc.net/problem/20057),[색상환](https://www.acmicpc.net/problem/2482)/[양 구출 작전](https://www.acmicpc.net/problem/16437), [카드 정렬하기](https://www.acmicpc.net/problem/1715), [색종이-3](https://www.acmicpc.net/problem/2571) -| 9월 3주차 | [양 구출 작전](https://www.acmicpc.net/problem/16437), [카드 정렬하기](https://www.acmicpc.net/problem/1715), [색종이-3](https://www.acmicpc.net/problem/2571)/[마법사 상어와 복제](https://www.acmicpc.net/problem/23290) -| 9월 4주차 | [줄세우기](https://www.acmicpc.net/problem/2631), [강의실 배정](https://www.acmicpc.net/problem/11000), [소수의 연속합](https://www.acmicpc.net/problem/1644)/[감시 피하기](https://www.acmicpc.net/problem/18428), [사회망 서비스(SNS)](https://www.acmicpc.net/problem/2533), [경쟁적 전염](https://www.acmicpc.net/problem/18405) -| 9월 5주차 | [목장 건설하기](https://www.acmicpc.net/problem/14925), [키 순서](https://www.acmicpc.net/problem/2458), [신기한 키보드](https://www.acmicpc.net/problem/1796)/-추석 연휴- -| 10월 1주차 | -추석 연휴-/[숨바꼭질 4](https://www.acmicpc.net/problem/13913), [행렬 곱셈 순서](https://www.acmicpc.net/problem/11049), [미로 만들기](https://www.acmicpc.net/problem/2665) -| 10월 2주차 | [빗물](https://www.acmicpc.net/problem/14719), [회전 초밥](https://www.acmicpc.net/problem/15961), [가르침](https://www.acmicpc.net/problem/1062)/[금민수의 합](https://www.acmicpc.net/problem/1528), [동전 분배](https://www.acmicpc.net/problem/1943), [모음사전](https://school.programmers.co.kr/learn/courses/30/lessons/84512) -| 10월 3주차 | /[백조의 호수](https://www.acmicpc.net/problem/3197), [문제집](https://www.acmicpc.net/problem/1766), [크게 만들기](https://www.acmicpc.net/problem/2812) diff --git "a/Rappire/4\354\233\2243\354\243\274\354\260\250/1041.py" "b/Rappire/4\354\233\2243\354\243\274\354\260\250/1041.py" deleted file mode 100644 index 20ed0b0..0000000 --- "a/Rappire/4\354\233\2243\354\243\274\354\260\250/1041.py" +++ /dev/null @@ -1,52 +0,0 @@ -import sys - -input = sys.stdin.readline - -num = int(input()) -arr = list(map(int, input().split())) - -if num == 1: - print(sum(arr) - max(arr)) - sys.exit() - -min_1 = min(arr) - -# 양쪽 면중 하나가 선택되니, 작은것 선택! -checklist_2 = [ - [0, 1], - [0, 2], - [0, 3], - [0, 4], - [1, 2], - [2, 4], - [4, 3], - [3, 1], - [5, 1], - [5, 2], - [5, 3], - [5, 4], -] -checklist_3 = [ - [0, 1, 2], - [0, 2, 4], - [0, 4, 3], - [0, 3, 1], - [5, 1, 2], - [5, 2, 4], - [5, 4, 3], - [5, 3, 1], -] -min_2 = 1000 -for i, j in checklist_2: - if min_2 > arr[i] + arr[j]: - min_2 = arr[i] + arr[j] -min_3 = 1000 -for i, j, k in checklist_3: - if min_3 > arr[i] + arr[j] + arr[k]: - min_3 = arr[i] + arr[j] + arr[k] -total_num = num * num * num -min_2_num = 8 * num - 12 -min_3_num = 4 -min_1_num = 5 * num * num - 16 * num + 12 -num_sum = min_1_num * min_1 + min_2_num * min_2 + min_3_num * min_3 -print(num_sum) diff --git "a/Rappire/4\354\233\2243\354\243\274\354\260\250/10942.py" "b/Rappire/4\354\233\2243\354\243\274\354\260\250/10942.py" deleted file mode 100644 index b228a12..0000000 --- "a/Rappire/4\354\233\2243\354\243\274\354\260\250/10942.py" +++ /dev/null @@ -1,25 +0,0 @@ -import sys - -input = sys.stdin.readline - -num = int(input()) -arr = list(map(int, input().split())) -dp = [[0 for i in range(num)] for i in range(num)] - - -# 1개, 2개 고려하면 쉽게 풀수 있음 -for i in range(num): - for j in range(num - i): - if arr[j] == arr[j + i]: - if j == j + i: - dp[j][j + i] = 1 - elif j + 1 > j + i - 1: - dp[j][j + i] = 1 - else: - dp[j][j + i] = dp[j + 1][j + i - 1] - - -num = int(input()) -for i in range(num): - S, E = map(int, input().split()) - print(dp[S - 1][E - 1]) diff --git "a/Rappire/4\354\233\2243\354\243\274\354\260\250/14719.py" "b/Rappire/4\354\233\2243\354\243\274\354\260\250/14719.py" deleted file mode 100644 index a2ea320..0000000 --- "a/Rappire/4\354\233\2243\354\243\274\354\260\250/14719.py" +++ /dev/null @@ -1,39 +0,0 @@ -import sys - -input = sys.stdin.readline -H, W = map(int, input().split()) -arr = list(map(int, input().split())) - -leftMax = -1 -count = 0 -sumNum = 0 -pos = 0 -answer = 0 - -for i, height in enumerate(arr): - if leftMax <= height: - answer += count * leftMax - sumNum - leftMax = height - count = 0 - sumNum = 0 - pos = i - else: - count += 1 - sumNum += height - -if pos < W - 1: - leftMax = -1 - count = 0 - sumNum = 0 - for i in range(W - 1, pos - 1, -1): - height = arr[i] - if leftMax <= height: - answer += count * leftMax - sumNum - leftMax = height - count = 0 - sumNum = 0 - else: - count += 1 - sumNum += height - -print(answer) diff --git "a/Rappire/4\354\233\2243\354\243\274\354\260\250/15486.py" "b/Rappire/4\354\233\2243\354\243\274\354\260\250/15486.py" deleted file mode 100644 index bc2de8f..0000000 --- "a/Rappire/4\354\233\2243\354\243\274\354\260\250/15486.py" +++ /dev/null @@ -1,17 +0,0 @@ -import sys - -input = sys.stdin.readline -day = int(input()) -Week = [0 for i in range(day + 1)] - - -now = 0 -for i in range(day): - T, P = map(int, input().split()) - finish = T + i - now = max(Week[i], now) - if finish > day: - continue - Week[finish] = max(now + P, Week[finish]) - -print(max(Week[-1], now)) diff --git "a/Rappire/4\354\233\2243\354\243\274\354\260\250/\354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.py" "b/Rappire/4\354\233\2243\354\243\274\354\260\250/\354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.py" deleted file mode 100644 index b6649a6..0000000 --- "a/Rappire/4\354\233\2243\354\243\274\354\260\250/\354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.py" +++ /dev/null @@ -1,39 +0,0 @@ -discount = [0.1, 0.2, 0.3, 0.4] - - -def solution(users, emoticons): - global length - global best - # 가입자, 판매액 - best = [0, 0] - length = len(emoticons) - check([], users, emoticons) - return best - - -def check(arr, users, emoticons): - if len(arr) < length: - for i in range(4): - arr.append(discount[i]) - check(arr, users, emoticons) - arr.pop() - else: - total_purchase = 0 - emoticon_user = 0 - for percent, total in users: - purchase = 0 - flag = True - for dis, price in zip(arr, emoticons): - if int(dis * 100) >= percent: - purchase += price * (1 - dis) - if purchase >= total: - emoticon_user += 1 - flag = False - break - if flag: - total_purchase += purchase - if best[0] < emoticon_user: - best[0] = emoticon_user - best[1] = total_purchase - elif best[0] == emoticon_user and best[1] < total_purchase: - best[1] = total_purchase diff --git "a/Rappire/4\354\233\2244\354\243\274\354\260\250/1068.py" "b/Rappire/4\354\233\2244\354\243\274\354\260\250/1068.py" deleted file mode 100644 index 3a8e309..0000000 --- "a/Rappire/4\354\233\2244\354\243\274\354\260\250/1068.py" +++ /dev/null @@ -1,24 +0,0 @@ -import sys - -input = sys.stdin.readline - -N = int(input()) -parent = list(map(int, input().split())) -K = int(input()) - -parent[K] = -2 -stack = [K] -while len(stack) > 0: - now = stack.pop() - parent[now] = -2 - for pos, i in enumerate(parent): - if i == now: - stack.append(pos) - -parent_set = set(parent) -count = 0 -for pos, i in enumerate(parent): - if i != -2 and pos not in parent_set: - count += 1 - -print(count) diff --git "a/Rappire/4\354\233\2244\354\243\274\354\260\250/11404.py" "b/Rappire/4\354\233\2244\354\243\274\354\260\250/11404.py" deleted file mode 100644 index 18d3828..0000000 --- "a/Rappire/4\354\233\2244\354\243\274\354\260\250/11404.py" +++ /dev/null @@ -1,29 +0,0 @@ -import sys - -input = sys.stdin.readline - -N = int(input()) -M = int(input()) -inf = 10e7 -arr = [[inf for _ in range(N)] for _ in range(N)] - -for i in range(N): - arr[i][i] = 0 - -for i in range(M): - start, end, cost = map(int, input().split()) - arr[start - 1][end - 1] = min(cost, arr[start - 1][end - 1]) - -for i in range(N): - for a in range(N): - for b in range(N): - arr[a][b] = min(arr[a][b], arr[a][i] + arr[i][b]) - - -for i in range(N): - for j in range(N): - if arr[i][j] == inf: - print(0, end=" ") - else: - print(arr[i][j], end=" ") - print() diff --git "a/Rappire/4\354\233\2244\354\243\274\354\260\250/2342.py" "b/Rappire/4\354\233\2244\354\243\274\354\260\250/2342.py" deleted file mode 100644 index a1aac1c..0000000 --- "a/Rappire/4\354\233\2244\354\243\274\354\260\250/2342.py" +++ /dev/null @@ -1,41 +0,0 @@ -import sys - - -def cost(pos, last): - if last == 0: - return 2 - calc = abs(pos - last) - if calc == 2: - return 4 - elif calc == 0: - return 1 - return 3 - - -# 1=>3 -# 2=>4 -# 처음에는 2 -# 차이가 2나면 4, 아니면 3, 같은거 1 -input = sys.stdin.readline -arr = list(map(int, input().split())) -arr.pop() -maxNum = int(10e8) -lastdp = [[maxNum for _ in range(5)] for _ in range(5)] -dp = [[maxNum for _ in range(5)] for _ in range(5)] -lastdp[0][0] = 0 - -for now in arr: - for left in range(5): - for right in range(5): - dp[now][right] = min(dp[now][right], lastdp[left][right] + cost(now, left)) - dp[left][now] = min(dp[left][now], lastdp[left][right] + cost(now, right)) - - lastdp, dp = dp, lastdp - for i in range(5): - for j in range(5): - dp[i][j] = maxNum - -minnum = maxNum -for line in lastdp: - minnum = min(min(line), minnum) -print(minnum) diff --git "a/Rappire/4\354\233\2244\354\243\274\354\260\250/7576.py" "b/Rappire/4\354\233\2244\354\243\274\354\260\250/7576.py" deleted file mode 100644 index fc82c06..0000000 --- "a/Rappire/4\354\233\2244\354\243\274\354\260\250/7576.py" +++ /dev/null @@ -1,46 +0,0 @@ -import sys -from collections import deque - -input = sys.stdin.readline - -move = [[1, 0], [-1, 0], [0, 1], [0, -1]] - - -M, N = map(int, input().split()) -count_arr = [[0 for _ in range(M)] for _ in range(N)] -arr = [] - -for i in range(N): - arr.append(list(map(int, input().split()))) -queue = deque([]) -for i in range(N): - for j in range(M): - if arr[i][j] == 1: - queue.append([i, j, 1]) - - -while len(queue) > 0: - now = queue.popleft() - x, y, num = now - for dx, dy in move: - dx += x - dy += y - if dx >= 0 and dx < N and dy >= 0 and dy < M: - if arr[dx][dy] == 0: - queue.append([dx, dy, num + 1]) - arr[dx][dy] = num + 1 - # 필요 없었던 코드 - # elif arr[dx][dy] == -1: - # pass - # elif arr[dx][dy] > num + 1: - # queue.append([dx, dy, num + 1]) - # arr[dx][dy] = num + 1 - -maxnum = -1 -for line in arr: - for i in line: - if i == 0: - print(-1) - sys.exit() - maxnum = max(maxnum, i) -print(maxnum - 1) diff --git "a/Rappire/4\354\233\2244\354\243\274\354\260\250/9935.py" "b/Rappire/4\354\233\2244\354\243\274\354\260\250/9935.py" deleted file mode 100644 index f60c6c4..0000000 --- "a/Rappire/4\354\233\2244\354\243\274\354\260\250/9935.py" +++ /dev/null @@ -1,33 +0,0 @@ -import sys - -input = sys.stdin.readline - - -def check(): - pos = -1 - while 1: - try: - if stack[pos] != boom[pos]: - return False - except Exception: - if pos == -length - 1: - return True - return False - pos -= 1 - - -str = input().rstrip() -boom = input().rstrip() -length = len(boom) -stack = [] -for i in str: - stack.append(i) - if check(): - for _ in range(length): - stack.pop() - - -if len(stack) == 0: - print("FRULA") -else: - print("".join(stack)) diff --git "a/Rappire/4\354\233\2244\354\243\274\354\260\250/\355\215\274\354\246\220 \354\241\260\352\260\201 \354\261\204\354\232\260\352\270\260.py" "b/Rappire/4\354\233\2244\354\243\274\354\260\250/\355\215\274\354\246\220 \354\241\260\352\260\201 \354\261\204\354\232\260\352\270\260.py" deleted file mode 100644 index d789abb..0000000 --- "a/Rappire/4\354\233\2244\354\243\274\354\260\250/\355\215\274\354\246\220 \354\241\260\352\260\201 \354\261\204\354\232\260\352\270\260.py" +++ /dev/null @@ -1,141 +0,0 @@ -def solution(game_board, table): - puzzlelist = findPuzzle(table) - emptylist = findEmpty(game_board) - answer = 0 - for i in emptylist: - for pos, j in enumerate(puzzlelist): - if checkSpin(i, j): - answer += sumpuzzle(j) - puzzlelist.pop(pos) - break - return answer - - -def sumpuzzle(puzzle): - count = 0 - for i in puzzle: - for j in i: - if j == 1: - count += 1 - return count - - -def movecheck(x, y, length): - move = [[1, 0], [-1, 0], [0, 1], [0, -1]] - arr = [] - for i in move: - if i[0] + x >= 0 and i[0] + x < length: - if i[1] + y >= 0 and i[1] + y < length: - arr.append([i[0] + x, i[1] + y]) - return arr - - -def checksame(puzzle, empty, puzzlelen): - for x in range(puzzlelen[0]): - for y in range(puzzlelen[1]): - if puzzle[x][y] != empty[x][y]: - return False - return True - - -def checkSpin(puzzle, empty): - puzzlelen = [len(puzzle), len(puzzle[0])] - emptylen = [len(empty), len(empty[0])] - if emptylen[0] != puzzlelen[0] or emptylen[1] != puzzlelen[1]: - if emptylen[0] != puzzlelen[1] or emptylen[1] != puzzlelen[0]: - return False - for i in range(4): - puzzlelen[0] = len(puzzle) - puzzlelen[1] = len(puzzle[0]) - if emptylen[0] != puzzlelen[0] or emptylen[1] != puzzlelen[1]: - puzzle = spin(puzzle) - continue - if checksame(puzzle, empty, puzzlelen): - return True - puzzle = spin(puzzle) - return False - - -def spin(puzzle): - n = len(puzzle) - m = len(puzzle[0]) - new = [[0] * n for i in range(m)] - for i in range(n): - for j in range(m): - new[j][n - i - 1] = puzzle[i][j] - return new - - -def findEmpty(game_board): - length = len(game_board) - check = [[0 for i in range(length)] for i in range(length)] - puzzlelist = [] - for i in range(length): - for j in range(length): - if check[i][j] == 1: - continue - if game_board[i][j] == 1: - check[i][j] = 1 - continue - puzzle = [] - stack = [[i, j]] - while len(stack) > 0: - now = stack.pop() - if check[now[0]][now[1]]: - continue - check[now[0]][now[1]] = 1 - puzzle.append(now) - nextmove = movecheck(now[0], now[1], length) - for move in nextmove: - if check[move[0]][move[1]] == 0: - if game_board[move[0]][move[1]] == 0: - stack.append(move) - puzzlelist.append(reguler(puzzle)) - return puzzlelist - - -def reguler(puzzle): - maxl = [-1, -1] - minl = [55, 55] - for i in puzzle: - maxl[0] = max(i[0], maxl[0]) - maxl[1] = max(i[1], maxl[1]) - minl[0] = min(i[0], minl[0]) - minl[1] = min(i[1], minl[1]) - arr = [ - [0 for i in range(maxl[1] - minl[1] + 1)] for i in range(maxl[0] - minl[0] + 1) - ] - for i in puzzle: - x = i[0] - minl[0] - y = i[1] - minl[1] - arr[x][y] = 1 - return arr - - -def findPuzzle(table): - length = len(table) - check = [[0 for i in range(length)] for i in range(length)] - puzzlelist = [] - - for i in range(length): - for j in range(length): - if check[i][j] == 1: - continue - if table[i][j] == 0: - check[i][j] = 1 - continue - puzzle = [] - stack = [[i, j]] - while len(stack) > 0: - now = stack.pop() - if check[now[0]][now[1]]: - continue - check[now[0]][now[1]] = 1 - puzzle.append(now) - nextmove = movecheck(now[0], now[1], length) - for move in nextmove: - if check[move[0]][move[1]] == 0: - if table[move[0]][move[1]] == 1: - stack.append(move) - puzzlelist.append(reguler(puzzle)) - return puzzlelist diff --git "a/Rappire/5\354\233\224 1\354\243\274\354\260\250/1106.py" "b/Rappire/5\354\233\224 1\354\243\274\354\260\250/1106.py" deleted file mode 100644 index 95e1d65..0000000 --- "a/Rappire/5\354\233\224 1\354\243\274\354\260\250/1106.py" +++ /dev/null @@ -1,19 +0,0 @@ -import sys - -input = sys.stdin.readline -C, N = map(int, input().split()) -arr = [] -maxint = int(10e10) -dp = [maxint for _ in range(C + 1)] -dp[0] = 0 -for i in range(N): - arr.append(list(map(int, input().split()))) - -for i in range(C + 1): - for cost, j in arr: - now = i + j - if now > C: - now = C - dp[now] = min(dp[now], dp[i] + cost) - -print(dp[-1]) diff --git "a/Rappire/5\354\233\224 1\354\243\274\354\260\250/1202.py" "b/Rappire/5\354\233\224 1\354\243\274\354\260\250/1202.py" deleted file mode 100644 index b896e1c..0000000 --- "a/Rappire/5\354\233\224 1\354\243\274\354\260\250/1202.py" +++ /dev/null @@ -1,28 +0,0 @@ -import sys -from heapq import heappush, heappop - -input = sys.stdin.readline -N, K = map(int, input().split()) - -jewels = [] -for i in range(N): - jewels.append(list(map(int, input().split()))) - -knaps = [] -for i in range(K): - knaps.append(int(input())) - -knaps.sort() -jewels.sort() -result = 0 -jewelsQueue = [] -pos = 0 -for knap in knaps: - while pos < len(jewels) and knap >= jewels[pos][0]: - heappush(jewelsQueue, -jewels[pos][1]) - pos += 1 - - if len(jewelsQueue) > 0: - result -= heappop(jewelsQueue) - -print(result) diff --git "a/Rappire/5\354\233\224 1\354\243\274\354\260\250/2141.py" "b/Rappire/5\354\233\224 1\354\243\274\354\260\250/2141.py" deleted file mode 100644 index 82b0fb4..0000000 --- "a/Rappire/5\354\233\224 1\354\243\274\354\260\250/2141.py" +++ /dev/null @@ -1,22 +0,0 @@ -import sys - -input = sys.stdin.readline -N = int(input()) -villages = [] -humanSum = 0 - -for i in range(N): - X, A = map(int, input().split()) - villages.append([X, A]) - - humanSum += A - -villages.sort() -humanSum /= 2 - -check = 0 -for village in villages: - check += village[1] - if check >= humanSum: - print(village[0]) - break diff --git "a/Rappire/5\354\233\224 2\354\243\274\354\260\250/1052.py" "b/Rappire/5\354\233\224 2\354\243\274\354\260\250/1052.py" deleted file mode 100644 index 7fcf7e2..0000000 --- "a/Rappire/5\354\233\224 2\354\243\274\354\260\250/1052.py" +++ /dev/null @@ -1,28 +0,0 @@ -import sys -from collections import deque - -input = sys.stdin.readline - -N, K = map(int, input().split()) - -arr = deque([]) -sum = N -size = 1 -while N > 0 and sum > K: - if N % 2 != 0: - arr.append(size) - sum += 1 - sum = sum - N + N // 2 - N //= 2 - size *= 2 - -arr.append(size) -answer = 0 - -pos = 0 -while sum > K and len(arr) > 2: - sum -= 1 - answer += arr[pos + 1] - arr[pos] - arr.popleft() - arr[0] = arr[0] * 2 -print(answer) diff --git "a/Rappire/5\354\233\224 2\354\243\274\354\260\250/1091.py" "b/Rappire/5\354\233\224 2\354\243\274\354\260\250/1091.py" deleted file mode 100644 index 901b8bb..0000000 --- "a/Rappire/5\354\233\224 2\354\243\274\354\260\250/1091.py" +++ /dev/null @@ -1,33 +0,0 @@ -import sys - -input = sys.stdin.readline - -N = int(input()) -arrP = list(map(int, input().split())) -arrS = list(map(int, input().split())) -arr = arrP[:] -count = 0 -while 1: - flag = True - for i in range(len(arr)): - if arr[i] != i % 3: - flag = False - break - if flag: - print(count) - exit() - - temparr = [0 for i in range(N)] - for i, next in enumerate(arrS): - temparr[next] = arr[i] - arr = temparr - flag = True - count += 1 - - for x, y in zip(arrP, arr): - if x != y: - flag = False - break - if flag: - print(-1) - exit() diff --git "a/Rappire/5\354\233\224 2\354\243\274\354\260\250/\354\231\270\353\262\275 \354\240\220\352\262\200.py" "b/Rappire/5\354\233\224 2\354\243\274\354\260\250/\354\231\270\353\262\275 \354\240\220\352\262\200.py" deleted file mode 100644 index 72f08ff..0000000 --- "a/Rappire/5\354\233\224 2\354\243\274\354\260\250/\354\231\270\353\262\275 \354\240\220\352\262\200.py" +++ /dev/null @@ -1,26 +0,0 @@ -from itertools import permutations - - -def solution(n, weaks, dist): - answer = int(10e10) - weakPos = weaks[:] - for i in weaks: - weakPos.append(i + n) - for i, weak in enumerate(weaks): - for friends in permutations(dist): - pos = weak - count = 0 - for friend in friends: - pos += friend - count += 1 - if pos >= weakPos[i + len(weaks) - 1]: - answer = min(answer, count) - break - else: - for next in weakPos: - if next > pos: - pos = next - break - if answer == int(10e10): - return -1 - return answer diff --git "a/Rappire/5\354\233\224 3\354\243\274\354\260\250/11508.py" "b/Rappire/5\354\233\224 3\354\243\274\354\260\250/11508.py" deleted file mode 100644 index 1e7dbba..0000000 --- "a/Rappire/5\354\233\224 3\354\243\274\354\260\250/11508.py" +++ /dev/null @@ -1,19 +0,0 @@ -import sys - -input = sys.stdin.readline - -N = int(input()) - -arr = [] -for i in range(N): - arr.append(int(input())) - -arr.sort(reverse=True) - -answer = 0 - -for i, price in enumerate(arr): - if i % 3 != 2: - answer += price - -print(answer) diff --git "a/Rappire/5\354\233\224 3\354\243\274\354\260\250/3020.py" "b/Rappire/5\354\233\224 3\354\243\274\354\260\250/3020.py" deleted file mode 100644 index 1f44695..0000000 --- "a/Rappire/5\354\233\224 3\354\243\274\354\260\250/3020.py" +++ /dev/null @@ -1,34 +0,0 @@ -import sys -from collections import Counter -from bisect import bisect_left, bisect_right - -input = sys.stdin.readline - -N, H = map(int, input().split()) - -up = [] -down = [] - -for i in range(N): - now = int(input()) - if i % 2 == 1: - # 종유석 - up.append(now) - else: - # 석순 - down.append(now) - -up.sort() -down.sort() - -upLength = len(up) -downLength = len(down) -countMap = [0 for i in range(H)] - -for i in range(H): - countMap[i] += downLength - bisect_right(down, i) - countMap[i] += upLength - bisect_left(up, H - i) - -count = Counter(countMap) -num = min(count) -print(num, count[num]) diff --git "a/Rappire/5\354\233\224 3\354\243\274\354\260\250/\355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\353\212\224 \352\261\264\353\254\274.py" "b/Rappire/5\354\233\224 3\354\243\274\354\260\250/\355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\353\212\224 \352\261\264\353\254\274.py" deleted file mode 100644 index 13a352d..0000000 --- "a/Rappire/5\354\233\224 3\354\243\274\354\260\250/\355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\353\212\224 \352\261\264\353\254\274.py" +++ /dev/null @@ -1,29 +0,0 @@ -def solution(board, skills): - N = len(board) - M = len(board[0]) - sumMap = [[0 for _ in range(M + 1)] for _ in range(N + 1)] - for type, r1, c1, r2, c2, degree in skills: - if type == 1: - degree = -degree - sumMap[r1][c1] += degree - sumMap[r1][c2 + 1] -= degree - sumMap[r2 + 1][c1] -= degree - sumMap[r2 + 1][c2 + 1] += degree - - # 누적합 가로 - for i in range(N): - for j in range(M): - sumMap[i][j + 1] += sumMap[i][j] - - # 누적합 세로 - for j in range(M): - for i in range(N): - sumMap[i + 1][j] += sumMap[i][j] - - answer = 0 - for i in range(N): - for j in range(M): - if board[i][j] + sumMap[i][j] >= 1: - answer += 1 - - return answer diff --git "a/Rappire/5\354\233\224 4\354\243\274\354\260\250/1342.py" "b/Rappire/5\354\233\224 4\354\243\274\354\260\250/1342.py" deleted file mode 100644 index 5a1d6bb..0000000 --- "a/Rappire/5\354\233\224 4\354\243\274\354\260\250/1342.py" +++ /dev/null @@ -1,38 +0,0 @@ -import sys -from math import factorial -from collections import Counter - - -def search(str, strLength): - global count - if strLength == length: - count += 1 - return - flag = True - num = 0 - if len(str) == 0 or countString[str] == 0: - for i in countString.values: - if i == 1: - num += 1 - elif i != 0: - flag = False - break - if flag: - count += factorial(num) - return - for i in countString: - if str != i and countString[i] > 0: - countString[i] -= 1 - search(i, strLength + 1) - countString[i] += 1 - - -input = sys.stdin.readline - -string = input().rstrip() -countString = Counter(string) -length = len(string) -count = 0 - -search("", 0) -print(count) diff --git "a/Rappire/5\354\233\224 4\354\243\274\354\260\250/14620.py" "b/Rappire/5\354\233\224 4\354\243\274\354\260\250/14620.py" deleted file mode 100644 index 3847ac8..0000000 --- "a/Rappire/5\354\233\224 4\354\243\274\354\260\250/14620.py" +++ /dev/null @@ -1,46 +0,0 @@ -import sys - -input = sys.stdin.readline -move = [(-1, 0), (1, 0), (0, -1), (0, 1)] - - -def check(x, y): - if checkArr[x][y] == 1: - return False - for dx, dy in move: - nx = x + dx - ny = y + dy - if checkArr[nx][ny] == 1: - return False - return True - - -def dfs(visitCount, cost): - global answer - if cost >= answer: - return - if visitCount == 3: - answer = min(answer, cost) - else: - for i in range(1, N - 1): - for j in range(1, N - 1): - if check(i, j): - temp_cost = mapArr[i][j] - for di, dj in move: - ni = di + i - nj = dj + j - checkArr[ni][nj] = 1 - temp_cost += mapArr[ni][nj] - dfs(visitCount + 1, cost + temp_cost) - for di, dj in move: - ni = di + i - nj = dj + j - checkArr[ni][nj] = 0 - - -N = int(input()) -answer = int(10e9) -mapArr = [list(map(int, input().split())) for _ in range(N)] -checkArr = [[0 for _ in range(N)] for _ in range(N)] -dfs(0, 0) -print(answer) diff --git "a/Rappire/5\354\233\224 4\354\243\274\354\260\250/1577.py" "b/Rappire/5\354\233\224 4\354\243\274\354\260\250/1577.py" deleted file mode 100644 index 2dd026b..0000000 --- "a/Rappire/5\354\233\224 4\354\243\274\354\260\250/1577.py" +++ /dev/null @@ -1,29 +0,0 @@ -import sys -from collections import defaultdict - -input = sys.stdin.readline - - -def makeHash(startX, startY): - return str(startX) + "," + str(startY) - - -N, M = map(int, input().split()) -K = int(input()) - -road = defaultdict(list) -dp = [[0 for _ in range(M + 2)] for _ in range(N + 2)] -dp[1][1] = 1 -for i in range(K): - startX, startY, endX, endY = list(map(int, input().split())) - road[makeHash(startX + 1, startY + 1)].append([endX + 1, endY + 1]) - road[makeHash(endX + 1, endY + 1)].append([startX + 1, startY + 1]) - -for i in range(1, N + 2): - for j in range(1, M + 2): - if [i, j] not in road[makeHash(i - 1, j)]: - dp[i][j] += dp[i - 1][j] - if [i, j] not in road[makeHash(i, j - 1)]: - dp[i][j] += dp[i][j - 1] - -print(dp[N + 1][M + 1]) diff --git "a/Rappire/5\354\233\224 4\354\243\274\354\260\250/\354\210\234\354\234\204\352\262\200\354\203\211.py" "b/Rappire/5\354\233\224 4\354\243\274\354\260\250/\354\210\234\354\234\204\352\262\200\354\203\211.py" deleted file mode 100644 index 8961032..0000000 --- "a/Rappire/5\354\233\224 4\354\243\274\354\260\250/\354\210\234\354\234\204\352\262\200\354\203\211.py" +++ /dev/null @@ -1,35 +0,0 @@ -from collections import defaultdict -from bisect import bisect_left - - -def solution(infos, queries): - infomap = defaultdict(list) - for info in infos: - for i in range(16): - temp = info.split() - if i & 8 == 8: - temp[0] = "-" - if i & 4 == 4: - temp[1] = "-" - if i & 2 == 2: - temp[2] = "-" - if i & 1 == 1: - temp[3] = "-" - infomap["".join(temp[:-1])].append(int(temp[4])) - print("".join(temp[:-1])) - - for key in infomap.keys(): - infomap[key].sort() - - answer = [] - - for query in queries: - temp = query.split(" and ") - finalTemp = temp[-1].split() - queryString = "".join(temp[:-1]) + finalTemp[0] - answer.append( - len(infomap[queryString]) - - bisect_left(infomap[queryString], int(finalTemp[1])) - ) - - return answer diff --git "a/Rappire/5\354\233\224 4\354\243\274\354\260\250/\354\213\240\352\267\234\354\225\204\354\235\264\353\224\224\354\266\224\354\262\234.py" "b/Rappire/5\354\233\224 4\354\243\274\354\260\250/\354\213\240\352\267\234\354\225\204\354\235\264\353\224\224\354\266\224\354\262\234.py" deleted file mode 100644 index 74f7594..0000000 --- "a/Rappire/5\354\233\224 4\354\243\274\354\260\250/\354\213\240\352\267\234\354\225\204\354\235\264\353\224\224\354\266\224\354\262\234.py" +++ /dev/null @@ -1,23 +0,0 @@ -from re import sub - - -def solution(new_id): - # 1 단계 - new_id = new_id.lower() - # 2 단계 - new_id = sub("[^a-z0-9\-\_\.]", "", new_id) - # 3 단계 - new_id = sub("\.+", ".", new_id) - # 4 단계 - new_id = sub("^\.|\.$", "", new_id) - # 5 단계 - if len(new_id) == 0: - new_id = "a" - # 6 단계 - new_id = new_id[:15] - new_id = sub("\.$", "", new_id) - # 7 단계 - while len(new_id) <= 2: - new_id += new_id[-1] - - return new_id diff --git "a/Rappire/5\354\233\224 5\354\243\274\354\260\250/16933.py" "b/Rappire/5\354\233\224 5\354\243\274\354\260\250/16933.py" deleted file mode 100644 index 3897083..0000000 --- "a/Rappire/5\354\233\224 5\354\243\274\354\260\250/16933.py" +++ /dev/null @@ -1,8 +0,0 @@ -import sys - -input = sys.stdin.readline -N, M, K = map(int, input().split()) -mapArr = [] -for _ in range(N): - mapArr.append(input().split()) -print(mapArr) diff --git "a/Rappire/5\354\233\224 5\354\243\274\354\260\250/2023.py" "b/Rappire/5\354\233\224 5\354\243\274\354\260\250/2023.py" deleted file mode 100644 index 2189cce..0000000 --- "a/Rappire/5\354\233\224 5\354\243\274\354\260\250/2023.py" +++ /dev/null @@ -1,28 +0,0 @@ -import sys - -input = sys.stdin.readline - -N = int(input()) - - -def isPrime(a): - for i in range(2, int(a**0.5) + 1): - if a % i == 0: - return False - return True - - -def dfs(num): - if len(str(num)) == N: - print(num) - else: - for i in range(10): - temp = num * 10 + i - if isPrime(temp): - dfs(temp) - - -dfs(2) -dfs(3) -dfs(5) -dfs(7) diff --git "a/Rappire/5\354\233\224 5\354\243\274\354\260\250/2212.py" "b/Rappire/5\354\233\224 5\354\243\274\354\260\250/2212.py" deleted file mode 100644 index 1d9c142..0000000 --- "a/Rappire/5\354\233\224 5\354\243\274\354\260\250/2212.py" +++ /dev/null @@ -1,21 +0,0 @@ -import sys - -input = sys.stdin.readline - -n = int(input()) -k = int(input()) -sensor = list(map(int, input().split())) -sensor.sort() - -if k >= n: - print(0) - sys.exit() - -calc = [] - -for i in range(n - 1): - calc.append(sensor[i + 1] - sensor[i]) - -calc.sort(reverse=True) -k -= 1 -print(sum(calc[k:])) diff --git "a/Rappire/6\354\233\224 1\354\243\274\354\260\250/1149.py" "b/Rappire/6\354\233\224 1\354\243\274\354\260\250/1149.py" deleted file mode 100644 index f679e8a..0000000 --- "a/Rappire/6\354\233\224 1\354\243\274\354\260\250/1149.py" +++ /dev/null @@ -1,13 +0,0 @@ -import sys - -input = sys.stdin.readline - -N = int(input()) -dp = [[0, 0, 0] for _ in range(N + 1)] -for i in range(1, N + 1): - R, G, B = list(map(int, input().split())) - dp[i][0] = min(dp[i - 1][1], dp[i - 1][2]) + R - dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) + G - dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) + B - -print(min(dp[N])) diff --git "a/Rappire/6\354\233\224 1\354\243\274\354\260\250/12869.py" "b/Rappire/6\354\233\224 1\354\243\274\354\260\250/12869.py" deleted file mode 100644 index 39c2266..0000000 --- "a/Rappire/6\354\233\224 1\354\243\274\354\260\250/12869.py" +++ /dev/null @@ -1,37 +0,0 @@ -import sys -from itertools import permutations - -input = sys.stdin.readline - - -def check(x, y, z, count): - global answer - if x < 0: - x = 0 - if y < 0: - y = 0 - if z < 0: - z = 0 - if x == 0 and y == 0 and z == 0: - answer = min(count, answer) - return - if dp[x][y][z] > count: - dp[x][y][z] = count - for dx, dy, dz in list(permutations([9, 3, 1])): - check(x - dx, y - dy, z - dz, count + 1) - - -N = int(input()) -maxInt = sys.maxsize -dp = [[[maxInt for i in range(61)] for i in range(61)] for i in range(61)] - -scv = list(map(int, input().split())) - -while len(scv) < 3: - scv.append(0) - -x, y, z = scv -answer = maxInt -check(x, y, z, 0) - -print(answer) diff --git "a/Rappire/6\354\233\224 1\354\243\274\354\260\250/22944.py" "b/Rappire/6\354\233\224 1\354\243\274\354\260\250/22944.py" deleted file mode 100644 index ace7131..0000000 --- "a/Rappire/6\354\233\224 1\354\243\274\354\260\250/22944.py" +++ /dev/null @@ -1,48 +0,0 @@ -import sys -from collections import deque - -input = sys.stdin.readline - -move = [[1, 0], [-1, 0], [0, 1], [0, -1]] - - -N, H, D = list(map(int, input().split())) -grid = [] -checklist = [[0 for _ in range(N)] for _ in range(N)] -for i in range(N): - grid.append(list(input().rstrip())) - -for i in range(N): - for j in range(N): - if grid[i][j] == "S": - start = [i, j] - break - -queue = deque([[start[0], start[1], H, 0, 0]]) -while queue: - x, y, hp_b, umbrella_b, count = queue.pop() - for dx, dy in move: - dx += x - dy += y - hp = hp_b - umbrella = umbrella_b - if 0 <= dx < N and 0 <= dy < N: - if grid[dx][dy] == "E": - print(count + 1) - sys.exit() - - if grid[dx][dy] == "U": - umbrella = D - - if umbrella > 0: - umbrella -= 1 - else: - hp -= 1 - if hp == 0: - continue - - if checklist[dx][dy] < hp: - checklist[dx][dy] = hp - queue.appendleft([dx, dy, hp, umbrella, count + 1]) - -print(-1) diff --git "a/Rappire/6\354\233\224 1\354\243\274\354\260\250/23563.py" "b/Rappire/6\354\233\224 1\354\243\274\354\260\250/23563.py" deleted file mode 100644 index 9a4df05..0000000 --- "a/Rappire/6\354\233\224 1\354\243\274\354\260\250/23563.py" +++ /dev/null @@ -1,50 +0,0 @@ -import sys -from collections import deque - - -def moveCheck(x, y): - for dx, dy in move: - dx += x - dy += y - if 0 <= dx < H and 0 <= dy < W: - if mapArr[dx][dy] == "#": - return True - return False - - -input = sys.stdin.readline -move = [[1, 0], [-1, 0], [0, 1], [0, -1]] - -H, W = list(map(int, input().split())) -mapArr = [] -checklist = [[20 for _ in range(W)] for _ in range(H)] - -for _ in range(H): - mapArr.append(list(input().rstrip())) - -for i in range(H): - for j in range(W): - if mapArr[i][j] == "S": - start = [i, j] - break - - -queue = deque([[start[0], start[1], 0]]) -checklist[start[0]][start[1]] = 1 - -while queue: - x, y, count = queue.pop() - nowCheck = moveCheck(x, y) - if mapArr[x][y] == "E": - print(count) - - for dx, dy in move: - dx += x - dy += y - if 0 <= dx < H and 0 <= dy < W: - if checklist[dx][dy] > count and mapArr[dx][dy] != "#": - checklist[dx][dy] = count - if nowCheck and moveCheck(dx, dy): - queue.appendleft([dx, dy, count]) - else: - queue.appendleft([dx, dy, count + 1]) diff --git "a/Rappire/6\354\233\224 1\354\243\274\354\260\250/23757.py" "b/Rappire/6\354\233\224 1\354\243\274\354\260\250/23757.py" deleted file mode 100644 index 4562083..0000000 --- "a/Rappire/6\354\233\224 1\354\243\274\354\260\250/23757.py" +++ /dev/null @@ -1,18 +0,0 @@ -import sys -from heapq import heappop, heappush - -input = sys.stdin.readline -N, M = list(map(int, input().split())) -gift = list(map(int, input().split())) -child = list(map(int, input().split())) -queue = [] -for i in gift: - heappush(queue, -i) - -for i in child: - now = -heappop(queue) - if now < i: - print(0) - sys.exit() - heappush(queue, -now + i) -print(1) diff --git "a/Rappire/6\354\233\224 2\354\243\274\354\260\250/15696.py" "b/Rappire/6\354\233\224 2\354\243\274\354\260\250/15696.py" deleted file mode 100644 index 8e35db6..0000000 --- "a/Rappire/6\354\233\224 2\354\243\274\354\260\250/15696.py" +++ /dev/null @@ -1,29 +0,0 @@ -import sys -from itertools import combinations - -input = sys.stdin.readline - -N, M = list(map(int, input().split())) -mapArr = [list(map(int, input().split())) for _ in range(N)] -chickens = [] -homes = [] -maxint = sys.maxsize -answer = maxint - -for i in range(N): - for j in range(N): - if mapArr[i][j] == 1: - homes.append([i, j]) - elif mapArr[i][j] == 2: - chickens.append([i, j]) - -for chicken in combinations(chickens, M): - total = 0 - for hx, hy in homes: - temp = maxint - for cx, cy in chicken: - temp = min(temp, abs(hx - cx) + abs(hy - cy)) - total += temp - answer = min(answer, total) - -print(answer) diff --git "a/Rappire/6\354\233\224 2\354\243\274\354\260\250/16929.py" "b/Rappire/6\354\233\224 2\354\243\274\354\260\250/16929.py" deleted file mode 100644 index 2e728ee..0000000 --- "a/Rappire/6\354\233\224 2\354\243\274\354\260\250/16929.py" +++ /dev/null @@ -1,35 +0,0 @@ -import sys - -move = [[1, 0], [-1, 0], [0, 1], [0, -1]] - - -def dfs(x, y, now, count): - if visit[x][y] == 1 and count > 3: - print("Yes") - sys.exit() - - for dx, dy in move: - dx += x - dy += y - if 0 <= dx < N and 0 <= dy < M: - if mapArr[dx][dy] == now: - if visit[dx][dy] == 0: - visit[dx][dy] = 1 - dfs(dx, dy, now, count + 1) - visit[dx][dy] = 0 - - -input = sys.stdin.readline - -N, M = list(map(int, input().split())) -mapArr = [list(input().rstrip()) for _ in range(N)] -visit = [[0 for _ in range(M)] for _ in range(N)] - - -for i in range(N): - for j in range(M): - now = mapArr[i][j] - if visit[i][j] == 0: - dfs(i, j, now, 0) - -print("No") diff --git "a/Rappire/6\354\233\2243\354\243\274\354\260\250/2623.py" "b/Rappire/6\354\233\2243\354\243\274\354\260\250/2623.py" deleted file mode 100644 index 8cd88df..0000000 --- "a/Rappire/6\354\233\2243\354\243\274\354\260\250/2623.py" +++ /dev/null @@ -1,39 +0,0 @@ -import sys -from collections import deque - -input = sys.stdin.readline - -N, M = list(map(int, input().split())) - -arr = [[0, []] for _ in range(N + 1)] -que = deque([]) - -for i in range(M): - temp = list(map(int, input().split())) - before = -1 - for i in range(1, temp[0]): - now = temp[i] - next = temp[i + 1] - arr[now][1].append(next) - arr[next][0] += 1 - -for i in range(1, N + 1): - temp = arr[i] - if temp[0] == 0: - que.append(i) - -answer = [] -while que: - now = que.popleft() - answer.append(now) - temp = arr[now][1] - for i in temp: - arr[i][0] -= 1 - if arr[i][0] == 0: - que.append(i) - -if len(answer) == N: - for i in answer: - print(i) -else: - print(0) diff --git "a/Rappire/6\354\233\2243\354\243\274\354\260\250/\353\263\264\354\204\235 \354\207\274\355\225\221.py" "b/Rappire/6\354\233\2243\354\243\274\354\260\250/\353\263\264\354\204\235 \354\207\274\355\225\221.py" deleted file mode 100644 index 0467c03..0000000 --- "a/Rappire/6\354\233\2243\354\243\274\354\260\250/\353\263\264\354\204\235 \354\207\274\355\225\221.py" +++ /dev/null @@ -1,28 +0,0 @@ -from collections import defaultdict - - -def solution(gems): - answer = [] - minNum = 10e10 - gemNum = len(set(gems)) - length = len(gems) - gemdict = defaultdict(int) - pos = 0 - count = 0 - for start in range(length): - while count < gemNum and pos < length: - if gemdict[gems[pos]] == 0: - count += 1 - gemdict[gems[pos]] += 1 - pos += 1 - - if count == gemNum: - if minNum > pos - start: - minNum = pos - start - answer = [start + 1, pos] - - if gemdict[gems[start]] == 1: - count -= 1 - gemdict[gems[start]] -= 1 - - return answer diff --git "a/Rappire/6\354\233\2243\354\243\274\354\260\250/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.py" "b/Rappire/6\354\233\2243\354\243\274\354\260\250/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.py" deleted file mode 100644 index 9a22c68..0000000 --- "a/Rappire/6\354\233\2243\354\243\274\354\260\250/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.py" +++ /dev/null @@ -1,40 +0,0 @@ -from math import ceil -from collections import defaultdict - - -def solution(fees, records): - recordDict = {} - totalDict = defaultdict(int) - answer = [] - - for record in records: - time, carNum, history = record.split() - time = time2num(time) - carNum = int(carNum) - if recordDict.get(carNum, -1) != -1: - inTime = recordDict.pop(carNum) - totalDict[carNum] += time - inTime - else: - recordDict[carNum] = time - - inTime = 23 * 60 + 59 - - for key in recordDict.keys(): - totalDict[key] += inTime - recordDict[key] - - keys = list(totalDict.keys()) - keys.sort() - for key in keys: - answer.append(calFee(totalDict[key], fees)) - return answer - - -def time2num(time): - hour, minute = map(int, time.split(":")) - return hour * 60 + minute - - -def calFee(total, fees): - if total > fees[0]: - return fees[1] + ceil((total - fees[0]) / fees[2]) * fees[3] - return fees[1] diff --git "a/baekeunsun/4\354\233\2243\354\243\274\354\260\250/1041.py" "b/baekeunsun/4\354\233\2243\354\243\274\354\260\250/1041.py" deleted file mode 100644 index 133ef27..0000000 --- "a/baekeunsun/4\354\233\2243\354\243\274\354\260\250/1041.py" +++ /dev/null @@ -1,27 +0,0 @@ -# 주사위 -N = int(input()) -dice = list(map(int,input().split(' '))) -square = N*N*5 -answer = 0 - -if N == 1 : - dice.sort() - print(sum(dice[:5])) -else : - answer = 0 - pair = [] - for i in range(3): - pair.append(min(dice[i],dice[-1-i])) - pair.sort() - - # 3면이 모두 보이는 경우 - answer += 4*sum(pair) - square -= 4*3 - - # 2면이 모두 보이는 경우 - answer += (8*N-12)*sum(pair[:2]) - square -= (8*N-12)*2 - - # 1면만 보이는 경우 - answer += square*pair[0] - print(answer) diff --git "a/baekeunsun/4\354\233\2243\354\243\274\354\260\250/10942.py" "b/baekeunsun/4\354\233\2243\354\243\274\354\260\250/10942.py" deleted file mode 100644 index a7b3ddb..0000000 --- "a/baekeunsun/4\354\233\2243\354\243\274\354\260\250/10942.py" +++ /dev/null @@ -1,29 +0,0 @@ -# 펠린드롬? -import sys -input = sys.stdin.readline -sys.setrecursionlimit(100000) - -N = int(input()) -hong = list(map(int,input().split(' '))) -dp = list([-2]*N for _ in range(N)) - -def palindrome(start,end): - if dp[start][end] != -2 : - return(dp[start][end]) - - if start == end : - return 1 - - if hong[start] == hong[end] : - if start + 1 == end : - return 1 - else : - dp[start][end] = palindrome(start+1,end-1) - return(dp[start][end]) - else : - return 0 - - -for _ in range(int(input())): - start,end = map(int,input().split(' ')) - print(palindrome(start-1,end-1)) diff --git "a/baekeunsun/4\354\233\2243\354\243\274\354\260\250/14719.py" "b/baekeunsun/4\354\233\2243\354\243\274\354\260\250/14719.py" deleted file mode 100644 index 3de7529..0000000 --- "a/baekeunsun/4\354\233\2243\354\243\274\354\260\250/14719.py" +++ /dev/null @@ -1,15 +0,0 @@ -# 빗물 -H, W = map(int,input().split(' ')) -block = list(map(int,input().split(' '))) -answer = 0 - -for i in range(1,len(block)-1): - left = max(block[:i]) - right = max(block[i+1:]) - - wall = min(left,right) - - if wall > block[i]: - answer += wall - block[i] - -print(answer) diff --git "a/baekeunsun/4\354\233\2243\354\243\274\354\260\250/150368.py" "b/baekeunsun/4\354\233\2243\354\243\274\354\260\250/150368.py" deleted file mode 100644 index aa425f3..0000000 --- "a/baekeunsun/4\354\233\2243\354\243\274\354\260\250/150368.py" +++ /dev/null @@ -1,33 +0,0 @@ -# 이모티콘 할인행사 -from itertools import product - -def solution(users, emoticons): - emotiPlus = 0 - totalPaid = 0 - discounts = product([10,20,30,40],repeat=len(emoticons)) - - for discount in discounts: # 경우의 수 - buyPlus = 0 - buyTotal = 0 - - for user in users: - paid = 0 - - for i in range(len(emoticons)): - if(discount[i] >= user[0]): # 할인이 사용자의 기준보다 높거나 같음(산다) - paid += emoticons[i] * (1 - discount[i]/100) - - if(paid >= user[1]): # 지불한 값이 가진 돈보다 크면 - buyPlus += 1 - else: # 전체 구매비용 추가 - buyTotal += paid - - if(emotiPlus < buyPlus): # 이모티콘 플러스 가입횟수가 더 많아짐, 갱신 - emotiPlus = buyPlus - totalPaid = buyTotal - - elif (emotiPlus == buyPlus): # 플러스 가입횟수 같을때, 돈 더 많이 벌었으면 갱신 - if buyTotal > totalPaid : - totalPaid = buyTotal - - return [emotiPlus, totalPaid] diff --git "a/baekeunsun/4\354\233\2243\354\243\274\354\260\250/15486.py" "b/baekeunsun/4\354\233\2243\354\243\274\354\260\250/15486.py" deleted file mode 100644 index a096016..0000000 --- "a/baekeunsun/4\354\233\2243\354\243\274\354\260\250/15486.py" +++ /dev/null @@ -1,15 +0,0 @@ -# 퇴사 2 -import sys -input = sys.stdin.readline - -N = int(input()) -dp = list(0 for _ in range(N+1)) - -for now in range(N): - T,P = map(int,input().split(' ')) - - dp[now+1] = max(dp[now+1],dp[now]) - if now + T < N+1 : - dp[now+T] = max(dp[now+T],dp[now]+P) - -print(dp[-1]) diff --git "a/baekeunsun/4\354\233\2244\354\243\274\354\260\250/1068.py" "b/baekeunsun/4\354\233\2244\354\243\274\354\260\250/1068.py" deleted file mode 100644 index 03a34d8..0000000 --- "a/baekeunsun/4\354\233\2244\354\243\274\354\260\250/1068.py" +++ /dev/null @@ -1,19 +0,0 @@ -# 트리 -def dfs(node): - tree[node] = -2 - for i in range(N): - if node == tree[i]: # 자식의 자식 - dfs(i) - -N = int(input()) -tree = list(map(int, input().split())) -E = int(input()) - -dfs(E) -answer = 0 - -for i in range(N): - if tree[i] != -2 and i not in tree: - answer += 1 - -print(answer) diff --git "a/baekeunsun/4\354\233\2244\354\243\274\354\260\250/11404.py" "b/baekeunsun/4\354\233\2244\354\243\274\354\260\250/11404.py" deleted file mode 100644 index 6e0e714..0000000 --- "a/baekeunsun/4\354\233\2244\354\243\274\354\260\250/11404.py" +++ /dev/null @@ -1,29 +0,0 @@ -# 플로이드 -import sys -input = sys.stdin.readline - -n = int(input()) -m = int(input()) -graph = list([sys.maxsize]*n for _ in range(n)) - - -for i in range(m): - s, e, value = map(int,input().split(' ')) - graph[s-1][e-1] = min(graph[s-1][e-1],value) - -for j in range(n): - graph[j][j] = 0 - - -for mid in range(n): - for start in range(n): - for end in range(n): - graph[start][end] = min(graph[start][end], graph[start][mid]+graph[mid][end]) - -for i in range(n): - for j in range(n): - if graph[i][j]==sys.maxsize: - print(0, end=' ') - else : - print(graph[i][j], end=' ') - print() diff --git "a/baekeunsun/4\354\233\2244\354\243\274\354\260\250/2342.py" "b/baekeunsun/4\354\233\2244\354\243\274\354\260\250/2342.py" deleted file mode 100644 index 309cbe9..0000000 --- "a/baekeunsun/4\354\233\2244\354\243\274\354\260\250/2342.py" +++ /dev/null @@ -1,30 +0,0 @@ -# Dance Dance Revolution -import sys -sys.setrecursionlimit(10**6) - -def move(a, b): - if a == b: - return 1 - if a == 0: - return 2 - if abs(b-a)%2 == 0: - return 4 - return 3 - -def solve(n, l, r): - global dp - if n >= len(game)-1: - return 0 - - if dp[n][l][r] != -1: - return dp[n][l][r] - left = solve(n+1, game[n],r) + move(l, game[n]) - right = solve(n+1, l, game[n]) + move(r, game[n]) - - dp[n][l][r] = min(left, right) - return dp[n][l][r] - -game = list(map(int, input().split())) -dp = [[[-1]*5 for _ in range(5)] for _ in range(100000)] - -print(solve(0, 0, 0)) diff --git "a/baekeunsun/4\354\233\2244\354\243\274\354\260\250/7576.py" "b/baekeunsun/4\354\233\2244\354\243\274\354\260\250/7576.py" deleted file mode 100644 index 38b631f..0000000 --- "a/baekeunsun/4\354\233\2244\354\243\274\354\260\250/7576.py" +++ /dev/null @@ -1,39 +0,0 @@ -# 토마토 -from collections import deque - -def bfs(M, N, box): - dx = [1, -1, 0, 0] - dy = [0, 0, -1, 1] - days = -1 - - while ripe: - days += 1 - for _ in range(len(ripe)): # 하루 - x, y = ripe.popleft() - - for i in range(4): - nx = x + dx[i] - ny = y + dy[i] - - if 0 <= nx < N and 0 <= ny < M and box[nx][ny] == 0: - box[nx][ny] = 1 - ripe.append([nx, ny]) - - for b in box: - if 0 in b: - return -1 - return days - - -M, N = map(int, input().split()) -box = list() -ripe = deque() - -for i in range(N): - row = list(map(int, input().split())) - for j in range(M): - if row[j] == 1: - ripe.append([i, j]) - box.append(row) - -print(bfs(M, N, box)) diff --git "a/baekeunsun/4\354\233\2244\354\243\274\354\260\250/9935.py" "b/baekeunsun/4\354\233\2244\354\243\274\354\260\250/9935.py" deleted file mode 100644 index 8d80ef4..0000000 --- "a/baekeunsun/4\354\233\2244\354\243\274\354\260\250/9935.py" +++ /dev/null @@ -1,18 +0,0 @@ -# 문자열 폭발 -string = input() -bomb = input() - -stack = [] -length = len(bomb) -lastChar = bomb[-1] - -for char in string: - stack.append(char) - if char == lastChar : - if ''.join(stack[-length:]) == bomb: - del stack[-length:] - -if not stack : - print("FRULA") -else : - print(''.join(stack)) diff --git "a/baekeunsun/5\354\233\2241\354\243\274\354\260\250/1043.py" "b/baekeunsun/5\354\233\2241\354\243\274\354\260\250/1043.py" deleted file mode 100644 index cff1df6..0000000 --- "a/baekeunsun/5\354\233\2241\354\243\274\354\260\250/1043.py" +++ /dev/null @@ -1,37 +0,0 @@ -# 거짓말 -from collections import deque - -N, M = map(int,input().split()) -know = list(map(int,input().split())) -meet = list({0} for _ in range(N+1)) -party = [] - -know.pop(0) - -for i in range(M): - tmp = list(map(int,input().split())) - for i in range(1,tmp[0]+1): - for j in range(1,tmp[0]+1): - meet[tmp[i]].add(tmp[j]) - party.append(tmp[1:]) - -queue = deque(know) -while queue: - tmp = queue.popleft() - for i in (meet[tmp]): - if i in know : - continue - else : - know.append(i) - queue.append(i) - - -answer = 0 -for i in range(M): - intersection = list(set(know) & set(party[i])) - if intersection : - continue - else : - answer += 1 - -print(answer) diff --git "a/baekeunsun/5\354\233\2241\354\243\274\354\260\250/1106.py" "b/baekeunsun/5\354\233\2241\354\243\274\354\260\250/1106.py" deleted file mode 100644 index 6b48a16..0000000 --- "a/baekeunsun/5\354\233\2241\354\243\274\354\260\250/1106.py" +++ /dev/null @@ -1,14 +0,0 @@ -# 호텔 -import sys - -C,N = map(int,input().split()) -promotion = [list(map(int,input().split())) for _ in range(N)] - -dp = [sys.maxsize for _ in range(C+100)] -dp[0] = 0 - -for value, customer in promotion: - for i in range(customer,C+100): - dp[i] = min(dp[i - customer] + value, dp[i]) # i명일 때, 최소비용 갱신 - -print(min(dp[C:])) # 최소 C명이 되어야 하기 때문 diff --git "a/baekeunsun/5\354\233\2241\354\243\274\354\260\250/1202.py" "b/baekeunsun/5\354\233\2241\354\243\274\354\260\250/1202.py" deleted file mode 100644 index 1d2f474..0000000 --- "a/baekeunsun/5\354\233\2241\354\243\274\354\260\250/1202.py" +++ /dev/null @@ -1,23 +0,0 @@ -# 보석 도둑 -import heapq -import sys - -input = sys.stdin.readline - -N, K = map(int,input().split()) # 보석개수, 가방개수 -gems = [(list(map(int,input().split()))) for _ in range(N)] # 무게, 가격 -bags = [(int(input())) for _ in range(K)] - -gems.sort() -bags.sort() -answer = 0 -canBuy = [] # 보석의 가격 저장 리스트 - -for bag in bags: - while gems and gems[0][0] <= bag: - heapq.heappush(canBuy, -gems[0][1]) # 최대힙 - heapq.heappop(gems) - if canBuy: - answer -= heapq.heappop(canBuy) - -print(answer) diff --git "a/baekeunsun/5\354\233\2241\354\243\274\354\260\250/14578.py" "b/baekeunsun/5\354\233\2241\354\243\274\354\260\250/14578.py" deleted file mode 100644 index 88fb86e..0000000 --- "a/baekeunsun/5\354\233\2241\354\243\274\354\260\250/14578.py" +++ /dev/null @@ -1,14 +0,0 @@ -# 영훈이의 색칠공부 -N = int(input()) -dp = [0,0,1] -fact = 2 -mod = 1000000007 - -if N > 1 : - for i in range(3,N+1): - dp.append(((dp[i-1]+dp[i-2])*(i-1))%mod) - fact *= i - print((fact*dp[N])%mod) - -else : - print(0) diff --git "a/baekeunsun/5\354\233\2241\354\243\274\354\260\250/16724.py" "b/baekeunsun/5\354\233\2241\354\243\274\354\260\250/16724.py" deleted file mode 100644 index 6dcf979..0000000 --- "a/baekeunsun/5\354\233\2241\354\243\274\354\260\250/16724.py" +++ /dev/null @@ -1,30 +0,0 @@ -# 피리부는 사나이 -N, M = map(int,input().split()) -Map = list(list(map(str,input())) for _ in range(N)) - -visit = [[-1 for _ in range(M)] for _ in range(N)] - -direction = ['L','R','U','D'] -dx = [0,0,-1,1] -dy = [-1,1,0,0] - -def move(x,y,idx): - global answer - if visit[x][y] != -1: # 방문함 - if visit[x][y] == idx: - answer += 1 - return # 만일 형성된 사이클에 방문하더라도 idx가 다르기때문에 괜찮다 - - visit[x][y] = idx - i = direction.index(Map[x][y]) - move(x + dx[i], y + dy[i], idx) - -idx = 0 -answer = 0 -for n in range(N): - for m in range(M): - move(n,m,idx) - idx += 1 - - -print(answer) diff --git "a/baekeunsun/5\354\233\2241\354\243\274\354\260\250/2141.py" "b/baekeunsun/5\354\233\2241\354\243\274\354\260\250/2141.py" deleted file mode 100644 index e04c21a..0000000 --- "a/baekeunsun/5\354\233\2241\354\243\274\354\260\250/2141.py" +++ /dev/null @@ -1,24 +0,0 @@ -# 우체국 -import sys -input = sys.stdin.readline - -N = int(input()) -village =[] -human = 0 - -for _ in range(N): - distance, people = map(int,input().split()) - village.append([distance,people]) - human += people - -village.sort() -tmp = 0 -answer = 0 - -for i in range(N): - tmp += village[i][1] - if tmp >= (human/2) : - answer = village[i][0] - break - -print(answer) diff --git "a/baekeunsun/5\354\233\2242\354\243\274\354\260\250/1052.py" "b/baekeunsun/5\354\233\2242\354\243\274\354\260\250/1052.py" deleted file mode 100644 index 8a55222..0000000 --- "a/baekeunsun/5\354\233\2242\354\243\274\354\260\250/1052.py" +++ /dev/null @@ -1,9 +0,0 @@ -# 물병 -N, K = map(int,input().split()) # 물병 수, 한버에 옮길 수 있는 물병 수 -count = 0 - -while bin(N).count('1') > K: - N += 1 - count += 1 - -print(count) diff --git "a/baekeunsun/5\354\233\2242\354\243\274\354\260\250/21923.py" "b/baekeunsun/5\354\233\2242\354\243\274\354\260\250/21923.py" deleted file mode 100644 index 3d6a5f5..0000000 --- "a/baekeunsun/5\354\233\2242\354\243\274\354\260\250/21923.py" +++ /dev/null @@ -1,31 +0,0 @@ -# 곡예 비행 -import sys -input = sys.stdin.readline - -N, M = map(int, input().split()) -Map = [list(map(int, input().split())) for _ in range(N)] -dp = [[-10000000001] * (M) for _ in range(N)] -dp[N-1][0] = 0 - -# 상승 -for i in range(N-1,-1,-1): - for j in range(M): - if i != N - 1: # 밑에서 올라온 값 갱신 - dp[i][j] = dp[i+1][j] - if j != 0 : # 왼쪽에서 이동한값 갱신 - dp[i][j] = max(dp[i][j], dp[i][j-1]) - - dp[i][j] += Map[i][j] - -# 하강 -for i in range(N): - for j in range(M): - if i != 0 : # 위에서 내려온 값 갱신 - dp[i][j] = max(dp[i][j], dp[i-1][j]) - if j != 0 : # 왼쪽에서 이동한 값 갱신 - dp[i][j] = max(dp[i][j], dp[i][j-1]) - - dp[i][j] += Map[i][j] - - -print(dp[N-1][M-1]) diff --git "a/baekeunsun/5\354\233\2242\354\243\274\354\260\250/27940.py" "b/baekeunsun/5\354\233\2242\354\243\274\354\260\250/27940.py" deleted file mode 100644 index b763bd7..0000000 --- "a/baekeunsun/5\354\233\2242\354\243\274\354\260\250/27940.py" +++ /dev/null @@ -1,41 +0,0 @@ -# 가지 산사태 -# for문 두번 넣은거 혹시 설명 부족했을까 싶어서 밑에 추가 해놨습니다~! - -# 최종 풀이 -import sys -input = sys.stdin.readline - -N, M, K = map(int,input().split()) # 농장층수, 비 횟수, 버틸수있는 빗물 양 - -total = 0 -for i in range(1,M+1): - t, r = map(int,input().split()) # 1층~t층, r만큼 비 - total += r - if total > K : - print(i,1) - sys.exit() - -print(-1) - -# 중간 풀이 -import sys -input = sys.stdin.readline - -N, M, K = map(int,input().split()) # 농장층수, 비 횟수, 버틸수있는 빗물 양 -farm = [0]*(N+1) - -total = 0 -for i in range(1,M+1): - t, r = map(int,input().split()) # 1층~t층, r만큼 비 - farm[t] += r - total += r - if total > K : - tmp = 0 - for j in range(N,0,-1): - tmp += farm[j] - if tmp > K : - print(i, j) - sys.exit() - -print(-1) - diff --git "a/baekeunsun/5\354\233\2243\354\243\274\354\260\250/11508.py" "b/baekeunsun/5\354\233\2243\354\243\274\354\260\250/11508.py" deleted file mode 100644 index 1670328..0000000 --- "a/baekeunsun/5\354\233\2243\354\243\274\354\260\250/11508.py" +++ /dev/null @@ -1,16 +0,0 @@ -# 2+1 세일 -import sys -input = sys.stdin.readline - -N = int(input()) -buy = list(int(input()) for _ in range(N)) -buy.sort(reverse=True) -answer = [] - -for i in range(N//3): - answer += buy[i*3:i*3+2] - -for j in range(N%3): - answer.append(buy[-1-j]) - -print(sum(answer)) diff --git "a/baekeunsun/5\354\233\2243\354\243\274\354\260\250/150369.py" "b/baekeunsun/5\354\233\2243\354\243\274\354\260\250/150369.py" deleted file mode 100644 index 7e97f7f..0000000 --- "a/baekeunsun/5\354\233\2243\354\243\274\354\260\250/150369.py" +++ /dev/null @@ -1,47 +0,0 @@ -# 택배 배달과 수거하기 -def solution(cap, n, deliveries, pickups): - def sol(target_list): - truck = cap - tmp = 0 - i = n-1 - return_list = [] - - while i >= 0: - if target_list[i] == 0 : - i -= 1 - continue - - tmp = max(tmp, (i+1)) - if truck >= target_list[i]: - truck -= target_list[i] - target_list[i] = 0 - i -= 1 - else : - target_list[i] -= truck - truck = 0 - - if truck == 0: # 배달할 수 있는 양 넘음, 돌아가야함 - return_list.append(tmp) - truck = cap - tmp = 0 - - if tmp > 0: - return_list.append(tmp) - - return return_list - - answer = 0 - deliver_list = sorted(sol(deliveries)) - pickup_list = sorted(sol(pickups)) - - - while deliver_list or pickup_list : - if deliver_list : - if pickup_list : - answer += (max(deliver_list.pop(), pickup_list.pop())) *2 - else : - answer += (deliver_list.pop())*2 - elif pickup_list : - answer += (pickup_list.pop())*2 - - return answer diff --git "a/baekeunsun/5\354\233\2243\354\243\274\354\260\250/16946.py" "b/baekeunsun/5\354\233\2243\354\243\274\354\260\250/16946.py" deleted file mode 100644 index 27a0f9c..0000000 --- "a/baekeunsun/5\354\233\2243\354\243\274\354\260\250/16946.py" +++ /dev/null @@ -1,50 +0,0 @@ -# 벽 부수고 이동하기 4 -from collections import deque - -N, M = map(int,input().split()) -Map = [list(map(int, input())) for _ in range(N)] -group_cnt = 2 -group = [0,0] -dx = [-1,1,0,0] -dy = [0,0,-1,1] -visit = list([True]*M for _ in range(N)) - -def bfs(sx, sy): - queue = deque([[sx,sy]]) - count = 0 - - while queue : - x, y = queue.popleft() - count += 1 - Map[x][y] = group_cnt - for i in range(4): - ix = x + dx[i] - iy = y + dy[i] - if N > ix >= 0 and M > iy >= 0 and Map[ix][iy] == 0 and visit[ix][iy] == True: - queue.append([ix,iy]) - visit[ix][iy] = False - return count - -for i in range(N): - for j in range(M): - if Map[i][j] == 0 : # 그룹 생성 - visit[i][j] = True - group.append(bfs(i,j)) - group_cnt += 1 - -for x in range(N) : - for y in range(M): - near_list = set() - tmp = 1 - if Map[x][y] > 1 : - print(0,end='') - else : - for i in range(4): - ix = x + dx[i] - iy = y + dy[i] - if N > ix >= 0 and M > iy >= 0 and Map[ix][iy] not in near_list: - near_list.add(Map[ix][iy]) - tmp += group[Map[ix][iy]] - print((tmp)%10, end='') - print() - diff --git "a/baekeunsun/5\354\233\2243\354\243\274\354\260\250/1759.py" "b/baekeunsun/5\354\233\2243\354\243\274\354\260\250/1759.py" deleted file mode 100644 index 280df70..0000000 --- "a/baekeunsun/5\354\233\2243\354\243\274\354\260\250/1759.py" +++ /dev/null @@ -1,50 +0,0 @@ -# 암호 만들기 -# 전체 combinations 한 코드 -from itertools import combinations -import sys -input=sys.stdin.readline - -L, C = map(int,input().split()) -string = sorted(input().split()) -words = combinations(string, L) - -for word in words : - count = 0 - for w in word : - if w in 'aeiou' : - count += 1 - if count >= 1 and (L-count) >= 2 : - print(''.join(word)) - -# 암호 만들기 -# 자음 모음 나누어서 combinations 한 코드 -import itertools -import sys -input=sys.stdin.readline - -L, C = map(int,input().split()) -string = list(map(str,input().split())) - -ja = [] -mo = [] - -for i in string : - if i in ['a','e','i','o','u'] : - ja.append(i) - else : - mo.append(i) - -answer = [] -tmp = [] -for n in range(1,min(len(ja)+1, L-1)): - for case1 in (itertools.combinations(ja, n)) : - for case2 in (itertools.combinations(mo, L - n)): - tmp = list(case1 + case2) - tmp.sort() - answer.append(tmp) -answer.sort() - -for i in answer : - print(*i, sep='') - - diff --git "a/baekeunsun/5\354\233\2243\354\243\274\354\260\250/2503.py" "b/baekeunsun/5\354\233\2243\354\243\274\354\260\250/2503.py" deleted file mode 100644 index e189bb9..0000000 --- "a/baekeunsun/5\354\233\2243\354\243\274\354\260\250/2503.py" +++ /dev/null @@ -1,30 +0,0 @@ -# 숫자 야구 -N = int(input()) -number = [True] * 1000 # 이 중 세자리수만 사용 - -for i in range(123, 1000): - tmp = str(i) - if tmp[0] == tmp[1] or tmp[1] == tmp[2] or tmp[0] == tmp[2]: - number[i] = False - if '0' in tmp: - number[i] = False - -for i in range(0, N): - target, strike, ball = map(int,input().split()) - - for num in range(123, 1000): - strike_cnt = 0 - ball_cnt = 0 - - for t in range(0, 3): - for n in range(0, 3): - if str(target)[t] == str(num)[n]: - if t == n : - strike_cnt += 1 - else : - ball_cnt += 1 - - if strike != strike_cnt or ball != ball_cnt: - number[num] = False - -print(number[123:1000].count(True)) diff --git "a/baekeunsun/5\354\233\2243\354\243\274\354\260\250/3020.py" "b/baekeunsun/5\354\233\2243\354\243\274\354\260\250/3020.py" deleted file mode 100644 index 02c200f..0000000 --- "a/baekeunsun/5\354\233\2243\354\243\274\354\260\250/3020.py" +++ /dev/null @@ -1,31 +0,0 @@ -# 개똥벌레 -import sys -input = sys.stdin.readline - -N, H = map(int,input().split()) -up = [0]*(H+1) -down = [0]*(H+1) - -for i in range(N): - tmp = int(input()) - if i%2 == 0 : - down[tmp] += 1 - else: - up[tmp] += 1 - -for i in range(H-1,0,-1): - up[i] += up[i+1] - down[i] += down[i+1] -min_count = 0 -min_num = sys.maxsize - -for i in range(1,H+1): - tmp = up[i] + down[H-i+1] - if min_num == tmp : - min_count += 1 - continue - if min_num > tmp : - min_num = tmp - min_count = 1 - -print(min_num, min_count) diff --git "a/easyhooon/4\354\233\2243\354\243\274\354\260\250/1041.py" "b/easyhooon/4\354\233\2243\354\243\274\354\260\250/1041.py" deleted file mode 100644 index b94e311..0000000 --- "a/easyhooon/4\354\233\2243\354\243\274\354\260\250/1041.py" +++ /dev/null @@ -1,87 +0,0 @@ -import sys - -# 주사위를 적절히 회전시키고 쌓아서, N x N x N 크기의 정육면체를 만들려고 함 -# 이 정육면체는 5개 면만 보인다. -# 보이는 5개의 면에 쓰여있는 수의 합의 최솟값을 출력하는 프로그램을 작성 -# 바닥에 닿는 면은 따로 체크 필요 - -# 바닥에 닿지 않는 케이스 -# 모서리, 꼭짓점, 면 -# 면 -> 항상 가장 작은 숫자 * (n-2) * (n-2) * 5 -# 모서리 -> 두 수의 합이 제일 적은 쪽으로 * (n-2) * 8 -# 꼭짓점 -> 세수의 합이 가장 작은 쪽으로 * 4 - -# 바닥에 닿는 케이스 -# 모서리 -> 가장 작은 수 * (n-2) * 4 -# 꼭지점 -> 두 수의 합이 제일 적은 쪽으로 * 4 - -# A B C D E F -# 1 2 3 4 5 6 - -# 만나는 면 모음 -# A, D, E -> 1 + 4 + 5 = 10 -# A, C, E -> 1 + 3 + 5 = 9 -# A, B, D -> 1 + 2 + 4 = 7 -# A, B, C -> 1 + 2 + 3 = 6 -# B, D, F -> 2 + 4 + 6 = 12 -# B, C, F -> 2 + 3 + 6 = 11 -# D, E, F -> 4 + 5 + 6 = 15 -# C, E, F -> 3 + 5 + 6 = 14 - -# 예제 1 -# (4 * 6) + (3 * 4) = 36 - -# 예제 2 -# (1 * 5) + (3 * 8) + (6 * 4) + (1 * 4) + (3 * 4) = 5 + 24 + 24 + 4 + 12 = 69 - -# 알아야 할 것 -# 가장 작은 수 -# 가장 작은 두 수의 합 -# 가장 작은 세수의 합 - -# 이게 안되는게 가장 작은 두개의 합, 가장 작은 세개의 합을 못 만들 수 도 있기 때문 -# 가능한 조합 중에서 가장 작은 걸 찾고 아래 식을 돌려야 함 -# 가능한 조합 인덱스 찾기 -# 내가 생각한 수식보다 더 작은 경우의 수일 때가 존재하는건가 - -# AE, AD, AB, AC, DB, DE, DF, CE, CB, CF, EF, BF -# (0,4) (0,3) (0,1) (0,2) (1,3), (3,4), (3,5), (2,4), (2,3), (2,5), (4,5), (1,5) - -# A, D, E -> 1 + 4 + 5 = 10, 0, 3, 4 -# A, C, E -> 1 + 3 + 5 = 9, 0, 2, 4 -# A, B, D -> 1 + 2 + 4 = 7, 0, 1, 3 -# A, B, C -> 1 + 2 + 3 = 6, 0, 1, 2 -# B, D, F -> 2 + 4 + 6 = 12, 1, 3, 5 -# B, C, F -> 2 + 3 + 6 = 11, 1, 2, 5 -# D, E, F -> 4 + 5 + 6 = 15, 3, 4, 5 -# C, E, F -> 3 + 5 + 6 = 14, 2, 4, 5 - - -si = sys.stdin.readline - -n = int(si()) -arr = list(map(int, si().split())) -min_num = sorted(arr)[0] -min_two_sum = min(arr[0] + arr[4], arr[0] + arr[3], arr[0] + arr[1], arr[0] + arr[2], arr[1] + arr[3], arr[3] + arr[4], - arr[3] + arr[5], arr[2] + arr[4], arr[1] + arr[2], arr[2] + arr[5], arr[4] + arr[5], arr[1] + arr[5]) -min_three_sum = min(arr[0] + arr[3] + arr[4], arr[0] + arr[2] + arr[4], arr[0] + arr[1] + arr[3], - arr[0] + arr[1] + arr[2], - arr[1] + arr[3] + arr[5], arr[1] + arr[2] + arr[5], arr[3] + arr[4] + arr[5], - arr[2] + arr[4] + arr[5]) - -# print(min_num, min_two_sum, min_three_sum) - -# 밑의 점화식은 n >= 2 이상일때에 해당 -# n == 1 일때를 고려해줘야 함 - -if n == 1: - answer = sum(sorted(arr)[:len(arr) - 1]) -else: - answer = 0 - answer += min_num * (n - 2) * (n - 2) * 5 - answer += min_two_sum * (n - 2) * 8 - answer += min_three_sum * 4 - answer += min_num * (n - 2) * 4 - answer += min_two_sum * 4 - -print(answer) diff --git "a/easyhooon/4\354\233\2243\354\243\274\354\260\250/10942.py" "b/easyhooon/4\354\233\2243\354\243\274\354\260\250/10942.py" deleted file mode 100644 index 55b523a..0000000 --- "a/easyhooon/4\354\233\2243\354\243\274\354\260\250/10942.py" +++ /dev/null @@ -1,82 +0,0 @@ -import sys - -sys.setrecursionlimit(10**4) -si = sys.stdin.readline - -# dp[i][j] := 배열의 시작 인덱스를 i, 끝 인덱스를 j 라고 할 때, arr[i,,,j]가 펠린드롬 수 인지(1) 아닌지(0) - -n = int(si()) -arr = [0] + list(map(int, si().split())) -dp = [[-1] * (n + 1) for _ in range(n + 1)] -m = int(si()) - -# 기저조건 모든 dp[i][i] 는 펠린 드롬 -# for i in range(1, n + 1): -# dp[i][i] = 1 - -# 2 개도 채울 수 있지 않나? -> 같으면 1, 다르면 0 -# for i in range(1, n): -# if arr[i] == arr[i + 1]: -# dp[i][i + 1] = 1 -# -# else: -# dp[i][i + 1] = 0 - -# 바로 직전의 상황을 통해 판단 n, n - 1 -# 구간 [s, e] 의 펠린드롬을 판별하기 위해 구간 [s + 1, e - 1] 의 펠린드롬 판별 결과를 이용(저장하고 있음) -# 재귀스럽다 -> 메모이제이션을 쓰는게 더 자연스러운 문제 같기도 하다... -# 근데 메모이제이션을 사용하는 풀이에 약하다. - -# for i in range(1, n): -# for j in range(i, n + 1): -# if dp[i + 1][j - 1] == 1 and arr[i] == arr[j]: -# dp[i][j] = 1 - -# 이건 다 채워버린 다음에 쿼리를 하나씩 푸는 문제인듯 -# 홀 수 일때, 짝 수 일 때 -# 1 2 1 3 1 2 1 -# 1 1 0 1 0 0 0 1 -# 2 1 0 0 0 1 0 -# 1 1 0 1 0 0 -# 3 1 0 0 0 -# 1 1 0 1 -# 2 1 0 -# 1 1 - -# 채워봤을때 보이는 규칙 -# 펠린드롬 이전의 수는 펠린드롬이 아니다. 물론 모두 같은 수라면 말이 다르겠지 - -# 짝수, 홀수를 나눠서 풀 필요가 없다. -def memo(i, j): - # 홀수의 기저 조건 - # 기저 조건 1, 2, 3... - if i == j: - return 1 - - # 짝수의 기저 조건 - # 두자리 수 일 경우 11, 22, 33... - elif i + 1 == j: - if arr[i] == arr[j]: - return 1 - else: - return 0 - - # 판단을 이전에 하였다면 (memoization) - if dp[i][j] != -1: - return dp[i][j] - - # 처음 인덱스의 값과 끝 인덱스의 값이 다르면 - if arr[i] != arr[j]: - dp[i][j] = 0 - # 같으면 펠린드롬인지 검사해봄 - else: - dp[i][j] = memo(i + 1, j - 1) - - return dp[i][j] - - -# 메모이제이션 풀이법은 먼저 전부를 채우는 방식이 아니다. - -for _ in range(m): - s, e = map(int, si().split()) - print(memo(s, e)) \ No newline at end of file diff --git "a/easyhooon/4\354\233\2243\354\243\274\354\260\250/14719.py" "b/easyhooon/4\354\233\2243\354\243\274\354\260\250/14719.py" deleted file mode 100644 index 4fdeaa3..0000000 --- "a/easyhooon/4\354\233\2243\354\243\274\354\260\250/14719.py" +++ /dev/null @@ -1,33 +0,0 @@ -# 높이의 기준을 찾기 어려움 -import sys - -si = sys.stdin.readline - - -def get_rain_amount(heights): - n = len(heights) - left_max = [0] * n - right_max = [0] * n - cnt = 0 - - # 왼쪽에서 오른쪽으로 이동하며 각 위치에서 왼쪽의 최대 높이를 계산 - left_max[0] = heights[0] - for i in range(1, n): - left_max[i] = max(left_max[i - 1], heights[i]) - - # 오른쪽에서 왼쪽으로 이동하며 각 위치에서 오른쪽의 최대 높이를 계산 - right_max[n - 1] = heights[n - 1] - for i in range(n - 2, -1, -1): - right_max[i] = max(right_max[i + 1], heights[i]) - - # 현재 위치에서 빗물이 차있는 높이에서 현재 위치의 높이를 빼서 누적 합 - for i in range(n): - cnt += min(left_max[i], right_max[i]) - heights[i] - - return cnt - - -h, w = map(int, si().split()) -heights = list(map(int, si().split())) - -print(get_rain_amount(heights)) \ No newline at end of file diff --git "a/easyhooon/4\354\233\2243\354\243\274\354\260\250/15486.py" "b/easyhooon/4\354\233\2243\354\243\274\354\260\250/15486.py" deleted file mode 100644 index 1be5ae4..0000000 --- "a/easyhooon/4\354\233\2243\354\243\274\354\260\250/15486.py" +++ /dev/null @@ -1,41 +0,0 @@ -# 퇴사2 -import sys - -# 계단 오르기 문제의 역방향 - -si = sys.stdin.readline -INT_MIN = -sys.maxsize - -n = int(si()) - -t = [0] * n -p = [0] * n - -# 문제 이해 1일째 상담이 3일 걸리면 1일, 2일, 3일까지 상담하고 4일째부터는 다시 상담이 가능하다 -# dp[i]:= i번째 날 부터 상담을 진행하였을 때 얻을 수 있는 최대 금액 -dp = [0] * (n + 1) - -for i in range(n): - a, b = map(int, si().split()) - t[i] = a - p[i] = b - -# 기저 조건 -# 최대 금액을 구하는 문제이므로 -INT_MIN 값으로 dp 배열을 초기화 -for i in range(n): - dp[i] = INT_MIN - -dp[n] = 0 - -# for문 거꾸로 순회 하는 방법도 생각해봐야. -for i in range(n - 1, -1, -1): - # 상담 종료일이 마지막 날 이후일 경우 - if i + t[i] > n: - dp[i] = dp[i + 1] - else: - dp[i] = max(dp[i + 1], p[i] + dp[i + t[i]]) - -# print(dp) - -# 구하는 값: 첫날 부터 상담을 시작했을 때 얻을 수 있는 최대 금액 -print(dp[0]) diff --git "a/easyhooon/4\354\233\2243\354\243\274\354\260\250/\354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.py" "b/easyhooon/4\354\233\2243\354\243\274\354\260\250/\354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.py" deleted file mode 100644 index 20b3814..0000000 --- "a/easyhooon/4\354\233\2243\354\243\274\354\260\250/\354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.py" +++ /dev/null @@ -1,88 +0,0 @@ -# 1. 이모티콘 플러스 가입자 늘리는것 > 2. 이모티콘 판매액을 최대한 늘리는 것 -# n 명에게 이모티콘 m 개를 판매 -# emoticons 들의 할인율을 다 정해놓고 다 정한 다음에 결과를 갱신하도록 -# discount_rates = [0.1, 0.2, 0.3, 0.4] -discount_rates = [10, 20, 30, 40] -answer = [0, 0] - - -def check(users, emoticons, n, m, choose_discount_rates): - discounted_emoticon_prices = [] - emoticon_plus_cnt = 0 - total_sales = 0 - - # 이모티콘의 할인율이 적용된 가격을 구함 - for i in range(m): - # 2. 두번째 디버깅 해맨지점 - # 부동 소수점 계산 고려 - # discounted_emoticon_prices.append(int(emoticons[i] * (1 - choose_discount_rates[i]))) - discounted_emoticon_prices.append(emoticons[i] * (100 - choose_discount_rates[i]) // 100) - - - # 이모티콘 플러스 구독자와, 총 판매액을 구함 - for i in range(n): - # 각 사람당 이모티콘 구매 비용 - sales = 0 - for j in range(m): - # 1. 첫번째 디버깅 해맨지점 - # print("sales", sales) - # 이모티콘 구독을 하는 경우 - # 해당 반복문이 계산 이후로 옮겨져야 한다 - # if sales >= users[i][1]: - # print("emoticon plus subscribe", sales, users[i][1]) - # emoticon_plus_cnt += 1 - # break - # else: - if users[i][0] <= choose_discount_rates[j]: - sales += discounted_emoticon_prices[j] - # print("after", sales) - - # 이모티콘 구독을 하는 경우 - if sales >= users[i][1]: - # print("emoticon plus subscribe", sales, users[i][1]) - emoticon_plus_cnt += 1 - # 이모티콘 플러스 구독을 안하는 경우 - else: - total_sales += sales - - # print(emoticon_plus_cnt, total_sales) - return emoticon_plus_cnt, total_sales - - -def dfs(users, emoticons, cnt, n, m, choose_discount_rates): - if cnt == m: - emoticon_plus_cnt, total_sales = check(users, emoticons, n, m, choose_discount_rates) - # 정답 갱신 - # 1) 이모티콘 구독자 수가 더 많으면 2) 판매액이 높으면 - - # 이모티콘 구독자 수가 더 많으면 무조건 갱신 - if emoticon_plus_cnt > answer[0]: - answer[0] = emoticon_plus_cnt - answer[1] = total_sales - - # 이모티콘 구독자 수가 같을 경우 - elif emoticon_plus_cnt == answer[0]: - # 총 판매액이 더 크면 갱신 - if total_sales > answer[1]: - answer[1] = total_sales - return - - # 4개의 할인율 중에 m개 골라서 넣기, 중복을 허용(중복 순열) - for i in range(4): - choose_discount_rates.append(discount_rates[i]) - dfs(users, emoticons, cnt + 1, n, m, choose_discount_rates) - choose_discount_rates.pop() - - -def solution(users, emoticons): - n = len(users) - m = len(emoticons) - - dfs(users, emoticons, 0, n, m, []) - - print(answer) - return answer - -# 3. 세번째 디버깅 해맨 지점 -# 이거 남겨 놓으니까 테케 19, 20 틀렸다.. 테케 테스트 한거는 지우자.. -# solution([[40, 10000], [25, 10000]], [7000, 9000]) \ No newline at end of file diff --git "a/easyhooon/4\354\233\2244\354\243\274\354\260\250/1068.py" "b/easyhooon/4\354\233\2244\354\243\274\354\260\250/1068.py" deleted file mode 100644 index 1f5f548..0000000 --- "a/easyhooon/4\354\233\2244\354\243\274\354\260\250/1068.py" +++ /dev/null @@ -1,46 +0,0 @@ -# 트리 -import sys - -si = sys.stdin.readline - -n = int(si()) -graph = [[] for _ in range(n)] -# 각 노드의 leaf 노드의 개수 -leaf = [0] * n -root = 0 - - -# 정점 x의 부모가 parent, subtree(x) 의 leaf 노드의 개수를 구함 -# 트리 dp 에서 많이 쓰던 함수 -def dfs(x, parent): - if not graph[x]: - leaf[x] += 1 - - for y in graph[x]: - if y == parent: - continue - dfs(y, x) - leaf[x] += leaf[y] - - -# 각 노드의 부모 노드를 저장 -parent = list(map(int, si().split())) - -for i in range(n): - # parent 가 -1 이면 루트 노드 - if parent[i] == -1: - root = i - continue - graph[parent[i]].append(i) - -# 제거할 노드 -erased = int(si()) - -for i in range(n): - if erased in graph[i]: - graph[i].remove(erased) - -if root != erased: - dfs(root, -1) - -print(leaf[root]) \ No newline at end of file diff --git "a/easyhooon/4\354\233\2244\354\243\274\354\260\250/11404.py" "b/easyhooon/4\354\233\2244\354\243\274\354\260\250/11404.py" deleted file mode 100644 index bad1eda..0000000 --- "a/easyhooon/4\354\233\2244\354\243\274\354\260\250/11404.py" +++ /dev/null @@ -1,37 +0,0 @@ -# 플로이드 -import sys - -si = sys.stdin.readline -INT_MAX = sys.maxsize - - -def floyd(): - for k in range(n): - for i in range(n): - for j in range(n): - if i == j: - graph[i][j] = 0 - - elif graph[i][k] and graph[k][j]: - graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]) - - -n = int(si()) -m = int(si()) - -graph = [[INT_MAX] * 101 for _ in range(101)] - -for _ in range(m): - i, j, price = map(int, si().split()) - # 시작 도시와 도착 도시를 연결하는 노선은 하나가 아닐 수 있다. - graph[i - 1][j - 1] = min(graph[i - 1][j - 1], price) - -floyd() - -for i in range(n): - for j in range(n): - if graph[i][j] == INT_MAX: - print(0, end=" ") - else: - print(graph[i][j], end=" ") - print() diff --git "a/easyhooon/4\354\233\2244\354\243\274\354\260\250/2342.py" "b/easyhooon/4\354\233\2244\354\243\274\354\260\250/2342.py" deleted file mode 100644 index efcd986..0000000 --- "a/easyhooon/4\354\233\2244\354\243\274\354\260\250/2342.py" +++ /dev/null @@ -1,54 +0,0 @@ -import sys - -si = sys.stdin.readline - -INT_MAX = sys.maxsize - -arr = list(map(int, si().split())) -arr.pop() -n = len(arr) - - -# 점프할 때 비용 -def get_cost(before, after): - if before == 0: - if after == 0: - return 0 - else: - return 2 - elif before == after: - return 1 - elif abs(before - after) == 1 or abs(before - after) == 3: - return 3 - else: - return 4 - - -# if n == 0: -# print(0) -# exit() - -# dp[i][j][k]:= i번째 점프에서 왼발의 위치가 j 이고 오른발의 위치가 k 일때 최소 비용 -dp = [[[INT_MAX for _ in range(5)] for _ in range(5)] for _ in range(n + 1)] -dp[-1][0][0] = 0 - -for i in range(n): - # l = arr[i], 왼발로 이번 위치 누를 때, 즉 이번에 왼발이 움직일 것 - for r in range(5): # 왼발이 움직이니 오른발은 고정 - for before in range(5): # k 는 왼발의 이전 위치. - cost = get_cost(before, arr[i]) # 왼발이 k에서 arr[i]로 움직일 때 드는 비용 - dp[i][arr[i]][r] = min(dp[i][arr[i]][r], dp[i - 1][before][r] + cost) - - # r = arr[i], 오른발로 이번 위치 누를 때, 즉 이번에 오른발이 움직일 것 - for l in range(5): # 오른발이 움직이니 왼발은 고정 - for before in range(5): # k는 오른발의 이전 위치. - cost = get_cost(before, arr[i]) # 오른발이 k에서 arr[i]로 움직일 때 드는 비용 - dp[i][l][arr[i]] = min(dp[i][l][arr[i]], dp[i - 1][l][before] + cost) - -answer = INT_MAX - -for l in range(5): - for r in range(5): - answer = min(answer, dp[n - 1][l][r]) - -print(answer) diff --git "a/easyhooon/4\354\233\2244\354\243\274\354\260\250/7576.py" "b/easyhooon/4\354\233\2244\354\243\274\354\260\250/7576.py" deleted file mode 100644 index 8bfa97d..0000000 --- "a/easyhooon/4\354\233\2244\354\243\274\354\260\250/7576.py" +++ /dev/null @@ -1,68 +0,0 @@ -# 토마토 -import sys -from collections import deque - -si = sys.stdin.readline - -n, m = map(int, si().split()) - -graph = [list(map(int, si().split())) for _ in range(m)] -dist = [[-1] * n for _ in range(m)] -dxs = [-1, 0, 1, 0] -dys = [0, -1, 0, 1] - -q = deque() - -for i in range(m): - for j in range(n): - if graph[i][j] == 1: - dist[i][j] = 0 - q.append((i, j)) - - -def in_range(x, y): - return 0 <= x < m and 0 <= y < n - - -def can_go(x, y): - return in_range(x, y) and graph[x][y] != -1 and dist[x][y] == -1 - - -def bfs(): - while q: - x, y = q.popleft() - for dx, dy in zip(dxs, dys): - nx = x + dx - ny = y + dy - if can_go(nx, ny): - dist[nx][ny] = dist[x][y] + 1 - q.append((nx, ny)) - - -bfs() - -# print(graph) -# print(dist) - -answer = -sys.maxsize -# 모든 토마토가 익지 않은 경우도 존재 -for i in range(m): - for j in range(n): - # 방문하지 못한 토마토가 존재 - if dist[i][j] == -1 and graph[i][j] == 0: - print(-1) - exit(0) - - else: - answer = max(answer, dist[i][j]) - -print(answer) - - - - - - - - - diff --git "a/easyhooon/4\354\233\2244\354\243\274\354\260\250/9935.py" "b/easyhooon/4\354\233\2244\354\243\274\354\260\250/9935.py" deleted file mode 100644 index e76e5ae..0000000 --- "a/easyhooon/4\354\233\2244\354\243\274\354\260\250/9935.py" +++ /dev/null @@ -1,43 +0,0 @@ -# 문자열 폭발 -# 폭발은 문자열에 폭발 문자열이 없을 때 까지 계속된다. -# 문자열의 길이 최대 1,000,000 -import sys -from collections import deque - -si = sys.stdin.readline - -origin = si().strip() -bomb_origin = si().strip() -bomb_size = len(bomb_origin) -arr = list(origin) -bomb_arr = list(bomb_origin) - -stack = deque() - - -def get_string(): - tmp = [] - for _ in range(bomb_size): - tmp.append(stack.pop()) - - return "".join(reversed(tmp)) - - -for i in range(len(arr)): - stack.append(arr[i]) - # 스택의 원소의 개수가 폭발 문자열보다 많거나, 마지막에 들어온 원소가 폭발 문자열의 마지막 원소인 경우 - # deque 으록 stack 을 구현에서 먼저 들어온 원소가 어떤 인덱스에 들어있는지 헷갈린다. - if len(stack) >= len(bomb_arr) and stack[-1] == bomb_arr[-1]: - # 스택의 끝에서부터 폭발 문자열의 길이 만큼 슬라이싱 해서 판별하고 뽑음 -> stack을 문자열로 통변환해서 시초 - # 원소를 폭발 문자열의 길이만큼 꺼낸 다음에 문자열로 변환해야함 - tmp = get_string() - if tmp != bomb_origin: - for i in range(bomb_size): - stack.append(tmp[i]) - - # print(stack) - -if len(stack) == 0: - print("FRULA") -else: - print("".join(stack)) diff --git "a/easyhooon/4\354\233\2244\354\243\274\354\260\250/\355\215\274\354\246\220 \354\241\260\352\260\201 \354\261\204\354\232\260\352\270\260.py" "b/easyhooon/4\354\233\2244\354\243\274\354\260\250/\355\215\274\354\246\220 \354\241\260\352\260\201 \354\261\204\354\232\260\352\270\260.py" deleted file mode 100644 index cb90717..0000000 --- "a/easyhooon/4\354\233\2244\354\243\274\354\260\250/\355\215\274\354\246\220 \354\241\260\352\260\201 \354\261\204\354\232\260\352\270\260.py" +++ /dev/null @@ -1,150 +0,0 @@ -from collections import deque - -dxs, dys = [-1, 0, 1, 0], [0, -1, 0, 1] - - -# def rotation(puzzle): -# r = len(puzzle) -# c = len(puzzle[0]) -# result = [[0] * r for _ in range(c)] -# for i in range(r): -# for j in range(c): -# result[j][r - 1 - i] = puzzle[i][j] -# return result - - -# 두개의 퍼즐을 인자로 받고 두개가 같은지 확인 -def is_match(puzzle, emptyPuzzle): - r = len(puzzle) - c = len(puzzle[0]) - - er = len(emptyPuzzle) - ec = len(emptyPuzzle[0]) - - if r != er or c != ec: - return False - - for i in range(r): - for j in range(c): - if puzzle[i][j] != emptyPuzzle[i][j]: - return False - - return True - - -# 퍼즐 모양을 포함 하는 가장 작은 직사각형을 만들어 주는 함수 -def trans_puzzle(puzzle_location): - x_min, x_max = 100, -1 - y_min, y_max = 100, -1 - - for (x, y) in puzzle_location: - x_min = min(x_min, x) - x_max = max(x_max, x) - y_min = min(y_min, y) - y_max = max(y_max, y) - - x_len = x_max - x_min + 1 - y_len = y_max - y_min + 1 - - trans = [[0] * y_len for _ in range(x_len)] - - for (x, y) in puzzle_location: - trans[x - x_min][y - y_min] = 1 - - return trans - - -def bfs(i, j, table, visited): - puzzle = [] - n = len(table) - q = deque() - q.append((i, j)) - visited[i][j] = True - puzzle.append((i, j)) - - while q: - x, y = q.popleft() - - for dx, dy in zip(dxs, dys): - nx, ny = x + dx, y + dy - if not (0 <= nx < n and 0 <= ny < n): - continue - if not visited[nx][ny] and table[nx][ny] == 1: - q.append((nx, ny)) - visited[nx][ny] = True - puzzle.append((nx, ny)) - - return puzzle - - -def solution(game_board, table): - n = len(game_board) - answer = 0 - puzzles = [] - # 빈 퍼즐 조각을 담아놓는 배열을 추가 - emptyPuzzles = [] - visited = [[False] * n for _ in range(n)] - puzzle_sum = [] - - for i in range(n): - for j in range(n): - if table[i][j] == 1 and not visited[i][j]: - # 테이블 내에 각각의 퍼즐을 bfs 를 통해 찾아내고 - puzzle_location = bfs(i, j, table, visited) - # 퍼즐 모양을 포함하는 가장 작은 직사각형을 만들어 - puzzle = trans_puzzle(puzzle_location) - # 해당 직사각형을 퍼즐을 저장 하는 배열에 저장 - puzzles.append(puzzle) - # 각 퍼즐의 칸 수도 따로 저장 - puzzle_sum.append(len(puzzle_location)) - - # 이후 방문을 초기화하고 같은 작업을 게임보드에서 진행해서 빈 조각들을 emptyPuzzles에 저장 - visited = [[False] * n for _ in range(n)] - - # 앞에 만들어진 bfs함수와 똑같은 작업을 하기위해 게임보드의 0과 1을 뒤집음 - # 이제 빈 조각은 1로 표기 - for i in range(n): - for j in range(n): - game_board[i][j] = 0 if game_board[i][j] == 1 else 1 - - # bfs를 게임보드에 실행하고 emptyPuzzles에 퍼즐 조각을 담음 - for i in range(n): - for j in range(n): - if game_board[i][j] == 1 and not visited[i][j]: - puzzle_location = bfs(i, j, game_board, visited) - puzzle = trans_puzzle(puzzle_location) - emptyPuzzles.append(puzzle) - - # usedPuzzle 은 사용한 퍼즐을 알아보기 위한 배열 - usedPuzzle = [False for _ in range(len(puzzles) + 1)] - - for emptyPuzzle in emptyPuzzles: - for idx, puzzle in enumerate(puzzles): - # 이미 사용된 퍼즐이라면 넘어감 - if usedPuzzle[idx]: - continue - # 해당 퍼즐 조각이 들어갈 공간을 찾았을 때 확인하는 변수 - find = False - for _ in range(4): - # 시계 방향 회전 - # puzzle = rotation(puzzle) - puzzle = list(zip(*puzzle[::-1])) - - # 게임 보드에 퍼즐을 추가할 수 있는지 확인 - if is_match(puzzle, emptyPuzzle): - # 찾았다면 퍼즐이 사용됬다고 기록하고 - usedPuzzle[idx] = True - # 답을 추가하고 - answer += puzzle_sum[idx] - # 이 빈 공간이 사용됬다고 표기 - find = True - break - - # 퍼즐을 찾았으니 다음 빈공간으로 넘어감 - if find: - break - - return answer - - -print(solution([[1, 1, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0], [0, 1, 1, 0, 0, 1], [1, 1, 0, 1, 1, 1], [1, 0, 0, 0, 1, 0], [0, 1, 1, 1, 0, 0]], [[1, 0, 0, 1, 1, 0], [1, 0, 1, 0, 1, 0], [0, 1, 1, 0, 1, 1], [0, 0, 1, 0, 0, 0], [1, 1, 0, 1, 1, 0], [0, 1, 0, 0, 0, 0]])) \ No newline at end of file diff --git "a/easyhooon/5\354\233\224 2\354\243\274\354\260\250/1052.py" "b/easyhooon/5\354\233\224 2\354\243\274\354\260\250/1052.py" deleted file mode 100644 index a0c0583..0000000 --- "a/easyhooon/5\354\233\224 2\354\243\274\354\260\250/1052.py" +++ /dev/null @@ -1,43 +0,0 @@ -# n 개의 물병을 가지고 있으며, 각 물병에는 무한대로 물을 부을 수 있다. -# 처음엔 모든 병에 물이 1리터씩 들어있고, 이 물병을 다른 장소로 옮기려도 한다. -# 한번에 k 개의 물병을 옮길 수 있다. -# 물 낭비를 하기 싫고, 이동을 한 번보다 많이 하기는 싫다 -# 물병의 물을 적절하게 재분배해서, K개를 넘지 않는 비어있지 않은 물병을 만들려고 함 -# 물을 재분배하는 방법: 같은 양의 물이 들어있는 물병 두개를 고르고, 그 다음에 한 개의 물병에 다른 한 쪽의 물을 모두 부음, 이 방법이 필요한 만큼 계속 수행 -# 새로운 물병을 살 수 있다. -# 상점에서 사야하는 물병의 최솟값 -> 물병의 개수가 k 개가 되었을 때 까지 구매한 물병의 개수 -# 정답이 없을 경우 -1 을 출력 -> 물병의 개수를 k 개 이하로 만들지 못하면 -1 을 출력 - -# 3 1 -# 1 1 1 -> 2 1 -> (물병 구매) 2 1 1 -> 2 2 -> 4 -# 4리터짜리 물병 1개로 만들어 장소를 옮길 수 있음 - -# 13 2 -# 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -# 2 2 2 2 2 2 1 -# 4 4 4 1 -# 8 4 1 -# 8 4 1 (1, 1, 1) -# 8 4 4 -# 8 8 -# 16 - -import sys - - -si = sys.stdin.readline - -# n <= 10^7 -# k <= 10^3 -n, k = map(int, si().split()) -answer = 0 - -while bin(n).count('1') > k: - # 1이 오른쪽에서 몇 번째에 있는지 찾기 - # index('c') -> 가장 작은 인덱스의 c 의 위치를 찾아주는 함수(사야하는 물병의 최솟값을 구하기 위함) - idx = bin(n)[::-1].index('1') - # 2^idx 만큼 answer, n 갱신(비어있는 1 채우기) - answer += 2 ** idx - n += 2 ** idx - -print(answer) diff --git "a/easyhooon/5\354\233\224 2\354\243\274\354\260\250/1091.py" "b/easyhooon/5\354\233\224 2\354\243\274\354\260\250/1091.py" deleted file mode 100644 index 21ad39e..0000000 --- "a/easyhooon/5\354\233\224 2\354\243\274\354\260\250/1091.py" +++ /dev/null @@ -1,35 +0,0 @@ -import sys - -si = sys.stdin.readline - -num = int(si()) -idx = list(map(int, si().split())) -init_state = idx[:] -shuffle = list(map(int, si().split())) - - -def is_sorted(idx, num): - for i in range(num): - if idx[i] != (i % 3): - return False - return True - - -count = 0 - -while not is_sorted(idx, num): - count += 1 - # 카드 섞기 - copy = idx[:] - for i in range(num): - idx[shuffle[i]] = copy[i] - # 카드가 섞기 전 맨 처음 상태인지 확인 - for i in range(num): - if init_state[i] != idx[i]: - break - if i == num - 1: - # 싸이클이 발생, 아무리 섞어도 종료 조건을 충족하지 못함 - print(-1) - exit(0) - -print(count) diff --git "a/easyhooon/5\354\233\224 2\354\243\274\354\260\250/21923.py" "b/easyhooon/5\354\233\224 2\354\243\274\354\260\250/21923.py" deleted file mode 100644 index 08ae739..0000000 --- "a/easyhooon/5\354\233\224 2\354\243\274\354\260\250/21923.py" +++ /dev/null @@ -1,49 +0,0 @@ -import sys - -si = sys.stdin.readline - -INT_MIN = -sys.maxsize - -dirA = [[-1, 0], [0, 1]] -dirB = [[-1, 0], [0, -1]] - -n, m = map(int, si().split()) -board = [list(map(int, si().split())) for _ in range(n)] - -# 전체 배열에 대해 초기화해주고 특정 지점까지 채워주면 된다. -# 초기화 자체를 변곡점에 맞춰 동적으로 범위를 지정해서 해줄 필요가 없다는 의미이다 -# 최대 점수를 구하기 때문에 최소로 초기화 -# 시작점 부터 변곡점 까지 이동할때 최대 비행 점수 -dpA = [[INT_MIN] * m for _ in range(n)] -# 끝점 부터 변곡점 까지 이동할때 최대 비행 점수 -dpB = [[INT_MIN] * m for _ in range(n)] - -# 기저 조건 -dpA[n - 1][0] = board[n - 1][0] - -# 변곡점 이전 -for i in range(n - 1, -1, -1): - for j in range(m): - for k in range(2): - ni = i + dirA[k][0] - nj = j + dirA[k][1] - if 0 <= ni < n and 0 <= nj < m: - dpA[ni][nj] = max(dpA[ni][nj], dpA[i][j] + board[ni][nj]) - -# 기저 조건 -dpB[n - 1][m - 1] = board[n - 1][m - 1] - -# 변곡점 이후 -for i in range(n - 1, -1, -1): - for j in range(m - 1, -1, -1): - for k in range(2): - ni = i + dirB[k][0] - nj = j + dirB[k][1] - if 0 <= ni < n and 0 <= nj < m: - dpB[ni][nj] = max(dpB[ni][nj], dpB[i][j] + board[ni][nj]) - -ans = INT_MIN -for i in range(n): - for j in range(m): - ans = max(ans, dpA[i][j] + dpB[i][j]) -print(ans) diff --git "a/easyhooon/5\354\233\224 2\354\243\274\354\260\250/27940.py" "b/easyhooon/5\354\233\224 2\354\243\274\354\260\250/27940.py" deleted file mode 100644 index b203d0e..0000000 --- "a/easyhooon/5\354\233\224 2\354\243\274\354\260\250/27940.py" +++ /dev/null @@ -1,42 +0,0 @@ -# 농장은 총 n 층 제일 낮은 곳이 1층 높은 곳이 n 층 -# 비를 맞는 층과 그 양을 확인할 수 있음 -# 비는 M번 쏟아지며, i 번째 비가 오는 순간 1층 부터 t층이 동시에 빗물을 각각 ri 만큼 받게 됨 -# 땅에 스며든 비는 증발하지 않음(마지막 비가 내린 직후 까지 누적됨) -# 농장의 각 층은 최대 k 만큼 빗물을 받아도 쓸려 내려가지 않음 -# 만약 어떤 층에 누적된 빗물의 양이 K를 초과한다면 해당 층은 무너짐 -# 비가 와서 무너지는 층이 동시에 여러 곳 발생할 수 있음 -# 농장에 한 층이라도 무너지기 전에 가지를 모두 수확하려고 함, 몇번째 비가 온 직후 어떤 층이 무너지는지 예측 -# 모든 비가 온 후 어떤 층도 무너지지 않으면 -1 을 출력 -# 처음으로 무너지는 층이 발생할때, i 와 무너지는 층을 아무거나 하나 출력 -import sys - -si = sys.stdin.readline - -# n <= 10^5 -# m <= 10^6 -# k <= 2 * 10^9 -# 2 중 포문으로 풀이하면 시초 -# 시간을 줄이는 방법(그리디, 애드 혹) -# 굳이 중간중간에 모든 배열을 다 갱신해줘야 되나, 입력값만으로 판단하면 되는것 아닌가? -# 범위바 1 ~ t 이므로 쨌든 1은 빗물을 받음 -> 1번으로 판단 -n, m, k = map(int, si().split()) -arr = [0] * (n + 1) - -r_sum = 0 -for i in range(1, m + 1): - t, r = map(int, si().split()) - # for j in range(1, t + 1): - # arr[j] += r - # if arr[j] > k: - # print(i, j) - # exit(0) - #print(arr) - r_sum += r - if r_sum > k: - print(i, 1) - exit(0) - -print(-1) - - - diff --git "a/easyhooon/5\354\233\224 2\354\243\274\354\260\250/\355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\354\235\200 \352\261\264\353\254\274.py" "b/easyhooon/5\354\233\224 2\354\243\274\354\260\250/\355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\354\235\200 \352\261\264\353\254\274.py" deleted file mode 100644 index 8ec6f22..0000000 --- "a/easyhooon/5\354\233\224 2\354\243\274\354\260\250/\355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\354\235\200 \352\261\264\353\254\274.py" +++ /dev/null @@ -1,39 +0,0 @@ -def accumulate(board): - # 가로 누적 - for i in range(len(board)): - for j in range(1, len(board[0])): - board[i][j] += board[i][j - 1] - - # 누적된 가로에 대한 세로 누적 - for i in range(1, len(board)): - for j in range(len(board[0])): - board[i][j] += board[i - 1][j] - - -def point_score(board, r1, c1, r2, c2, score): - board[r1][c1] += score - board[r1][c2 + 1] -= score - board[r2 + 1][c1] -= score - # 두번 뺐으므로 다시 더해줌 - board[r2 + 1][c2 + 1] += score - - -def solution(board, skill): - answer = 0 - accumulated_board = [[0] * 1001 for _ in range(1001)] - - for t, r1, c1, r2, c2, degree in skill: - score = degree - if t == 1: - score = -degree - point_score(accumulated_board, r1, c1, r2, c2, score) - - accumulate(accumulated_board) - - for i in range(len(board)): - for j in range(len(board[0])): - board[i][j] += accumulated_board[i][j] - if board[i][j] > 0: - answer += 1 - - return answer \ No newline at end of file diff --git "a/easyhooon/5\354\233\224 3\354\243\274\354\260\250/11508.py" "b/easyhooon/5\354\233\224 3\354\243\274\354\260\250/11508.py" deleted file mode 100644 index 949854c..0000000 --- "a/easyhooon/5\354\233\224 3\354\243\274\354\260\250/11508.py" +++ /dev/null @@ -1,41 +0,0 @@ -# 2 + 1 세일 -# 최소 비용으로 유제품을 구입할 수 있도록 -# 4 -# 3 -# 2 -# 3 -# 2 -# (3, 3, 2), (2) -> 8 - -# 6 -# 6 -# 4 -# 5 -# 5 -# 5 -# 5 -# (6, 5, 5), (5, 5, 4) -> 21 - - -import sys - -si = sys.stdin.readline - -n = int(si()) -arr = [] - -for _ in range(n): - arr.append(int(si())) - -arr.sort(reverse=True) -# print(arr) -arr.insert(0, 0) - -total_sum = sum(arr) -subtract_sum = 0 - -for i in range(1, n + 1): - if i % 3 == 0: - subtract_sum += arr[i] - -print(total_sum - subtract_sum) \ No newline at end of file diff --git "a/easyhooon/5\354\233\224 3\354\243\274\354\260\250/16946.py" "b/easyhooon/5\354\233\224 3\354\243\274\354\260\250/16946.py" deleted file mode 100644 index 236a7b0..0000000 --- "a/easyhooon/5\354\233\224 3\354\243\274\354\260\250/16946.py" +++ /dev/null @@ -1,96 +0,0 @@ -# 벽 부수고 이동하기 4 -# 0: 이동 가능 -# 1: 이동 할 수 없는 벽 -# 이동하려면 두 칸이 인접해야 함 -# 두 칸이 변을 공유할 때 인접하다고 함 - -# 벽을 부수고 이동할 수 있는 곳으로 변경 -# 그 위치에서 이동할 수 있는 칸의 개수를 세어봄 - -# 원래 빈 칸인 곳은 0을 출력, 벽인 곳은 이동할 수 있는 칸의 개수를 10으로 나눈 나머지를 출력 - -# 101 -# 010 -# 101 -# -# 303 -# 050 -# 303 -# -# 11001 -# 00111 -# 01010 -# 10101 -# -# 46003 -# 00732 -# 06040 -# 50403 - -import sys -from collections import deque - -si = sys.stdin.readline - -n, m = map(int, si().split()) - -dxs, dys = [-1, 0, 1, 0], [0, -1, 0, 1] - -graph = [list(map(int, si().strip())) for _ in range(n)] -visited = [[False] * m for _ in range(n)] -zeros = [[0] * m for _ in range(n)] -group_num = 1 -group_size = {} -group_size[0] = 0 - - -def in_range(x, y): - return 0 <= x < n and 0 <= y < m - - -def can_go(x, y): - return in_range(x, y) and not visited[x][y] and graph[x][y] == 0 - - -def bfs(i, j): - q = deque() - q.append((i, j)) - cnt = 1 - while q: - x, y = q.popleft() - zeros[x][y] = group_num - for dx, dy in zip(dxs, dys): - nx, ny = x + dx, y + dy - if can_go(nx, ny): - visited[nx][ny] = True - q.append((nx, ny)) - cnt += 1 - return cnt - - -for i in range(n): - for j in range(m): - if graph[i][j] == 0 and not visited[i][j]: - visited[i][j] = True - size = bfs(i, j) - group_size[group_num] = size - group_num += 1 - -for x in range(n): - for y in range(m): - if graph[x][y] == 1: - # 그룹 중복 누적을 막기 위해 - temp = set() - for dx, dy in zip(dxs, dys): - nx, ny = x + dx, y + dy - if in_range(nx, ny): - temp.add(zeros[nx][ny]) - - for elem in temp: - graph[x][y] += group_size[elem] - graph[x][y] %= 10 - -for i in range(n): - for j in range(m): - print(graph[i][j], end="") - print() \ No newline at end of file diff --git "a/easyhooon/5\354\233\224 3\354\243\274\354\260\250/1759.py" "b/easyhooon/5\354\233\224 3\354\243\274\354\260\250/1759.py" deleted file mode 100644 index f6ec50f..0000000 --- "a/easyhooon/5\354\233\224 3\354\243\274\354\260\250/1759.py" +++ /dev/null @@ -1,48 +0,0 @@ -# 암호 만들기 -import sys - -# 증가하는 순 -> 순서가 정해져 있다 (순열) -# 더 나은 풀이 확인 - -si = sys.stdin.readline - -l, c = map(int, si().split()) - -selected = [0] -alphabets = [" "] + list(map(str, si().split())) -visited = [False] * (c + 1) -alphabets.sort() - - -def is_vowel(x): - return x == 'a' or x == 'e' or x == 'i' or x == 'o' or x == 'u' - - -def dfs(k): - if k == l + 1: - vowel = 0 - consonant = 0 - - for i in range(1, l + 1): - if is_vowel(alphabets[selected[i]]): - vowel += 1 - else: - consonant += 1 - - if vowel >= 1 and consonant >= 2: - answer = "" - for i in range(1, l + 1): - answer += alphabets[selected[i]] - print(answer) - - for i in range(1, c + 1): - # 이전에 뽑은 값과도 비교가 필요 - if not visited[i] and i > selected[k - 1]: - selected.append(i) - visited[i] = True - dfs(k + 1) - visited[i] = False - selected.pop() - - -dfs(1) \ No newline at end of file diff --git "a/easyhooon/5\354\233\224 3\354\243\274\354\260\250/2503.py" "b/easyhooon/5\354\233\224 3\354\243\274\354\260\250/2503.py" deleted file mode 100644 index 390fd1f..0000000 --- "a/easyhooon/5\354\233\224 3\354\243\274\354\260\250/2503.py" +++ /dev/null @@ -1,43 +0,0 @@ -# 숫자 야구 -import sys - -si = sys.stdin.readline - -n = int(si()) - -# preprocess -nums = [] -for i in range(123, 988): - num = str(i) - # 0 이 존재하거나, 같은 숫자가 반복되어 나오는 경우 제외 - if '0' not in num and len(set(num)) == 3: - nums.append(num) - - -def check(test, num, strike, ball): - strike_count = 0 - for i in range(3): - if str(test)[i] == str(num)[i]: - strike_count += 1 - - ball_count = 0 - for s in test: - if s in num: - ball_count += 1 - - ball_count -= strike_count - - return (strike_count == strike) and (ball_count == ball) - - -for _ in range(n): - test, strike, ball = map(int, si().split()) - test = str(test) - - new_nums = [] - for num in nums: - if check(test, num, strike, ball): - new_nums.append(num) - nums = new_nums - -print(len(nums)) diff --git "a/easyhooon/5\354\233\224 3\354\243\274\354\260\250/3020.py" "b/easyhooon/5\354\233\224 3\354\243\274\354\260\250/3020.py" deleted file mode 100644 index 4ec68a1..0000000 --- "a/easyhooon/5\354\233\224 3\354\243\274\354\260\250/3020.py" +++ /dev/null @@ -1,37 +0,0 @@ -# 개똥 벌래 -import sys -import bisect - -si = sys.stdin.readline - -INT_MAX = sys.maxsize - -n, h = map(int, si().split()) -top = [] -bottom = [] -result = INT_MAX -result_cnt = 0 - -for i in range(n // 2): - top.append(int(si())) - bottom.append(int(si())) - -top.sort() -bottom.sort() - -for i in range(1, h + 1): - # 충돌하지 않는 장애물 수를 구함 - # 정렬된 순서를 유지하며 i 를 top에 삽입할 때, 가장 왼쪽 인덱스 - lower_bound = bisect.bisect_left(top, i) - # 정렬된 순서를 유지하며 h-i 를 bottom에 삽입할 때, 가장 오른쪽 인덱스 반환 - upper_bound = bisect.bisect_right(bottom, h - i) - # 전체에서 장애물 중에서 충돌 하지 않을 장애물 수를 빼서 충돌할 장애물 수를 구함 - cnt = n - (lower_bound + upper_bound) - - if result == cnt: - result_cnt += 1 - elif result > cnt: - result = cnt - result_cnt = 1 - -print(result, result_cnt) diff --git "a/easyhooon/5\354\233\224 3\354\243\274\354\260\250/\355\203\235\353\260\260 \353\260\260\353\213\254\352\263\274 \354\210\230\352\261\260\355\225\230\352\270\260.py" "b/easyhooon/5\354\233\224 3\354\243\274\354\260\250/\355\203\235\353\260\260 \353\260\260\353\213\254\352\263\274 \354\210\230\352\261\260\355\225\230\352\270\260.py" deleted file mode 100644 index 52f2e28..0000000 --- "a/easyhooon/5\354\233\224 3\354\243\274\354\260\250/\355\203\235\353\260\260 \353\260\260\353\213\254\352\263\274 \354\210\230\352\261\260\355\225\230\352\270\260.py" +++ /dev/null @@ -1,18 +0,0 @@ -def solution(cap, n, deliveries, pickups): - deliveries = deliveries[::-1] - pickups = pickups[::-1] - answer = 0 - - have_to_deli = 0 - have_to_pick = 0 - - for i in range(n): - have_to_deli += deliveries[i] - have_to_pick += pickups[i] - - while have_to_deli > 0 or have_to_pick > 0: - have_to_deli -= cap - have_to_pick -= cap - answer += (n - i) * 2 - - return answer \ No newline at end of file diff --git "a/easyhooon/5\354\233\2241\354\243\274\354\260\250/1043.py" "b/easyhooon/5\354\233\2241\354\243\274\354\260\250/1043.py" deleted file mode 100644 index f6644e2..0000000 --- "a/easyhooon/5\354\233\2241\354\243\274\354\260\250/1043.py" +++ /dev/null @@ -1,94 +0,0 @@ -# 거짓말 - -# 이야기의 진실을 아는 사람들에겐 진실을 이야기 할 수 밖에 없다 -# 어떤 사람이 어떤 파티에서는 진실을 듣고, 또 다른 파티에서는 과장된 이야기를 들었을 때도, 지민이는 거짓말쟁이로 알려지게 된다. -# 지민이는 모든 파티에 참가 -# 거짓말쟁이로 알려지지 않으면서, 과장된 이야기를 할 수 있는 파티 개수의 최댓값 - -import sys - -si = sys.stdin.readline - -# 사람의 수, 파티의 수 -n, m = map(int, si().split()) -uf = [0] * (n + 1) - -for i in range(1, n + 1): - uf[i] = i - - -def union(x, y): - x = find(x) - y = find(y) - # 이렇게 판단 과정을 내리면 안될거 같은게 이후의 파티가 이전 파티에 영향을 미치지 못하고 있음 - # -> 마지막에 검사할대 find 를 한번 더 돌려주면 됨 - if x in true_arr and y not in true_arr: - uf[y] = x - - elif y in true_arr and x not in true_arr: - uf[x] = y - - elif x in true_arr and y in true_arr: - return - else: - min_num = min(x, y) - max_num = max(x, y) - uf[max_num] = min_num - - -def find(x): - if uf[x] == x: - return x - - root_node = find(uf[x]) - uf[x] = root_node - - return root_node - -# 이야기의 진실을 아는 사람의 수, 목록 -# 진실을 아는 사람이 존재하면 해당 파티에는 과장을 못함 -# 진실을 아는 사람이 없는 파티만을 체크하면 됨 -true_arr = list(map(int, si().split())) - -# 진실을 아는 사람이 없으면 모든 파티에 과장된 이야기 가능 -if true_arr[0] == 0: - print(m) - exit(0) - -true_arr = true_arr[1:] - -parties = [] - -# 각 파티마다 오는 사람의 수와 번호 -# 쭉 나열되어 있어서 짝짓는게 까다롭네 -# i, i + 1 로 하자 ㅇㅇ -for _ in range(m): - party = list(map(int, si().split())) - if party[0] != 1: - for i in range(1, party[0]): - # print(party[i], party[i + 1]) - union(party[i], party[i + 1]) - - parties.append(party[1:]) - -# 과장된 이야기를 할 수 있는 '파티 수', '사람 수' (x) -answer = 0 - -# print(true_arr) - -for party in parties: - # print(party) - flag = True - for elem in party: - # if uf[elem] in true_arr: - if find(elem) in true_arr: - flag = False - break - - if flag: - answer += 1 - - -# print(uf) -print(answer) - diff --git "a/easyhooon/5\354\233\2241\354\243\274\354\260\250/1106.py" "b/easyhooon/5\354\233\2241\354\243\274\354\260\250/1106.py" deleted file mode 100644 index c24d95e..0000000 --- "a/easyhooon/5\354\233\2241\354\243\274\354\260\250/1106.py" +++ /dev/null @@ -1,68 +0,0 @@ -# 호텔 -# 돈에 정수배 만큼을 투자할 수 있다. -# -> 동일한 보석을 여러개 고르는 것을 허용 -# 고객을 적어도 C 명 늘리기 위해 형택이가 투자해야 하는 돈의 '최솟값' -# 돈, 즉 무게의 최솟값을 구하는 문제 -# -> 무게의 제한이 문제에 존재하지 않는다. -# i 원으로 얻을 수 있는 고객이 j 명일 때, C명을 늘릴 수 있는 가장 작은 i원 를 구하는 문제 -# C, 늘리고자 하는 고객의 숫자 <= 1000 -# N, 도시의 개수(종류) <= 20 <- 숫자가 유의미하게 작다. 중요 포인트 -# dp[i] := i 만큼 비용을 사용했을 때, 얻을 수 있는 고객의 최대값 -# 최대 비용 -# C가 1000명이고, 도시를 홍보할 때 필요한 비용이 100원, 이때 얻을 수 있는 고객이 1명인 경우 -# -> 100 * 1000 -> 100,000 - -# 12 2 -# 3 5 -# 1 1 -# (6, 10) + (2, 2) - -# 10 3 -# 3 1 -# 2 2 -# 1 3 -# (2, 6) + (4, 4) - - -import sys - -si = sys.stdin.readline - -INT_MIN = -sys.maxsize - - -# c <= 1000 -# n <= 20 -c, n = map(int, si().split()) - -weight = [0] * (n + 1) -value = [0] * (n + 1) - -for i in range(1, n + 1): - w, v = map(int, si().split()) - weight[i] = w - value[i] = v - -# dp = [INT_MIN] * (c + 1) -dp = [INT_MIN] * 100001 -dp[0] = 0 - -# 무게를 i 만큼 썼을때 얻을 수 있는 가치의 최대 값을 구할 때 사용하는 방법 -# 무게의 범위 <= 100,000 -for i in range(1, 100001): - for j in range(1, n + 1): - if weight[j] > i: - dp[i] = max(dp[i], dp[i - 1]) - else: - dp[i] = max(dp[i], dp[i - weight[j]] + value[j]) - - -# print(dp) -# print(c) - -for i in range(1, 100001): - # print(dp[i]) - if dp[i] >= c: - print(i) - exit(0) - diff --git "a/easyhooon/5\354\233\2241\354\243\274\354\260\250/1202.py" "b/easyhooon/5\354\233\2241\354\243\274\354\260\250/1202.py" deleted file mode 100644 index 4e3bc7a..0000000 --- "a/easyhooon/5\354\233\2241\354\243\274\354\260\250/1202.py" +++ /dev/null @@ -1,81 +0,0 @@ -# 보석 도둑 -# 정석적인 냅색? 근데 왜 골드 2지 -# 아 이번엔 가방이 1개가 아니라 k 개이다... -# 가방에는 최대 '한개'의 보석만 넣을 수 있다. -# 훔칠 수 있는 보석 가격의 합의 최댓값 -# dp 가 아니라고?? -# 가장 가치가 큰 보석부터 넣을 수 있는 가방에 하나씩 넣어주기 - -# 2 1 -# 5 10 -# 100 100 -# 11 - -# (5, 10) 한 개만 넣을 수 있어서 10 - -# 3 2 -# 1 65 -# 5 23 -# 2 99 -# 10 -# 2 - -# (65 + 23 + 99) + (99) -# 가 아니라(보석을 다른 가방에 이미 넣었다면, 그 보석은 다른 가방에 넣을 수 없음) -# 65 + 95 = 164 -# 동일한 상태를 정의하기 위한 요소 -# i 번째 가방 까지 고려하였을 때, j번 보석을 넣었고, 가격의 합이 같은 경우 -import sys -import heapq - -si = sys.stdin.readline - -# n 보석의 개수 <= 300,000 -# k 가방의 개수 <= 300,000 -n, k = map(int, si().split()) - -jews = [] -bags = [] - -for _ in range(n): - m, v = map(int, si().split()) - jews.append((m, v)) - -for _ in range(k): - c = int(si()) - bags.append(c) - -jews.sort() -bags.sort() - -answer = 0 -pq = [] - -# 문제: 무조건 가치가 큰걸 무게를 많이 담을 수 있는 가방에 넣는건 옳지 않다 -# 괜히 가치가 큰걸 무게 많이 담을 수 있는 가방에 넣으면, 나머지 보석들을 못넣을 수 있다. 한 개씩 넣는거라 딱 맞는거에 넣는게 베스트일 수 도 -# 2 2 -# 5 100 -# 50 10 -# 50 -# 20 - -# (5, 100)을 20에 넣고, (50, 10) 을 50에 넣으면 됨 -# 가장 적절한 가방을 찾는 방법이 뭘까 -# 가장 적게 담을 수 있는 가방 부터 보석을 넣어야 함 -# 가장 적게 담을 수 있는 가방에 넣을 수 있는 보석중 가장 가치가 큰 보석을 넣는 행위를 반복! - -for i in range(k): - # 보석이 존재하고, 가방에 담을 수 있는 보석이 있을 때 - while jews and jews[0][0] <= bags[i]: - # 해당 보석들의 가격을 최대 힙으로 저장 - heapq.heappush(pq, -jews[0][1]) - # 최대 힙에 넣은 보석 제거 - heapq.heappop(jews) - - if pq: - # 가방에 담을 수 있는 보석 중 가장 가치가 큰 보석을 빼냄 - max_value_jew = -heapq.heappop(pq) - # 정답을 갱신 - answer += max_value_jew - -print(answer) diff --git "a/easyhooon/5\354\233\2241\354\243\274\354\260\250/16724.py" "b/easyhooon/5\354\233\2241\354\243\274\354\260\250/16724.py" deleted file mode 100644 index 9c9cef2..0000000 --- "a/easyhooon/5\354\233\2241\354\243\274\354\260\250/16724.py" +++ /dev/null @@ -1,78 +0,0 @@ -# 피리 부는 사나이 -# 지도 어느 구역에 있더라도, 피리를 불때, SAFE ZONE 으로 들어갈 수 있게 하는 SAFE ZONE 의 '최소' 개수 -# 순환 -> 사이클 -# 격자 좌표가 있어서 유파일거라고 생각을 못했음 -> 격자 탐색 + 유파 (백조의 호수 쉬운 버전) - -import sys - -si = sys.stdin.readline - -n, m = map(int, si().split()) -graph = [list(si().strip()) for _ in range(n)] -visited = [[False] * m for _ in range(n)] -uf = [[(x, y) for y in range(m)] for x in range(n)] - -# print(uf) - -dxs = [-1, 1, 0, 0] -dys = [0, 0, -1, 1] - - -def union(curr, next): - x, y = find(curr[0], curr[1]) - nx, ny = find(next[0], next[1]) - - uf[x][y] = (nx, ny) - - -def find(x, y): - if (x, y) == uf[x][y]: - return (x, y) - - uf[x][y] = find(uf[x][y][0], uf[x][y][1]) - return uf[x][y] - - -def dfs(x, y): - global answer - - nx, ny = x, y - if graph[x][y] == "U": - nx, ny = x + dxs[0], y + dys[0] - elif graph[x][y] == "D": - nx, ny = x + dxs[1], y + dys[1] - elif graph[x][y] == "L": - nx, ny = x + dxs[2], y + dys[2] - elif graph[x][y] == "R": - nx, ny = x + dxs[3], y + dys[3] - - next_root = find(nx, ny) - # 사이클이 아니라면 - if next_root == (nx, ny) and graph[nx][ny] != "C": - union((x, y), (nx, ny)) - visited[nx][ny] = True - dfs(nx, ny) - - else: - # 새 사이클 형성 - if next_root == (x, y): - graph[x][y] = "C" - answer += 1 - return - - # 기존의 사이클에 포함 - else: - union((x, y), (nx, ny)) - return - -# 시이클의 개수 -answer = 0 - -for i in range(n): - for j in range(m): - if not visited[i][j]: - visited[i][j] = True - dfs(i, j) - -# print(graph) -print(answer) diff --git "a/easyhooon/5\354\233\2241\354\243\274\354\260\250/2141(fail).py" "b/easyhooon/5\354\233\2241\354\243\274\354\260\250/2141(fail).py" deleted file mode 100644 index cca6dde..0000000 --- "a/easyhooon/5\354\233\2241\354\243\274\354\260\250/2141(fail).py" +++ /dev/null @@ -1,54 +0,0 @@ -# 우체국 -# 각 사람들까지의 거리의 합이 '최소'가 되는 위치에 우체국을 세운다. -# 가능한 경우가 여러가지 인 경우 더 작은 위치를 출력하도록 한다. -# 파라매트릭 서치인가 -# mid 에 우체국을 세울때 각 사람들까지의 거리의 합이 최소인가? 로 문제를 변형 - -import sys - -si = sys.stdin.readline - -INT_MAX = sys.maxsize - -n = int(si()) - -location = [0] * (n + 1) -personnel = [0] * (n + 1) - -for i in range(1, n + 1): - x, a = map(int, si().split()) - location[i] = x - personnel[i] = a - -left = 0 -right = 1_000_000_000 -min_distance_sum = INT_MAX -answer = 0 - - -def get_distance_sum(mid): - # 각 사람들로 부터 위치의 합을 구함 - length = 0 - for i in range(1, n + 1): - length += abs(location[i] - mid) * personnel[i] - - # 더 작은 지점 - return length - - -# 아 mid 는 결과 값이 아니다.. -while left <= right: - mid = (left + right) // 2 - distance_sum = get_distance_sum(mid) - - if distance_sum <= min_distance_sum: - # 최소를 구하는 것이기 때문에 - min_distance_sum = distance_sum - answer = mid - right = mid - 1 - # print(left, right, mid) - else: - left = mid + 1 - - -print(answer) \ No newline at end of file diff --git "a/easyhooon/5\354\233\2244\354\243\274\354\260\250/1342.py" "b/easyhooon/5\354\233\2244\354\243\274\354\260\250/1342.py" deleted file mode 100644 index c03cb5d..0000000 --- "a/easyhooon/5\354\233\2244\354\243\274\354\260\250/1342.py" +++ /dev/null @@ -1,32 +0,0 @@ -import sys -from collections import Counter - -si = sys.stdin.readline - - -def dfs(curr_num, pre): - global answer - - # 행운의 문자열 생성 - if curr_num == len(s): - answer += 1 - - for k in cnt.keys(): - # 현재 단어가 이전 단어일 경우와 현재 단어의 개수가 0일 경우 다음 단어를 확인 - if k == pre or cnt[k] == 0: - continue - - cnt[k] -= 1 - dfs(curr_num + 1, k) - cnt[k] += 1 - - -s = list(map(str, si().strip())) - -# 문자의 개수를 딕셔너리로 변환 -cnt = Counter(s) -answer = 0 - -dfs(0, '') - -print(answer) \ No newline at end of file diff --git "a/easyhooon/5\354\233\2244\354\243\274\354\260\250/14620.py" "b/easyhooon/5\354\233\2244\354\243\274\354\260\250/14620.py" deleted file mode 100644 index 9fec0de..0000000 --- "a/easyhooon/5\354\233\2244\354\243\274\354\260\250/14620.py" +++ /dev/null @@ -1,81 +0,0 @@ -# 꽃길 -# 꽃잎이 닿게 될 경우 두 꽃 모두 죽어버린다, 화단에 꽃잎이 나가버려도 -# 서로 다른 세 씨앗이 모두 꽃 피게 하면서 가장 싼 각겨에 화단을 대여 -# 꽃 하나당 5평 -import sys - -INT_MAX = sys.maxsize - -si = sys.stdin.readline - -n = int(si()) -graph = [list(map(int, si().split())) for _ in range(n)] -visited = [[0] * n for _ in range(n)] - -flower = [] -# 꽃 씨앗의 위치를 정하고 -# 겹치지 않게 잘 심었으면 최솟값 갱신 - -min_cost_sum = INT_MAX - -dxs = [-1, 0, 1, 0] -dys = [0, -1, 0, 1] - - -def in_range(x, y): - return 0 <= x < n and 0 <= y < n - - -def can_seed(x, y): - flag = True - for dx, dy in zip(dxs, dys): - nx = x + dx - ny = y + dy - if not in_range(nx, ny) or visited[nx][ny]: - flag = False - return flag - - return flag - - -def get_cost_sum(): - cost_sum = 0 - for (x, y) in flower: - cost_sum += graph[x][y] - for dx, dy in zip(dxs, dys): - nx = x + dx - ny = y + dy - cost_sum += graph[nx][ny] - - return cost_sum - - -def dfs(curr_num): - global min_cost_sum - if curr_num == 3: - # print(flower, get_cost_sum()) - min_cost_sum = min(min_cost_sum, get_cost_sum()) - return - - for i in range(n): - for j in range(n): - if not visited[i][j] and can_seed(i, j): - visited[i][j] = True - for di, dj in zip(dxs, dys): - ni = i + di - nj = j + dj - visited[ni][nj] = True - - flower.append((i, j)) - dfs(curr_num + 1) - flower.pop() - - visited[i][j] = False - for di, dj in zip(dxs, dys): - ni = i + di - nj = j + dj - visited[ni][nj] = False - - -dfs(0) -print(min_cost_sum) \ No newline at end of file diff --git "a/easyhooon/5\354\233\2244\354\243\274\354\260\250/1577.py" "b/easyhooon/5\354\233\2244\354\243\274\354\260\250/1577.py" deleted file mode 100644 index 0e63236..0000000 --- "a/easyhooon/5\354\233\2244\354\243\274\354\260\250/1577.py" +++ /dev/null @@ -1,59 +0,0 @@ -import sys - -si = sys.stdin.readline - -dxs = [1, 0] -dys = [0, 1] - -n, m = map(int, si().split()) -k = int(si()) - -construct = set() - -for _ in range(k): - sx, sy, ex, ey = map(int, si().split()) - construct.add((sx, sy, ex, ey)) - construct.add((ex, ey, sx, sy)) - -# dp[i][j] := i, j 까지 도달할 수 있는 가지 수 -dp = [[0] * (m + 1) for _ in range(n + 1)] - -# 초기 조건에 길이 막히면 그 이후로 채우면 안됨 -# 여기가 인덱스 문제가 있는 듯(틀린 이유) -# for i in range(n + 1): -# if (i, 0, i + 1, 0) in construct: -# break -# else: -# dp[i][0] = 1 -# -# for j in range(m + 1): -# if (0, j, 0, j + 1) in construct: -# break -# else: -# dp[0][j] = 1 - -dp[0][0] = 1 -# 초기 조건에 길이 막히면 그 이후로 채우면 안됨 -for i in range(1, n + 1): - if (i - 1, 0, i, 0) in construct: - break - else: - dp[i][0] = 1 -for j in range(1, m + 1): - if (0, j - 1, 0, j) in construct: - break - else: - dp[0][j] = 1 - -# 1. 위에서 내려오는 거 -# 2. 왼쪽에서 오른쪽 -# 탑 다운이 더 직관적일 것 같은데.. -for i in range(1, n + 1): - for j in range(1, m + 1): - # (이동 시작 지점과 이동 후 지점이 모두 공사 중일 경우) 가 아닌 경우 - if not ((i - 1, j, i, j) in construct): - dp[i][j] += dp[i - 1][j] - if not ((i, j - 1, i, j) in construct): - dp[i][j] += dp[i][j - 1] - -print(dp[n][m]) diff --git "a/easyhooon/5\354\233\2244\354\243\274\354\260\250/\352\270\260\353\221\245\352\263\274 \353\263\264 \354\204\244\354\271\230.py" "b/easyhooon/5\354\233\2244\354\243\274\354\260\250/\352\270\260\353\221\245\352\263\274 \353\263\264 \354\204\244\354\271\230.py" deleted file mode 100644 index cfe79f7..0000000 --- "a/easyhooon/5\354\233\2244\354\243\274\354\260\250/\352\270\260\353\221\245\352\263\274 \353\263\264 \354\204\244\354\271\230.py" +++ /dev/null @@ -1,93 +0,0 @@ - -def solution(n, build_frame): - answer = [] - - # a: 구조물의 종류 0 -> 기둥, 1 -> 보 - # b: 구조물을 설치 할지 말지 0 -> 삭제, 1 -> 설치 - for x, y, a, b in build_frame: - # 기둥 설치 - if b == 1 and a == 0: - # 바닥에 있는 경우 무조건 설치 가능 - if y == 0: - answer.append([x, y, a]) - - # 바닥에 있지 않은 경우 - else: - # 해당 지점 밑에 기둥이 있는 경우 - temp = [x, y - 1, 0] - # 해당 지점 밑 왼쪽에 보가 있는 경우 - temp2 = [x - 1, y, 1] - # 해당 지점 밑 오른쪽에 보가 있는 경우 - temp3 = [x, y, 1] - - if temp in answer or temp2 in answer or temp3 in answer: - answer.append([x, y, a]) - # 보 설치 - elif b == 1 and a == 1: - # 왼쪽 아래 기둥 설치 - temp = [x, y - 1, 0] - # 오른쪽 아래 기둥 설치 - temp2 = [x + 1, y - 1, 0] - # 왼쪽에 보 설치 - temp3 = [x - 1, y, 1] - # 오른쪽 보 설치 - temp4 = [x + 1, y, 1] - - if (temp in answer) or (temp2 in answer) or (temp3 in answer and temp4 in answer): - answer.append([x, y, a]) - - # 기둥 제거 - elif b == 0 and a == 0: - # 위에 기둥이 있다면 - if [x, y + 1, 0] in answer: - # 왼쪽 오른쪽 바쳐 줄 수 없다면 - if [x - 1, y + 1, 1] not in answer and [x, y + 1, 1] not in answer: - continue - - # 오른쪽 위 보가 있다면 - if [x, y + 1, 1] in answer: - # 다른쪽 기둥이 버티고 있지 않거나 양쪽 보가 연결 되어 있지 않다면 - if [x + 1, y, 0] not in answer and ([x + 1, y + 1, 1] not in answer or [x - 1, y + 1, 1] not in answer): - continue - - # 왼쪽 위 보가 있다면 - if [x - 1, y + 1, 1] in answer: - # 다른쪽 기둥이 버티고 있지 않거나 양쪽 보가 연결 되어 있지 않다면 - if [x - 1, y, 0] not in answer and ([x, y + 1, 1] not in answer or [x - 2, y + 1, 1] not in answer): - continue - - # 다른 곳으로 인해 버티기 가능 - answer.pop(answer.index([x, y, a])) - - # 보 제거 - elif b == 0 and a == 1: - # 왼쪽 위 기둥이 있다면 - if [x, y, 0] in answer: - # 아래쪽 기둥도 없고 왼쪽에 바쳐줄 보도 없다면 - if [x, y - 1, 0] not in answer and [x - 1, y, 1] not in answer: - continue - - # 오른쪽 위 기둥이 있다면 - if [x + 1, y, 0] in answer: - # 아래쪽 기둥도 없고 오른쪽에 바쳐줄 보도 없다면 - if [x + 1, y - 1, 0] not in answer and [x + 1, y, 1] not in answer: - continue - - # 왼쪽에 보가 있다면 - if [x - 1, y, 1] in answer: - # 아래 둘다 기둥이 없다면 - if [x - 1, y - 1, 0] not in answer and [x, y - 1, 0] not in answer: - continue - - # 오른쪽에 보가 있다면 - if [x + 1, y, 1] in answer: - # 아래 둘다 기둥이 없다면 - if [x + 1, y - 1, 0] not in answer and [x + 2, y - 1, 0] not in answer: - continue - - # 다른 곳으로 인해 버티기 가능 - answer.pop(answer.index([x, y, a])) - - answer.sort(key=lambda x: (x[0], x[1], x[2])) - - return answer \ No newline at end of file diff --git "a/easyhooon/5\354\233\2244\354\243\274\354\260\250/\354\213\240\352\267\234 \354\225\204\354\235\264\353\224\224 \354\266\224\354\262\234.py" "b/easyhooon/5\354\233\2244\354\243\274\354\260\250/\354\213\240\352\267\234 \354\225\204\354\235\264\353\224\224 \354\266\224\354\262\234.py" deleted file mode 100644 index ca6a72a..0000000 --- "a/easyhooon/5\354\233\2244\354\243\274\354\260\250/\354\213\240\352\267\234 \354\225\204\354\235\264\353\224\224 \354\266\224\354\262\234.py" +++ /dev/null @@ -1,29 +0,0 @@ -import re - - -def solution(new_id): - # 1단계: 소문자로 치환 - new_id = new_id.lower() - - # 2단계: 알파벳 소문자, 숫자, -, _, .를 제외한 모든 문자 제거 - new_id = re.sub('[^a-z0-9-_.]', '', new_id) - - # 3단계: .가 2번 이상 연속된 부분을 하나의 .로 치환 - new_id = re.sub('\.+', '.', new_id) - - # 4단계: 문자열의 앞뒤에 위치한 . 제거 - new_id = new_id.strip('.') - - # 5단계: 빈 문자열 이라면 a를 대입 - if new_id == '': - new_id = 'a' - - # 6단계: 길이가 16자 이상이면 첫 15개의 문자를 제외한 나머지 문자들을 모두 제거 - if len(new_id) >= 16: - new_id = new_id[:15] - new_id = new_id.rstrip('.') - - # 7단계: 길이가 2자 이하라면, 마지막 문자를 길이가 3이 될 때까지 반복해서 끝에 붙임 - while len(new_id) < 3: - new_id += new_id[-1] - return new_id diff --git "a/easyhooon/5\354\233\2245\354\243\274\354\260\250/13164.py" "b/easyhooon/5\354\233\2245\354\243\274\354\260\250/13164.py" deleted file mode 100644 index 5a309a5..0000000 --- "a/easyhooon/5\354\233\2245\354\243\274\354\260\250/13164.py" +++ /dev/null @@ -1,33 +0,0 @@ -# 행복 유치원 - -# 키 순서대로 일렬로 세우고 k 개의 조로 나눔 -# 각 조에는 원생이 최소 한명, 같은 조에 속한 원생들은 서로 인접 -# 조마다 티셔츠를 맞추는 비용 = (가장 키가 큰 원생 - 가장 키가 작은 원생), 혼자면 비용이 없나보다 -# 티셔츠를 만드는 비용의 합을 최소로 -# 원생의 수 <= 30만 -> 2중 포문 불가능 -# 처음 부터 정렬 되어 입력 됨 -# 5 3 -# (1, 3), (5, 6) 10 -# 2 + 1 = 3 -# 2 2 1 4 -# 3 팀으로 나눴다 -> 2 지점을 택해서 잘랐다 -import sys - -si = sys.stdin.readline - -n, k = map(int, si().split()) - -nums = list(map(int, si().split())) - -diff = [] - -for i in range(1, n): - diff.append(nums[i] - nums[i - 1]) - -diff.sort() - -answer = 0 -for i in range(n - k): - answer += diff[i] - -print(answer) \ No newline at end of file diff --git "a/easyhooon/5\354\233\2245\354\243\274\354\260\250/2023.py" "b/easyhooon/5\354\233\2245\354\243\274\354\260\250/2023.py" deleted file mode 100644 index f467681..0000000 --- "a/easyhooon/5\354\233\2245\354\243\274\354\260\250/2023.py" +++ /dev/null @@ -1,37 +0,0 @@ -# 신기한 소수 - -import sys - -si = sys.stdin.readline - -n = int(si()) - -candidate_number = [1, 2, 3, 5, 7, 9] - - -def is_prime(num): - if num < 2: - return False - - for i in range(2, int(num ** 0.5) + 1): - if num % i == 0: - return False - - return True - - -def dfs(curr_num, num): - if curr_num == n: - print(num) - return - - for elem in candidate_number: - num = num * 10 + elem - # 소수 판정 - if is_prime(num): - dfs(curr_num + 1, num) - num -= elem - num //= 10 - - -dfs(0, 0) \ No newline at end of file diff --git "a/easyhooon/5\354\233\2245\354\243\274\354\260\250/2212.py" "b/easyhooon/5\354\233\2245\354\243\274\354\260\250/2212.py" deleted file mode 100644 index 8e84270..0000000 --- "a/easyhooon/5\354\233\2245\354\243\274\354\260\250/2212.py" +++ /dev/null @@ -1,42 +0,0 @@ -# 센서 - -# 고속도로 위에 n 개의 센서를 설치 -# 최대 k 개의 집중국을 설치 -# n 개의 센서가 적어도 하나의 집중국과는 통신이 가능해야 함 -# 집중국의 유지비 문제로 인해 각 집중국의 수신 가능 영역의 길이의 '합'을 최소화 -# 6 -# 2 -# 1 6 9 3 6 7 -# 센서의 좌표가 한 개의 정수로 n 개 주어짐 -# 1 3 (6, 6), 7, 9 - -# 하나의 집중국이 1 ~ 3 = 2 -# 다른 하나가 6 ~ 9 = 3 -# 5 최소 - -import sys - -si = sys.stdin.readline - -# n <= 10000 -n = int(si()) -# k <= 1000 -k = int(si()) - -nums = list(map(int, si().split())) - -nums.sort() - -if k >= n: - print(0) - exit(0) - -dist = [] -for i in range(1, n): - dist.append(nums[i] - nums[i - 1]) - -dist.sort(reverse=True) -for _ in range(k - 1): - dist.pop(0) - -print(sum(dist)) diff --git "a/easyhooon/5\354\233\2245\354\243\274\354\260\250/25682.py" "b/easyhooon/5\354\233\2245\354\243\274\354\260\250/25682.py" deleted file mode 100644 index fc355cc..0000000 --- "a/easyhooon/5\354\233\2245\354\243\274\354\260\250/25682.py" +++ /dev/null @@ -1,47 +0,0 @@ -# 체스판 다시 칠하기2 - -import sys - -si = sys.stdin.readline - -# n, m <= 2000 -> 판의 최대 칸 수 400만 -n, m, k = map(int, si().split()) - -board = [list(si().strip()) for _ in range(n)] - - -# k x k 정사각형을 만든다 -# 다시 칠해야 하는 칸의 개수를 센다 -# 최소 개수를 갱신한다 -> 시간 초과 - -# 다시 칠해야 하는 칸의 누적합을 먼저 구하고 -# k x k 정사각형을 순회하며 최소 개수를 갱신한다. - - -def get_min_repaint_count(color): - prefix_sum = [[0] * (m + 1) for _ in range(n + 1)] - - for i in range(n): - for j in range(m): - repaint_count = 0 - if (i + j) % 2 == 0: - if board[i][j] != color: - repaint_count = 1 - else: - if board[i][j] == color: - repaint_count = 1 - - prefix_sum[i + 1][j + 1] = prefix_sum[i][j + 1] + prefix_sum[i + 1][j] - prefix_sum[i][j] + repaint_count - - min_repaint_count = sys.maxsize - - for i in range(1, n - k + 2): - for j in range(1, m - k + 2): - min_repaint_count = min(min_repaint_count, - prefix_sum[i + k - 1][j + k - 1] - prefix_sum[i + k - 1][j - 1] - prefix_sum[i - 1][ - j + k - 1] + prefix_sum[i - 1][j - 1]) - - return min_repaint_count - - -print(min(get_min_repaint_count('B'), get_min_repaint_count('W'))) diff --git "a/easyhooon/5\354\233\2245\354\243\274\354\260\250/\354\226\221\352\263\274 \353\212\221\353\214\200.py" "b/easyhooon/5\354\233\2245\354\243\274\354\260\250/\354\226\221\352\263\274 \353\212\221\353\214\200.py" deleted file mode 100644 index fc94fbd..0000000 --- "a/easyhooon/5\354\233\2245\354\243\274\354\260\250/\354\226\221\352\263\274 \353\212\221\353\214\200.py" +++ /dev/null @@ -1,62 +0,0 @@ -# 양과 늑대 - -# 갈 수 있는 모든 노드를 찾는 함수 -def get_can_go_nodes(parent, prev, graph): - # 현재 지점이 아닌 모든 이동 가능한 노드 - # 누적해서 더해 주어야함(이 문제 한정으로 0 - 5 - 1 4 - 8 - 3 - 7 이런식으로 움직일 수 있으려면) - can_go_nodes = [node for node in prev if node != parent] - - for j in range(len(graph)): - # 현재 지점에서 이동 가능한 간선일 경우 - if graph[parent][j]: - # 갈 수 있는 노드에 포함 시킴 - can_go_nodes.append(j) - - return can_go_nodes - - -# 현재 위치(i)를 기준으로 갈 수 있는 곳 가보기 -> DFS -# 갈 수 있는 모든 edges 탐색 -# parent: 지금 위치한 노드 -# s: 지금까지 모은 양의 수 -# w: 지금까지 모은 늑대의 수 -def dfs(parent, s, w, prev, graph, info): - global answer - - can_go_nodes = get_can_go_nodes(parent, prev, graph) - - # 양의 수와 늑대의 수가 같거나, 갈 수 있는 노드가 존재하지 않는 경우 - if s == w or not can_go_nodes: - # 정답을 갱신 - if answer < s: - answer = s - return - - # 갈 수 있는 노드에 대해서 - for node in can_go_nodes: - # 가려는 노드에 양이 있는 경우 - if info[node] == 0: - dfs(node, s + 1, w, can_go_nodes, graph, info) - - # 가려는 노드에 늑대가 있는 경우 - else: - dfs(node, s, w + 1, can_go_nodes, graph, info) - - -def solution(info, edges): - global answer - - answer = 1 - - graph = [[False] * len(info) for _ in range(len(info))] - - # 간선이 존재하는 경우 True - for x, y in edges: - graph[x][y] = True - - # 탐색 시작 - # 0번 노드부터 시작 - # 0번은 무조건 양이므로 양 1마리, 늑대 0마리 - dfs(0, 1, 0, [0], graph, info) - - return answer \ No newline at end of file diff --git "a/easyhooon/6\354\233\224 4\354\243\274\354\260\250/2229.py" "b/easyhooon/6\354\233\224 4\354\243\274\354\260\250/2229.py" deleted file mode 100644 index ab435c9..0000000 --- "a/easyhooon/6\354\233\224 4\354\243\274\354\260\250/2229.py" +++ /dev/null @@ -1,43 +0,0 @@ -# 조 짜기 -import sys - -si = sys.stdin.readline - -# 가급적 실력차이가 많이 나도록 조를 편성하는 것이 유리 -# 나이 차이가 많이 날 경우에는 오히려 부정적인 효과 -# -> 연속된 학생들을 모두 같은 조에 포함시켜야 한다는 뜻(1과 9가 같은 조애 속해있다면, 그 사이에 있는 3, 4, 8, 6 도 모두 1, 9와 같은 조에 속해야 함 -# 따라서 선생님들은 우선 나이 순서대로 정렬 후 적당히 학생들을 나누기로 함, 조의 개수는 상관x -# 각각의 조가 잘 짜여진 정도: 그 조에 속해있는 가장 점수가 높은 학생과 가장 낮은 학색의 점수 차이 -# 각 조의 잘 짜여진 정도의 합의 최댓값을 구하자. (조에 한명만 속하면 합이 0) -n = int(si()) -# 나이 순으로 정렬된 학생들의 점수 -arr = list(map(int, si().split())) -# 2 5 7 1 3 4 8 6 9 3 -# (2, 5), (7, 1), (3, 4, 8) (6, 9, 3) -# 3 + 6 + 5 + 6 = 20 (최대) - -# dp[i] := i 번째 학생까지 고려했을때 조가 잘 짜여진 정도의 최댓값, - -dp = [-sys.maxsize] * 1001 -# 기저 조건 -dp[0] = 0 - -# n ^ 2 -> 1000 x 1000 ㅆㄱㄴ -for i in range(1, n): - # i번 학생을 새로운 조에 넣거나 - # 이전 조에 포함 - # min, max_score 를 현재 위치의 학생의 점수로 초기화 - min_score = max_score = arr[i] - for j in range(i, -1, -1): - # 현재 i 부터 0번 위치까지 탐색하여 가장 큰 값과 가장 작은 값을 찾아냄 - min_score = min(min_score, arr[j]) - max_score = max(max_score, arr[j]) - # j 가 0보다 클 경우 - if j > 0: - # j - 1 번 위치의 학생까지 고려했을때 최댓값에 max_score - min_score 로 이뤄진 팀의 차이를 더함 - dp[i] = max(dp[i], dp[j - 1] + max_score - min_score) - # j 가 0 일 경우 - else: - dp[i] = max(dp[i], max_score - min_score) - -print(dp[n - 1]) diff --git "a/easyhooon/6\354\233\224 4\354\243\274\354\260\250/2623.py" "b/easyhooon/6\354\233\224 4\354\243\274\354\260\250/2623.py" deleted file mode 100644 index 60cfc09..0000000 --- "a/easyhooon/6\354\233\224 4\354\243\274\354\260\250/2623.py" +++ /dev/null @@ -1,47 +0,0 @@ -# 음악 프로그램 -from collections import deque -import sys - -si = sys.stdin.readline - -n, m = map(int, si().split()) - -edges = [[] for _ in range(n + 1)] -indegree = [0] * (n + 1) - -for _ in range(m): - arr = list(map(int, si().split())) - arr = arr[1:] - for i in range(len(arr) - 1): - edges[arr[i]].append(arr[i + 1]) - indegree[arr[i + 1]] += 1 - -# print(edges) -# print(indegree) - -q = deque() - -for i in range(1, n + 1): - # 진입 차수가 0 이 아니라면 - if not indegree[i]: - q.append(i) - -answer = [] - -while q: - x = q.popleft() - answer.append(x) - - for y in edges[x]: - indegree[y] -= 1 - - # 진입 차수가 0이라면 - if not indegree[y]: - q.append(y) - -if len(answer) == n: - for elem in answer: - print(elem) - -else: - print(0) diff --git "a/easyhooon/6\354\233\224 4\354\243\274\354\260\250/\353\263\264\354\204\235 \354\207\274\355\225\221.py" "b/easyhooon/6\354\233\224 4\354\243\274\354\260\250/\353\263\264\354\204\235 \354\207\274\355\225\221.py" deleted file mode 100644 index ce99780..0000000 --- "a/easyhooon/6\354\233\224 4\354\243\274\354\260\250/\353\263\264\354\204\235 \354\207\274\355\225\221.py" +++ /dev/null @@ -1,65 +0,0 @@ -# 진열대의 특정 범위의 보석을 모두 구매하되, -# 진열된 모든 종류의 보석을 적어도 1개 이상 포함하는 가장 짧은 구간을 찾아서 구매 -# 3 부터 7 -> 모든 종류 보석 적어도 1개씩 포함 -# 슬라이딩 윈도우인가 -# 그런데 윈도우의 크기가 정해지지 않았음 그러면 슬라이딩 윈도우를 사용해서 문제를 풀 수 없음 -# 그러면 투포인터네 -import sys - -jew_type = {} - - -# 보석의 종류가 최대 10만개여서 10만 x 10만이 될 수 있음 -def is_possible(m, unique_cnt): - # flag = True - # for key in jew_type.keys(): - # if jew_type[key] < 1: - # flag = False - # return flag - # - return m == unique_cnt - - -def solution(gems): - # 진열대(배열)의 길이 List - n = len(gems) - # 보석의 종류의 개수 - m = len(set(gems)) - # 현재 유니크한 보석의 개수 - unique_cnt = 0 - answer = [] - min_len_answer = sys.maxsize - min_L = 0 - min_R = 0 - # 보석의 종류 - for jew in set(gems): - jew_type[jew] = jew_type.get(jew, 0) - - R = -1 - for L in range(0, n): - if L >= 1: - jew_type[gems[L - 1]] -= 1 - if jew_type[gems[L - 1]] == 0: - unique_cnt -= 1 - - while R + 1 < n and not is_possible(m, unique_cnt): - R += 1 - jew_type[gems[R]] += 1 - if jew_type[gems[R]] == 1: - unique_cnt += 1 - - if is_possible(m, unique_cnt): - # print(L, R) - # print(jew_type) - - len_answer = R - L + 1 - if len_answer < min_len_answer: - min_len_answer = len_answer - min_L = L + 1 # 인덱스 - min_R = R + 1 - - answer = [] - answer.append(min_L) - answer.append(min_R) - - return answer \ No newline at end of file diff --git "a/easyhooon/6\354\233\224 4\354\243\274\354\260\250/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.py" "b/easyhooon/6\354\233\224 4\354\243\274\354\260\250/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.py" deleted file mode 100644 index c731d6b..0000000 --- "a/easyhooon/6\354\233\224 4\354\243\274\354\260\250/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.py" +++ /dev/null @@ -1,55 +0,0 @@ -# 어떤 차량이 입차된 후에 출차된 내역이 없다면, 23:59 에 출차된 것으로 간주 -# fees -> (기본 시간, 기본 요금, 단위 시간, 단위 요금) -# records > (시각, 차량번호, 내역) -# 차량 번호가 작은 자동차부터 청구할 주차 요금을 차례대로 담아 return -from collections import defaultdict - - -def solution(fees, records): - car_cost = defaultdict(list) - default_time, default_cost, unit_time, unit_cost = fees - - for record in records: - time, car_num, io = record.split(" ") - car_cost[car_num].append(time) - - for key in car_cost.keys(): - if len(car_cost[key]) % 2 == 1: - car_cost[key].append('23:59') - - # key 값 기준 정렬 - # sorted 함수 -> list 를 리턴함.. - # dict 으로 다시 변환하면 됨 - car_cost = dict(sorted(car_cost.items())) - print(car_cost) - - car_time_sum = [] - for key in car_cost.keys(): - # print(key) - sum_hh = 0 - sum_mm = 0 - for i in range(0, len(car_cost[key]) - 1, 2): - in_hh, in_mm = car_cost[key][i].split(":") - out_hh, out_mm = car_cost[key][i + 1].split(":") - sum_hh += int(out_hh) - int(in_hh) - sum_mm += int(out_mm) - int(in_mm) - - car_time_sum.append(sum_hh * 60 + sum_mm) - - print(car_time_sum) - answer = [] - for car_time in car_time_sum: - cost = 0 - if car_time > default_time: - cost += default_cost - add_time = car_time - default_time - if add_time % unit_time > 0: - cost += ((add_time // unit_time) + 1) * unit_cost - else: - cost += (add_time // unit_time) * unit_cost - else: - cost = default_cost - - answer.append(cost) - - return answer \ No newline at end of file diff --git "a/easyhooon/6\354\233\224 4\354\243\274\354\260\250/\355\221\234 \353\263\221\355\225\251.py" "b/easyhooon/6\354\233\224 4\354\243\274\354\260\250/\355\221\234 \353\263\221\355\225\251.py" deleted file mode 100644 index 8e4c10b..0000000 --- "a/easyhooon/6\354\233\224 4\354\243\274\354\260\250/\355\221\234 \353\263\221\355\225\251.py" +++ /dev/null @@ -1,81 +0,0 @@ -def solution(commands): - answer = [] - - # merge 관계를 나타내기 위한 배열 (같은 순서쌍이 들어가 있으면 그 칸들은 merge 되어있다.) - # 병합된 셀에 접근하기 위해 만든 배열 - merged = [[(i, j) for j in range(51)] for i in range(51)] - # 실제 값이 들어 있는 배열 - board = [["EMPTY"] * 51 for _ in range(51)] - print(merged) - - for command in commands: - if command.startswith("UPDATE"): - # 병합된 칸이 있다면 해당 칸도 업데이트 - # r, c (value) - tmp = command.split(" ") - if len(tmp) == 4: - r, c, value = int(tmp[1]), int(tmp[2]), tmp[3] - # print(r, c, merged[r][c]) - # r, c 가 어떤 칸에 merge가 되어있는지 확인 -> r, c 가 아닌 다른 순서쌍(x, y)이 들어있는 경우 -> 다른 순서쌍(x, y) 칸에 merge 되어 있다. - x, y = merged[r][c] - # x, y 칸에 value 업데이트 - board[x][y] = value - - # value1 -> value2 - elif len(tmp) == 3: - value1, value2 = tmp[1], tmp[2] - for i in range(1, 51): - for j in range(1, 51): - # value 1 이 들어있는 칸을 전부 value 2로 변경 - if board[i][j] == value1: - board[i][j] = value2 - - elif command.startswith("MERGE"): - tmp = command.split(" ") - r1, c1, r2, c2 = int(tmp[1]), int(tmp[2]), int(tmp[3]), int(tmp[4]) - # 현재 칸이 어느 칸에 merge 되어 있는지 확인 (r, c) == (x, y) 이면 merge 되지 않은 것 - x1, y1 = merged[r1][c1] - x2, y2 = merged[r2][c2] - - # 병합하려는 셀에 값이 존재하지 않으면 - if board[x1][y1] == "EMPTY": - # 병합 하는 칸에 값을 가짐 - board[x1][y1] = board[x2][y2] - - for i in range(51): - for j in range(51): - # (i, j 가 x2, y2 로 merge 되어 있었다면) - if merged[i][j] == (x2, y2): - # (i, j) 를 (x1, y1) 칸에 merge - merged[i][j] = (x1, y1) - - - elif command.startswith("UNMERGE"): - tmp = command.split(" ") - r, c = int(tmp[1]), int(tmp[2]) - # r, c 가 어떤 칸에 merge 되어 있는지 - x, y = merged[r][c] - # 머지된 칸의 값을 저장 - tmp_value = board[x][y] - for i in range(51): - for j in range(51): - # (x, y) 라는 칸에 merge 되어 있는 상태라면 - if merged[i][j] == (x, y): - # unmerge - merged[i][j] = (i, j) - board[i][j] = "EMPTY" - # 머지 되었었던 칸의 값으로 update - board[r][c] = tmp_value - - # r,c - elif command.startswith("PRINT"): - tmp = command.split(' ') - r, c = int(tmp[1]), int(tmp[2]) - # 해당 칸이 병합된 칸이 있는지 (없으면 x, y = r, c) - x, y = merged[r][c] - answer.append(board[x][y]) - - return answer - -# print(solution(["UPDATE 1 1 menu", "UPDATE 1 2 category", "UPDATE 2 1 bibimbap", "UPDATE 2 2 korean", "UPDATE 2 3 rice", "UPDATE 3 1 ramyeon", "UPDATE 3 2 korean", "UPDATE 3 3 noodle", "UPDATE 3 4 instant", "UPDATE 4 1 pasta", "UPDATE 4 2 italian", "UPDATE 4 3 noodle", "MERGE 1 2 1 3", "MERGE 1 3 1 4", "UPDATE korean hansik", "UPDATE 1 3 group", "UNMERGE 1 4", "PRINT 1 3", "PRINT 1 4"])) -# print(solution(["UPDATE 1 1 a", "UPDATE 1 2 b", "UPDATE 2 1 c", "UPDATE 2 2 d", "MERGE 1 1 1 2", "MERGE 2 2 2 1", "MERGE 2 1 1 1", "PRINT 1 1", "UNMERGE 2 2", "PRINT 1 1"])) \ No newline at end of file diff --git "a/easyhooon/6\354\233\224 5\354\243\274\354\260\250/1167.py" "b/easyhooon/6\354\233\224 5\354\243\274\354\260\250/1167.py" deleted file mode 100644 index 6481571..0000000 --- "a/easyhooon/6\354\233\224 5\354\243\274\354\260\250/1167.py" +++ /dev/null @@ -1,64 +0,0 @@ -# 트리의 지름 -import sys -sys.setrecursionlimit(10**6) - -si = sys.stdin.readline - -MAX = 100_000 - -n = int(si()) -node = [[] for _ in range(MAX + 1)] -visited = [False] * (MAX + 1) -max_len = 0 -max_len_point = 0 - - -def dfs(point, length): - global max_len, max_len_point - - if visited[point]: - return - - visited[point] = True - if max_len < length: - max_len = length - max_len_point = point - - for i in range(len(node[point])): - dfs(node[point][i][0], length + node[point][i][1]) - - -for _ in range(n): - temp_list = list(map(int, si().split()))[:-1] - - cnt = 0 - parent = temp_list[cnt] - - while True: - cnt += 1 - child_index = cnt - cnt += 1 - length_index = cnt - if len(temp_list) <= cnt: - break - child = temp_list[child_index] - length = temp_list[length_index] - - node[parent].append((child, length)) - # 양방향 연결을 해주지 않는게 빠르다 - # node[child].append((parent, length)) - - -# print(node) - -# 가장 멀리 있는 정점(max_len_point) 구하기 -dfs(1, 0) - -max_len = 0 - -visited = [False] * (MAX + 1) - -# max_len_point 와 가장 멀리 있는 정점과의 거리 구하기 -dfs(max_len_point, 0) - -print(max_len) diff --git "a/easyhooon/6\354\233\224 5\354\243\274\354\260\250/2143.py" "b/easyhooon/6\354\233\224 5\354\243\274\354\260\250/2143.py" deleted file mode 100644 index e0ef6d0..0000000 --- "a/easyhooon/6\354\233\224 5\354\243\274\354\260\250/2143.py" +++ /dev/null @@ -1,85 +0,0 @@ -# 두 배열의 합 -# 각각의 배열의 합의 순서쌍을 count map 에 저장해서 각각의 count map 을 비교, 갯수가 몇개인지 -import sys - -si = sys.stdin.readline - -t = int(si()) -n = int(si()) -a = list(map(int, si().split())) -m = int(si()) -b = list(map(int, si().split())) -a_sum = {} -b_sum = {} -answer = 0 -# 1 3 1 2 -# 1개 4C1 = 4 -# 1 3 1 2 -# 2개 4C2 = 6 -# 4 2 3 4 5 3 -# 3개 4C3 = 4 -# 5 6 4 6 -# 4개 4C4 = 1 -# 7 -# 1: 2 -# 2: 2 -# 3: 3 -# 4: 3 -# 5: 2 -# 6: 2 -# 7: 1 - -# 1 3 2 3C1 + 3C2 + 3C3 = 3 + 3 + 1 = 7 -# 1: 1 -# 2: 1 -# 3: 2 -# 4: 1 -# 5: 1 -# 6: 1 - -# 5 -# 1 4 -# 2 3 -# 3 2 -# 4 1 - -# 부 배열의 합: 해당 값이 몇번 나올수 있는지-> 맵에 저장해둠 -# A[1] + A[4] + B[3] 이건 없음 -# A[3] + A[4] + B[3] 이건 있고 -# 부 배열의 합이라는게 연속되 인덱스여야 하는듯 -# for i in range(1, n + 1): -# combination_i = list(combinations(a, i)) -# for elem in combination_i: -# a_sum[sum(elem)] = a_sum.get(sum(elem), 0) + 1 -# -# for j in range(1, m + 1): -# combination_j = list(combinations(b, j)) -# for elem in combination_j: -# b_sum[sum(elem)] = b_sum.get(sum(elem), 0) + 1 - -for i in range(n): - for j in range(i, n): - sub_a = a[i: j + 1] - a_sum[sum(sub_a)] = a_sum.get(sum(sub_a), 0) + 1 - -for i in range(m): - for j in range(i, m): - sub_b = b[i: j + 1] - b_sum[sum(sub_b)] = b_sum.get(sum(sub_b), 0) + 1 - -# print(a_sum) -# print(b_sum) - -# 한쪽이 전부 차지하면 안되니까 각각의 합의 범위는 1, ~ (t -1) -# 아 T 에 음의 정수도 들어올 수 있음 (-1,000,000,000 <= T <= 1,000,000,000) -# 이런 음의 인덱스 때문에 HashMap 을 사용한 것 -# for i in range(1, t): -# # answer += a_sum[i] * b_sum[t - i] -> KeyError -# # print(a_sum.get(i, 0), b_sum.get(t - i, 0)) -# answer += a_sum.get(i, 0) * b_sum.get(t - i, 0) - -for key in a_sum.keys(): - # answer += a_sum[key] * b_sum[t - key] -> KeyError - answer += a_sum.get(key, 0) * b_sum.get(t - key, 0) - -print(answer) \ No newline at end of file diff --git "a/easyhooon/6\354\233\224 5\354\243\274\354\260\250/2671.py" "b/easyhooon/6\354\233\224 5\354\243\274\354\260\250/2671.py" deleted file mode 100644 index 34837ce..0000000 --- "a/easyhooon/6\354\233\224 5\354\243\274\354\260\250/2671.py" +++ /dev/null @@ -1,21 +0,0 @@ -# 잠수함 식별 -import re -import sys - -si = sys.stdin.readline - -str = si().strip() - -# 정상적인 잠수함의 엔진소리는 (100~1~|01)~ 패턴을 따름 -# 이를 정규식으로 표현하면 다음과 같음 -# '+' 는 앞선 문자가 1번 이상 반복됨을 나타냄 -# '|' 는 OR 연산을 의미 -# 즉, '100' 다음에 1이 하나 이상 나오고, 그 다음에 '1'이 하나 이상 나오거나, '0' 다음에 '1'이 오는 패턴이 반복되는 것을 찾음 -pattern = re.compile('(100+1+|01)+') -# fullmatch() 함수는 문자열 전체가 정규식 패턴과 일치하는지 확인 -match = pattern.fullmatch(str) - -if match: - print('SUBMARINE') -else: - print('NOISE') diff --git "a/easyhooon/6\354\233\224 5\354\243\274\354\260\250/2800.py" "b/easyhooon/6\354\233\224 5\354\243\274\354\260\250/2800.py" deleted file mode 100644 index bd9d899..0000000 --- "a/easyhooon/6\354\233\224 5\354\243\274\354\260\250/2800.py" +++ /dev/null @@ -1,63 +0,0 @@ -# 괄호 제거 -# 스택을 통해 괄호의 쌍(문자열에서의 인덱스)을 pair 로 리스트에 저장하여 -# 이들을 재귀를 통해 순서를 정하여 출력 -# 출력된 순서쌍중 겹치는 것이 존재하면 하나만 출력(set 자료구조 이용) -# 스택은 list 로 대체 -# 쌍을 제거해서 나올 수 있는 서로 다른 식을 사전 순으로 출력 -import sys -from itertools import combinations - -si = sys.stdin.readline - -stack = [] - -exp = si().strip() -pair_list = [] -n = len(exp) - -for i in range(n): - if exp[i] == '(': - stack.append(i) - elif exp[i] == ')': - j = stack.pop() - pair_list.append((j, i)) - -# print(pair_list) -# pair_list.sort() # 필요 없음 -# print(pair_list) -m = len(pair_list) - -# 출력이 까다롭다 - -# 괄호를 한개도 안 고른거는 출력 x -# 중복되는거 한번씩만 출력 -answer = [] - -for i in range(1, m + 1): - combinations_i = list(combinations(pair_list, i)) - for elem in combinations_i: - exp_visited = [False] * len(exp) - for j in range(len(elem)): - exp_visited[elem[j][0]] = True - exp_visited[elem[j][1]] = True - - exp_str = "" - for k in range(len(exp)): - if not exp_visited[k]: - exp_str += exp[k] - - answer.append(exp_str) - for j in range(len(elem)): - exp_visited[elem[j][0]] = False - exp_visited[elem[j][1]] = False - -answer = list(set(answer)) -answer.sort() -for elem in answer: - print(elem) - - - - - - diff --git "a/easyhooon/6\354\233\224 5\354\243\274\354\260\250/\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.py" "b/easyhooon/6\354\233\224 5\354\243\274\354\260\250/\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.py" deleted file mode 100644 index 9d88afd..0000000 --- "a/easyhooon/6\354\233\224 5\354\243\274\354\260\250/\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.py" +++ /dev/null @@ -1,60 +0,0 @@ -# 단순한 dfs/bfs 문제 -from collections import deque - -graph = [[0] * 101 for _ in range(101)] -visited = [[False] * 101 for _ in range(101)] - -dx = [-1, 0, 1, 0] -dy = [0, -1, 0, 1] - - -def in_range(x, y, n, m): - return 0 <= x < n and 0 <= y < m - - -def bfs(x, y, n, m): - island_sum = 0 - - q = deque() - q.append((x, y)) - island_sum += graph[x][y] - - while q: - x, y = q.popleft() - - for i in range(4): - nx = x + dx[i] - ny = y + dy[i] - if in_range(nx, ny, n, m) and not visited[nx][ny] and graph[nx][ny] != 0: - visited[nx][ny] = True - island_sum += graph[nx][ny] - q.append((nx, ny)) - - return island_sum - - -def solution(maps): - answer = [] - n = len(maps) - m = len(maps[0]) - - for i in range(n): - for j in range(m): - if maps[i][j] == 'X': - graph[i][j] = 0 - else: - graph[i][j] = int(maps[i][j]) - - for i in range(n): - for j in range(m): - if not visited[i][j] and graph[i][j] != 0: - visited[i][j] = True - island_sum = bfs(i, j, n, m) - answer.append(island_sum) - - answer.sort() - - if len(answer) == 0: - answer.append(-1) - - return answer \ No newline at end of file diff --git "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/1149(reverse).py" "b/easyhooon/6\354\233\2242\354\243\274\354\260\250/1149(reverse).py" deleted file mode 100644 index aafa393..0000000 --- "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/1149(reverse).py" +++ /dev/null @@ -1,22 +0,0 @@ -# RGB 거리 역방향 풀이 - -import sys - -si = sys.stdin.readline - -n = int(si()) - -board = [list(map(int, si().split())) for _ in range(n)] -dp = [[0] * 3 for _ in range(n)] - -# 기저 조건 -dp[n - 1][0] = board[n - 1][0] -dp[n - 1][1] = board[n - 1][1] -dp[n - 1][2] = board[n - 1][2] - -# 역방향으로 dp 배열 채우기 -for i in range(n - 2, -1, -1): - for j in range(0, 3): - dp[i][j] = min(dp[i + 1][(j + 1) % 3], dp[i + 1][(j + 2) % 3]) + board[i][j] - -print(min(dp[0][0], dp[0][1], dp[0][2])) diff --git "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/1149.py" "b/easyhooon/6\354\233\2242\354\243\274\354\260\250/1149.py" deleted file mode 100644 index afe5a1c..0000000 --- "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/1149.py" +++ /dev/null @@ -1,27 +0,0 @@ -# RGB 거리 - -import sys - -si = sys.stdin.readline - -n = int(si()) - -board = [list(map(int, si().split())) for _ in range(n)] -dp = [[0] * 3 for _ in range(n)] - -# 동등한 상황 -# 지금까지 고려한 위치가 같고 -# 현재 고른 위치가 같으며 -# 현재 까지의 합이 같은 경우 -# -> 지금까지 고려한 위치와 마지막에 고른 위치가 같다면 합이 작을수록 좋다 -# dp[i][j]:= i번째 위치까지 선택하였고, 마지막에 j번 색깔을 선택 했을 때 최소 합 - -# 기저 조건 -for i in range(0, 3): - dp[0][i] = board[0][i] - -for i in range(1, n): - for j in range(0, 3): - dp[i][j] = min(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + board[i][j] - -print(min(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])) diff --git "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/12869(top-down).py" "b/easyhooon/6\354\233\2242\354\243\274\354\260\250/12869(top-down).py" deleted file mode 100644 index 434f280..0000000 --- "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/12869(top-down).py" +++ /dev/null @@ -1,47 +0,0 @@ -# 뮤탈리스크 (top-down dp) - -import sys - -sys.setrecursionlimit(10**6) -si = sys.stdin.readline - -n = int(si()) -scv = list(map(int, si().split())) - -while len(scv) < 3: - scv.append(0) - -scv.sort(reverse=True) - -dp = [[[0] * 61 for _ in range(61)] for _ in range(61)] - - -def solve(i, j, k): - if i < 0: - return solve(0, j, k) - - if j < 0: - return solve(i, 0, k) - - if k < 0: - return solve(i, j, 0) - - if i == 0 and j == 0 and k == 0: - return 0 - - if dp[i][j][k]: - return dp[i][j][k] - - ret = sys.maxsize - ret = min(ret, solve(i - 9, j - 3, k - 1) + 1) - ret = min(ret, solve(i - 9, j - 1, k - 3) + 1) - ret = min(ret, solve(i - 1, j - 9, k - 3) + 1) - ret = min(ret, solve(i - 1, j - 3, k - 9) + 1) - ret = min(ret, solve(i - 3, j - 9, k - 1) + 1) - ret = min(ret, solve(i - 3, j - 1, k - 9) + 1) - - dp[i][j][k] = ret - return ret - - -print(solve(scv[0], scv[1], scv[2])) diff --git "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/12869.py" "b/easyhooon/6\354\233\2242\354\243\274\354\260\250/12869.py" deleted file mode 100644 index 1d6b202..0000000 --- "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/12869.py" +++ /dev/null @@ -1,60 +0,0 @@ -# 뮤탈리스크 -# 남은 scv 를 모두 파괴하기 위해 공격해야하는 횟수의 최솟값 -# 3 -# 12 10 4 -# 12 - 3, 10 - 9, 4 -1 => 9, 1, 3 -# 9 - 9, 1 - 1, 3 - 3 => 0, 0, 0 -# scv 는 최대 3마리, 체력이 0 이하가 되면 즉시 파괴 -# 다 계산 해보면 되는것 같은데, 체력도 적음 -# 문제는 몇번 시행한다고 정해진게 아니라 끝날때까지 하는거라 기존의 n과 m 풀이와는 다르게 가져가야 -# 아 물병 문제 처럼 -# 3 ^ n - -import sys -from collections import deque - -sys.setrecursionlimit(10 * 6) - -si = sys.stdin.readline - -n = int(si()) -arr = list(map(int, si().split())) - -while len(arr) < 3: - arr.append(0) - -visited = [[[False] * 61 for _ in range(61)] for _ in range(61)] -attacks = [(9, 3, 1), (9, 1, 3), (3, 9, 1), (3, 1, 9), (1, 9, 3), (1, 3, 9)] - - -def bfs(): - q = deque() - q.append((arr[0], arr[1], arr[2], 0)) - visited[arr[0]][arr[1]][arr[2]] = True - - while q: - x, y, z, curr_num = q.popleft() - - if x == 0 and y == 0 and z == 0: - print(curr_num) - return - - for attack in attacks: - nx = x - attack[0] - ny = y - attack[1] - nz = z - attack[2] - if nx < 0: - nx = 0 - if ny < 0: - ny = 0 - if nz < 0: - nz = 0 - if not visited[nx][ny][nz]: - visited[nx][ny][nz] = True - q.append((nx, ny, nz, curr_num + 1)) - - -bfs() - - - diff --git "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/2157.py" "b/easyhooon/6\354\233\2242\354\243\274\354\260\250/2157.py" deleted file mode 100644 index 553a0d7..0000000 --- "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/2157.py" +++ /dev/null @@ -1,51 +0,0 @@ -# 여행 - -import sys - -# n 개의 도시 중 m 개 이하의 도시를 지나는 여행을 계획할때 먹게 된느 기내식 점수의 총합이 최대가 되도록 -# dp[i][j] := i 번째 도시를 j 개 이하의 도시를 지나 도착했을때 먹은 기내식 점수의 총합 -# 동 -> 서로, 도시 번호가 증가하는 순서대로만 이동 가능 -# 예제 1 -> 3, 2개의 도시를 지나(3개 이하) 기내식 점수를 10점 얻는게 정답 - -si = sys.stdin.readline - -n, m, k = map(int, si().split()) - -arr = [[0] * 301 for _ in range(301)] -# i 도시에서 j 도시로 갈때 얻을 수 있는 기내식 점수의 최대 -dp = [[-1] * 301 for _ in range(301)] - -for _ in range(k): - a, b, c = map(int, input().split()) - if a > b: - continue - arr[a][b] = max(arr[a][b], c) - - -def solve(idx, cnt): - # 기저 조건 - if idx != 1 and cnt == 1: - return -sys.maxsize - - # 기저 조건 - if idx == 1: - return 0 - - # 이미 채운 값이 있는 경우 - if dp[idx][cnt] != -1: - return dp[idx][cnt] - - # 최댓값을 구하는 것이므로 최솟값으로 초기화 - dp[idx][cnt] = -sys.maxsize - - for i in range(1, idx): - # 존재하는 경로에 대해서 - if arr[i][idx]: - dp[idx][cnt] = max(dp[idx][cnt], solve(i, cnt - 1) + arr[i][idx]) - - return dp[idx][cnt] - - -ans = solve(n, m) - -print(ans) diff --git "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/22944.py" "b/easyhooon/6\354\233\2242\354\243\274\354\260\250/22944.py" deleted file mode 100644 index 167febd..0000000 --- "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/22944.py" +++ /dev/null @@ -1,70 +0,0 @@ -# 죽음의 비 - -import sys -from collections import deque - -# 모든 우산의 내구도는 d 로 동일 -# 최단거리 문제이므로 항상 풀던대로 bfs -# 우산을 들고 있다가 파괴되 경우와 원래 부터 우산이 없는 경우를 분리? ㄴㄴ 우산의 내구도를 통해 판단 가능 - -si = sys.stdin.readline - -dxs = [-1, 0, 1, 0] -dys = [0, -1, 0, 1] - -n, h, d = map(int, si().split()) -board = [list(si().strip()) for _ in range(n)] -visited = [[0] * n for _ in range(n)] - -sx, sy = 0, 0 - -for i in range(n): - for j in range(n): - if board[i][j] == 'S': - sx, sy = i, j - - -def in_range(x, y): - return 0 <= x < n and 0 <= y < n - - -def bfs(): - q = deque([(sx, sy, h, 0, 0)]) - visited[sx][sy] = h - - while q: - x, y, curr_h, curr_d, cnt = q.pop() - - for dx, dy in zip(dxs, dys): - nx = x + dx - ny = y + dy - - if in_range(nx, ny): - if board[nx][ny] == 'E': - print(cnt + 1) - return - - next_h = curr_h - next_d = curr_d - - if board[nx][ny] == 'U': - next_d = d - - if next_d == 0: - next_h -= 1 - - else: - # next_d 가 0 이 아닐때만 실행 - next_d -= 1 - - if next_h == 0: - continue - - if visited[nx][ny] < next_h: - visited[nx][ny] = next_h - q.appendleft((nx, ny, next_h, next_d, cnt + 1)) - - print(-1) - - -bfs() diff --git "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/23757.py" "b/easyhooon/6\354\233\2242\354\243\274\354\260\250/23757.py" deleted file mode 100644 index 965bd16..0000000 --- "a/easyhooon/6\354\233\2242\354\243\274\354\260\250/23757.py" +++ /dev/null @@ -1,44 +0,0 @@ -# 아이들과 선물 상자 - -import sys -import heapq - -si = sys.stdin.readline - -# n <= 100,000 -# m <= 100,000 - -# 4 3 2 1 -# 1번 아이 -> 4 고름 3 -> 가능 1 3 2 1 -# 2번 아이 -> 3 고름 1 -> 가능 1 2 2 1 -# 3번 아이 -> 2 고름 2 -> 가능 1 0 2 1 -# 4번 아이 -> 2 고름 1 -> 가능 1 0 1 1 -# 가능 - -# 4 3 -# 1번 아이 -> 4 고름 3 -> 가능 1 3 2 1 -# 2번 아이 -> 3 고름 5 -> 불가능 -# 불가능 -> -1 이 아니라 0 출력 - -n, m = map(int, si().split()) -presents = list(map(int, si().split())) -children = list(map(int, si().split())) - -pq = [] - -for i in range(len(presents)): - heapq.heappush(pq, -presents[i]) - - -for child in children: - present = -heapq.heappop(pq) - if child <= present: - present -= child - # 다시 넣어줄때도 - 붙혀서 넣어줘야지.. - heapq.heappush(pq, -present) - - else: - print(0) - exit(0) - -print(1) \ No newline at end of file diff --git "a/easyhooon/6\354\233\2243\354\243\274\354\260\250/15686.py" "b/easyhooon/6\354\233\2243\354\243\274\354\260\250/15686.py" deleted file mode 100644 index b7f7f66..0000000 --- "a/easyhooon/6\354\233\2243\354\243\274\354\260\250/15686.py" +++ /dev/null @@ -1,57 +0,0 @@ -# 치킨 배달 -# 맨하탄 거리 -# 집의 개수는 2N 개를 넘지 않으며, 적어도 1개는 존재 -import sys - -si = sys.stdin.readline - -# 2 <= n <= 50, 도시의 한변의 길이 -# 1 <= m <= 13, 도시에 있는 치킨 집 중 최대 M개를 고름, 나머지는 모두 폐업 -# 도시의 치킨 거리가 가장 작게 될지 구하는 프로그램 -# 치킨 거리: 집에서 가장 가까운 치킨집 사이의 거리 -# 폐업시키지 않을 치킨집을 최대 M개를 골랐을 때, 도시의 치킨 거리의 최솟값 -# 최대 M 개를 고르는거면 M개 보다 적게 골라도 되는거 아닌가 -# 치킨집이 많을수록 각 집에서의 치킨거리는 줄어들기 때문에 M개를 뽑는게 치킨거리의 합을 최소로 만들 수 있다. -n, m = map(int, si().split()) -graph = [[0] * (n + 1)] -for _ in range(n): - graph.append([0] + list(map(int, si().split()))) -chicken = [(0, 0)] -ans = sys.maxsize -selected = [0] - -for i in range(1, n + 1): - for j in range(1, n + 1): - if graph[i][j] == 2: - chicken.append((i, j)) - - -def get_chicken_distance_sum(): - chicken_distance_sum = 0 - for i in range(1, n + 1): - for j in range(1, n + 1): - if graph[i][j] == 1: - chicken_distance = sys.maxsize - for k in range(1, m + 1): - chicken_distance = min(chicken_distance, - abs(i - chicken[selected[k]][0]) + abs(j - chicken[selected[k]][1])) - chicken_distance_sum += chicken_distance - return chicken_distance_sum - - -# 중복을 허용하지 않음 -def dfs(curr_num): - global ans - if curr_num == m + 1: - ans = min(ans, get_chicken_distance_sum()) - return - - for cand in range(1, len(chicken)): - if selected[curr_num - 1] < cand: - selected.append(cand) - dfs(curr_num + 1) - selected.pop() - - -dfs(1) -print(ans) diff --git "a/easyhooon/6\354\233\2243\354\243\274\354\260\250/16929.py" "b/easyhooon/6\354\233\2243\354\243\274\354\260\250/16929.py" deleted file mode 100644 index 2abe9dc..0000000 --- "a/easyhooon/6\354\233\2243\354\243\274\354\260\250/16929.py" +++ /dev/null @@ -1,49 +0,0 @@ -import sys - -sys.setrecursionlimit(10 ** 6) - -si = sys.stdin.readline - -n, m = map(int, si().split()) - -# set 으로 지나온 경로 담고 있는 건 메모리가 터질 것 같은데 n, m <= 50 이라 -# 이전에 온 방향을 기억하면 어떨까? 그 역방향으로 가는거만 막으면 사이클 판단 가능할듯 -# dfs 시작점일 경우엔 이전 방향이 없는데 -graph = [list(si().strip()) for _ in range(n)] -visited = [[False] * m for _ in range(n)] -dxs = [-1, 0, 1, 0] -dys = [0, -1, 0, 1] - - -def in_range(x, y): - return 0 <= x < n and 0 <= y < m - - -def dfs(x, y, before_dx, before_dy): - for dx, dy in zip(dxs, dys): - nx = x + dx - ny = y + dy - - # 범위 밖, 다른 알파벳, 바로 이전 위치로 이동 하는 경우 cut - if not in_range(nx, ny) or graph[x][y] != graph[nx][ny] or (dx == -before_dx and dy == -before_dy): - continue - - # 바로 이전 위치로 이동하는 것이 아닌데 이미 방문한 곳에 도착하였다. - # 사이클이 생성 되었다. - if visited[nx][ny]: - # print(nx, ny) - print('Yes') - exit(0) - - # print(nx, ny) - visited[nx][ny] = True - dfs(nx, ny, dx, dy) - - -for i in range(n): - for j in range(m): - if not visited[i][j]: - visited[i][j] = True - dfs(i, j, 0, 0) -print('No') - diff --git "a/easyhooon/6\354\233\2243\354\243\274\354\260\250/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.py" "b/easyhooon/6\354\233\2243\354\243\274\354\260\250/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.py" deleted file mode 100644 index 0bfb747..0000000 --- "a/easyhooon/6\354\233\2243\354\243\274\354\260\250/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.py" +++ /dev/null @@ -1,72 +0,0 @@ -# 각 대기실 별로 거리두기 지키면 1, 한명 이라도 안지키면 0을 담아 return -# 3차원 배열임 - -answer = [] - - -def check(candidates, place): - for sx, sy, ex, ey in candidates: - for x in range(sx, ex + 1): - for y in range(sy, ey + 1): - if place[x][y] == 'O': - return False - - for x in range(ex, sx + 1): - for y in range(sy, ey + 1): - if place[x][y] == 'O': - return False - - for x in range(sx, ex + 1): - for y in range(ey, sy + 1): - if place[x][y] == 'O': - return False - - for x in range(ex, sx + 1): - for y in range(ey, sy + 1): - if place[x][y] == 'O': - return False - - return True - - -def is_possible(people, place): - # 맨하탄 거리가 2 이하인 사람들의 조합을 구함 - candidates = [] - for i in range(len(people) - 1): - for j in range(i + 1, len(people)): - dist = abs(people[i][0] - people[j][0]) + abs(people[i][1] - people[j][1]) - if dist <= 2: - # 맨해튼 거리가 1 이하인 위치 관계가 존재 -> 무조건 불가능 - if dist <= 1: - answer.append(0) - return - # 맨해튼 거리가 2, 거리 두기 조건을 위반할 수 있는 후보 - else: - sx = people[i][0] - sy = people[i][1] - ex = people[j][0] - ey = people[j][1] - - candidates.append((sx, sy, ex, ey)) - - if check(candidates, place): - answer.append(1) - else: - answer.append(0) - - -def solution(places): - for place in places: - people = [] - for i in range(5): - for j in range(5): - if place[i][j] == 'P': - people.append((i, j)) - - is_possible(people, place) - - return answer - - -# print(solution([["POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"], ["POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"], ["PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"], ["OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"], ["PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"]])) -print(solution([["OOPOO", "OPOOO", "OOOOO", "OOOOO", "OOOOO"]])) \ No newline at end of file diff --git "a/easyhooon/6\354\233\2243\354\243\274\354\260\250/\352\270\270 \354\260\276\352\270\260 \352\262\214\354\236\204.py" "b/easyhooon/6\354\233\2243\354\243\274\354\260\250/\352\270\270 \354\260\276\352\270\260 \352\262\214\354\236\204.py" deleted file mode 100644 index e4bf29d..0000000 --- "a/easyhooon/6\354\233\2243\354\243\274\354\260\250/\352\270\270 \354\260\276\352\270\260 \352\262\214\354\236\204.py" +++ /dev/null @@ -1,88 +0,0 @@ -# 이진트리를 구성하는 각 노드의 x, y 좌표를 받아서 -# 이를 통해서 이진트리를 구성하고, -# 그 이진 트리의 전위 순회, 후위 순회한 결과를 2차원 배열에 순서대로 담아 return -# 좌표를 통해 트리를 구축하는게 어렵다 -import sys - -sys.setrecursionlimit(10 ** 6) - - -# 트리 구축 -# y 좌표는 같을 수 있지만, x 좌표는 다 다르다. -def add_node(parent, child, tree): - # 부모 노드보다 x 좌표가 작을 경우, 왼쪽 자식 노드에 들어갈 수 있는지 검사 - if tree[child][0] < tree[parent][0]: - if tree[parent][1] is None: - tree[parent][1] = child - # 이미 자식 노드가 존재한다면 - else: - # 부모의 왼쪽 자식 노드를 부모로 설정하여 그 부모에 자식 노드가 될 수 있는지 검사(탐색) - add_node(tree[parent][1], child, tree) - - # 부모 노드보다 x 좌표가 클 경우, 오른쪽 자식 노드에 들어갈 수 있는지 검사 - else: - if tree[parent][2] is None: - tree[parent][2] = child - else: - add_node(tree[parent][2], child, tree) - - -# 전위 탐색 -# root -> left -> right -def pre_order(node, tree, order): - # None 이면 존재하지 않으므로 종료 - if node is None: - return - - order.append(node) - pre_order(tree[node][1], tree, order) - pre_order(tree[node][2], tree, order) - - -# 후위 탐색 -# left -> right -> root -def post_order(node, tree, order): - if node is None: - return - - post_order(tree[node][1], tree, order) - post_order(tree[node][2], tree, order) - order.append(node) - - -def solution(nodeinfo): - info = {} - for idx, node in enumerate(nodeinfo): - x, y = node - info[idx + 1] = (x, y) - - - # print("info: ", info) - - # 트리의 루트 노드 찾기 - # 각 노드의 위상 관계 찾기 (앞에 있을 수록 루트에 가까움, 왼쪽 자식, 오른쪽 자식 순) - # 1) y 좌표가 클수록, y 좌표가 같으면 x 좌표가 작을 수록 더 앞선 노드이다. - nodes = sorted(list(info.keys()), key=lambda x: (-info[x][1], info[x][0])) - # print("nodes: ", nodes) - - # { node: (node의 x 좌표, left_child, right_child) } - # y 좌표는 중복이 있지만, x 좌표를 고유값 -> x 좌푤르 통해 각 노드의 위치를 특정 - tree = {node: [info[node][0], None, None] for node in nodes} - # print("tree: ", tree) - - root = nodes[0] - for node in nodes[1:]: - add_node(root, node, tree) - - # print("tree: ", tree) - - pre_order_list = [] - post_order_list = [] - - pre_order(root, tree, pre_order_list) - post_order(root, tree, post_order_list) - - return [pre_order_list, post_order_list] - - -print(solution([[5, 3], [11, 5], [13, 3], [3, 5], [6, 1], [1, 3], [8, 6], [7, 2], [2, 2]])) diff --git "a/easyhooon/6\354\233\2243\354\243\274\354\260\250/\354\226\221\352\266\201 \352\262\214\354\236\204.py" "b/easyhooon/6\354\233\2243\354\243\274\354\260\250/\354\226\221\352\266\201 \352\262\214\354\236\204.py" deleted file mode 100644 index abe24cf..0000000 --- "a/easyhooon/6\354\233\2243\354\243\274\354\260\250/\354\226\221\352\266\201 \352\262\214\354\236\204.py" +++ /dev/null @@ -1,72 +0,0 @@ -from collections import defaultdict - - -# 라이언이 어피치를 가장 큰 점수 차이로 이기기 위해서 n 발의 화살을 어떤 과녁 점수에 맞혀야 하는지를 구하려고 함 -# dp 같은디 -# 어피치보다 같은 점수의 과녁을 하나만 더 맞추면 그 점수를 가져갈 수 있다. -# 시간 10초 - -def solution(n, info): - cases = [] - combinations = [] - - # 중복 조합 - def dfs(curr_num, start): - if curr_num == n: - cases.append(combinations[:]) - return - - for i in range(start, 11): - combinations.append(i) - dfs(curr_num + 1, i) - combinations.pop() - - dfs(0, 0) - # print(cases) - - cands = [] - win_dict = defaultdict(list) - - # 승패 판단 - def compare(ryan, apeach): - ryan_score = 0 - apeach_score = 0 - - for i in range(11): # 점수 계산 - if apeach[i] >= ryan[i]: - if apeach[i] == 0: - continue - apeach_score += 10 - i - else: - ryan_score += 10 - i - - # 라이언이 이겼으면 - if ryan_score > apeach_score: - # win_dict에 {점수 차 : [라이언 결과들]} 형태로 같은 점수 차를 갖는 라이언 결과들을 모음 - win_dict[ryan_score - apeach_score].append(ryan) - - # 중복조합을 이용하여 라이언을 쏠 수 있는 모든 경우의 수를 구함 - for case in cases: - ryan = [0] * 11 - for i in case: - ryan[i] += 1 - cands.append(ryan) - - # 이긴 것만 win_dict에 기록 - for cand in cands: - compare(cand, info) - - # 한번도 이길 수 없다면 - if not win_dict: - return [-1] - - # 점수 차가 가장 큰 라이언 결과들 - target = win_dict[max(win_dict.keys())] - # print(target) - # 가장 큰 점수 차이로 이기는 경우 중에서 가장 낮은 점수를 가장 많이 맞힌 케이스를 출력 - target.sort(key=lambda x: tuple([-x[i] for i in range(10, -1, -1)])) - - return target[0] - -# print(solution(5, [2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0])) -# print(solution(10, [0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3])) diff --git "a/easyhooon/6\354\233\2243\354\243\274\354\260\250/\354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270 \352\263\265\353\266\200.py" "b/easyhooon/6\354\233\2243\354\243\274\354\260\250/\354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270 \352\263\265\353\266\200.py" deleted file mode 100644 index 9846195..0000000 --- "a/easyhooon/6\354\233\2243\354\243\274\354\260\250/\354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270 \352\263\265\353\266\200.py" +++ /dev/null @@ -1,76 +0,0 @@ -# 각 문제마다 문제를 풀면 올라가는 알고력과 코딩력이 정해져 있음 -# 같은 문제를 여러번 푸는 것이 가능 -# 주어진 모든 문제들을 풀 수 있는 알고력과 코딩력을 얻는 최단 시간을 구하려 함 -# 모든 문제를 풀 수 있는 능력치에 도달하면 종료 -# 마지막 문제를 푸는 시간을 더할 필요 없음 -# 백트래킹 -> 메모이제이션 dp -# 알고력을 높이기 위해 알고 공부를 하냐, 코딩력을 높이기 위해 코딩 공부를 하냐 -# 풀 수 있는 문제를 풀어 알고, 코딩력 모두를 올리냐 선택해서 최단 시간을 구하라 -# 동일한 상태를 정의 하기 위한 요소 -# 현재까지 고려한 위치(시간) -# 알고력 -# 코딩력 -# dp[i][j]:= 알고력 i, 코딩력이 j 를 도달하기 위한 최단 시간 -# 기저 조건 dp[alp][cop] = 0 -# 최소를 구하는 문제이므로 최대로 모든 배열을 초기화 시킴 - -# 알고리즘을 공부하여 알고력을 1 높이는 경우: -# dp[i+1][j] = min(dp[i+1][j], dp[i][j]+1) - -# 코딩을 공부하여 코딩력을 1 높이는 경우: -# dp[i][j+1] = min(dp[i][j+1], dp[i][j]+1) - -# 문제 하나를 선택하여 알고력과 코딩력을 높이는 경우: -# dp[i+alp_rwd][j+cop_rwd] = -# min(dp[i + alp_rwd][j + cop_rwd], dp[i][j] + cost) (단, i >= alp_req 이고 j >= cop_req) - -import sys - -INT_MAX = sys.maxsize - - -# alp, cop <= 150 -# problem <= 100 -# alp_req, cop_req <= 150 -# alp_rwd, cop_rwd <= 30 -# cost <= 100 -def solution(alp, cop, problems): - # 문제 중 최대 알고력 - max_alp = sorted(problems, reverse=True, key=lambda x: (x[0]))[0][0] - # 문제 중 최대 코딩력 - max_cop = sorted(problems, reverse=True, key=lambda x: (x[1]))[0][1] - - # print(max_alp, max_cop) - - # dp[i][j]:= 알고력 i, 코딩력이 j 를 도달하기 위한 최단 시간 - dp = [[INT_MAX] * (max_cop + 1) for _ in range(max_alp + 1)] - - # 목표 알고력 - alp = min(alp, max_alp) - # 목표 코딩력 - cop = min(cop, max_cop) - - # print(alp, cop) - - # 기저 조건 - dp[alp][cop] = 0 - - for i in range(alp, max_alp + 1): - for j in range(cop, max_cop + 1): - # 알고리즘 공부 - if i + 1 <= max_alp: - dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1) - - # 코딩 공부 - if j + 1 <= max_cop: - dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1) - - # 문제 풀이 - for (alp_req, cop_req, alp_rwd, cop_rwd, cost) in problems: - if i >= alp_req and j >= cop_req: - next_alp, next_cop = min(max_alp, i + alp_rwd), min(max_cop, j + cop_rwd) - dp[next_alp][next_cop] = min(dp[next_alp][next_cop], dp[i][j] + cost) - - return dp[max_alp][max_cop] - -# print(solution(0, 0, [[0, 0, 30, 2, 1], [150, 150, 30, 30, 100]])) diff --git "a/easyhooon/7\354\233\224 2\354\243\274\354\260\250/20040.py" "b/easyhooon/7\354\233\224 2\354\243\274\354\260\250/20040.py" deleted file mode 100644 index 7ba01f9..0000000 --- "a/easyhooon/7\354\233\224 2\354\243\274\354\260\250/20040.py" +++ /dev/null @@ -1,46 +0,0 @@ -# 사이클이 완성 되었다면 몇번째 차례에 처음으로 사이클이 완성된 것인지를 출력 -# Union-Find -import sys - -sys.setrecursionlimit(10 ** 6) - -si = sys.stdin.readline - -# 3 <= n <= 500,000 -# 3 <= m <= 1,000,000 -n, m = map(int, si().split()) - -uf = [0] * n - -for i in range(n): - uf[i] = i - - -def find(x): - if uf[x] == x: - return x - - root_node = find(uf[x]) - uf[x] = root_node - - return root_node - - -def union(x, y): - x = find(x) - y = find(y) - uf[x] = y - - -answer = 0 -for i in range(1, m + 1): - x, y = map(int, si().split()) - # 사이클이 생성 되었는지 검사 - if find(x) == find(y): - answer = i - break - # 사이클이 아니면 union 연산 진행 - else: - union(x, y) - -print(answer) diff --git "a/easyhooon/7\354\233\224 2\354\243\274\354\260\250/4386.py" "b/easyhooon/7\354\233\224 2\354\243\274\354\260\250/4386.py" deleted file mode 100644 index 2361a30..0000000 --- "a/easyhooon/7\354\233\224 2\354\243\274\354\260\250/4386.py" +++ /dev/null @@ -1,74 +0,0 @@ -# 별자리 만들기 -import sys -import math - -si = sys.stdin.readline - -# 1 <= n <= 100 -n = int(si()) -stars = [] -edges = [] -uf = [0] * (n + 1) -mst = [] - -for _ in range(n): - x, y = map(float, si().split()) - stars.append((x, y)) - -for i in range(n): - for j in range(i + 1, n): - x1, y1 = stars[i] - x2, y2 = stars[j] - - dist = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) - edges.append((i, j, dist)) - # edges.append(dist) - -# print(edges) - -# 간선을 가중치 기준으로 오름차순 정렬 -sorted_edges = sorted(edges, key=lambda x: (x[2])) -# print(sorted_edges) - - -def find(x): - # x 가 루트 노드 라면 - if uf[x] == x: - # x 값을 반환 - return x - - # x 가 루트 노드가 아니라면, x 의 부모인 uf[x]에서 더 탐색을 진행 - root_node = find(uf[x]) - # 노드 x 에 부모를 루트 노드로 설정 - uf[x] = root_node - # 찾아낸 루트 노드를 반환 - return root_node - - -def union(x, y): - x = find(x) - y = find(y) - uf[x] = y - - -# uf 배열을 노드의 수 |V| 만큼 초기화 -for i in range(1, n + 1): - uf[i] = i - -# 각 간선에 대해서 간선을 이루고 있는 두 노드 u,v 를 보며 -for u, v, w in sorted_edges: - # u, v 의 루트 노드가 다른 경우에만 - if find(u) != find(v): - # mst에 해당 간선을 넣어주고 - mst.append((u, v, w)) - # u, v 를 같은 루트 노드를 갖도록 만들어 줌 - union(u, v) - -answer = 0.0 - -# print(mst) - -for _, _, w in mst: - answer += w - -print(round(answer, 2)) diff --git "a/easyhooon/7\354\233\224 2\354\243\274\354\260\250/\353\213\244\353\213\250\352\263\204 \354\271\253\354\206\224 \355\214\220\353\247\244.py" "b/easyhooon/7\354\233\224 2\354\243\274\354\260\250/\353\213\244\353\213\250\352\263\204 \354\271\253\354\206\224 \355\214\220\353\247\244.py" deleted file mode 100644 index e69de29..0000000 diff --git "a/easyhooon/7\354\233\224 3\354\243\274\354\260\250/11497.py" "b/easyhooon/7\354\233\224 3\354\243\274\354\260\250/11497.py" deleted file mode 100644 index ee436e3..0000000 --- "a/easyhooon/7\354\233\224 3\354\243\274\354\260\250/11497.py" +++ /dev/null @@ -1,35 +0,0 @@ -# 통나무 건너뛰기 - -# 각 인접한 통나무의 높이 차가 최소가 되도록 -# 높이 차의 최댓값으로 난이도가 결정 -# 최소 난이도를 출력 -# 원형으로 이어지는 구조라 정렬하면 가장 작은 것과 가장 큰게 인접함 -> 최대 난이도를 형성함 -# 그리디인가 - 가장 큰거랑 작은게 인접하게 하면 안됨 -# 가장 큰거를 가운데에 위치 시키고 왼쪽 오른 쪽 번갈아 놓으면 -# 왼쪽에 그 다음으로 큰거 오른쪽에 그 다음로 큰거를 위치시킨다 가정하면 인접한 높이의 -# 10, 10, 11, 11, 12, 12, 13 -# 10 10 11 12 13 12 11 - -# 2 4 5 7 9 -# 2 5 9 7 4 - -# 6 6 6 6 6 6 6 - -import sys - -si = sys.stdin.readline - -# t 의 범위는 없음 -tc = int(si()) -# n <= 10,000 -> 2중 포문 가능 -# 통나무의 높이 <= 100,000 -for _ in range(tc): - n = int(si()) - arr = list(map(int, si().split())) - arr.sort() - max_diff = -sys.maxsize - for i in range(2, n): - max_diff = max(max_diff, arr[i] - arr[i - 2]) - print(max_diff) - - diff --git "a/easyhooon/7\354\233\224 3\354\243\274\354\260\250/1987.py" "b/easyhooon/7\354\233\224 3\354\243\274\354\260\250/1987.py" deleted file mode 100644 index 929bddf..0000000 --- "a/easyhooon/7\354\233\224 3\354\243\274\354\260\250/1987.py" +++ /dev/null @@ -1,29 +0,0 @@ -# 알파벳 -# 최장거리 -> 다항식의 시간 복잡도로 불가능, 백트래킹을 통한 완전 탐색 -import sys - -si = sys.stdin.readline - -n, m = map(int, si().split()) -board = [list(si().strip()) for _ in range(n)] -dirs = ((1, 0), (0, 1), (-1, 0), (0, -1)) -ans = 0 -visited = [False for _ in range(26)] # 정답 변수 & 사용한 알파벳 기록 배열 - - -def recursive(x, y, cnt): - global ans - ans = max(ans, cnt) - visited[ord(board[x][y]) - ord('A')] = True - - for dx, dy in dirs: - nx, ny = x + dx, y + dy - if 0 <= nx < n and 0 <= ny < m and not visited[ord(board[nx][ny]) - ord('A')]: - recursive(nx, ny, cnt + 1) - - visited[ord(board[x][y]) - ord('A')] = False - - -recursive(0, 0, 1) - -print(ans) \ No newline at end of file diff --git "a/easyhooon/7\354\233\224 3\354\243\274\354\260\250/2096.py" "b/easyhooon/7\354\233\224 3\354\243\274\354\260\250/2096.py" deleted file mode 100644 index a6373dd..0000000 --- "a/easyhooon/7\354\233\224 3\354\243\274\354\260\250/2096.py" +++ /dev/null @@ -1,43 +0,0 @@ -# 내려가기 -# 메모리 초과 - -import sys - -si = sys.stdin.readline - -n = int(si()) - -# 동등한 상황 -# 여태 고려한 위치가 같고, 현재 선택하려는 위치가 같으며, 여태까지 고른 숫자들의 합이 같은 경우 -# 지금까지 고려한 위치가 같고, 현재 선택하려는 위치가 같다면, 합이 클수록/작을 수록 좋다 -# i 번째 줄에서 j 칸을 선택 했을때 여태 까지 얻은 점수의 최대 합 -# max_dp = [[0] * 3 for _ in range(n)] -# i 번째 줄에서 j 칸을 선택 했을때 여태 까지 얻은 점수의 최소 합 -# min_dp = [[0] * 3 for _ in range(n)] -max_dp = [0] * 3 -min_dp = [0] * 3 - -max_temp = [0] * 3 -min_temp = [0] * 3 - -for i in range(n): - x, y, z = map(int, si().split()) - for j in range(3): - if j == 0: - max_temp[j] = max(max_dp[0], max_dp[1]) + x - min_temp[j] = min(min_dp[0], min_dp[1]) + x - - elif j == 1: - max_temp[j] = max(max_dp[0], max_dp[1], max_dp[2]) + y - min_temp[j] = min(min_dp[0], min_dp[1], min_dp[2]) + y - - elif j == 2: - max_temp[j] = max(max_dp[1], max_dp[2]) + z - min_temp[j] = min(min_dp[1], min_dp[2]) + z - - for j in range(3): - max_dp[j] = max_temp[j] - min_dp[j] = min_temp[j] - -print(max(max_dp), min(min_dp)) - diff --git "a/easyhooon/7\354\233\224 3\354\243\274\354\260\250/21922.py" "b/easyhooon/7\354\233\224 3\354\243\274\354\260\250/21922.py" deleted file mode 100644 index a6faf44..0000000 --- "a/easyhooon/7\354\233\224 3\354\243\274\354\260\250/21922.py" +++ /dev/null @@ -1,67 +0,0 @@ -from collections import deque -import sys - -# 굳이 방문 배열을 3차원으로 관리 하지 않아도 된다. - -si = sys.stdin.readline - -dxs = [-1, 1, 0, 0] -dys = [0, 0, -1, 1] - -n, m = map(int, si().split()) -visited = [[0] * m for _ in range(n)] - -q = deque() -graph = [] - -for i in range(n): - line = list(map(int, si().split())) - for j in range(m): - # 에어컨 위치 미리 큐에 넣어 놓기 - if line[j] == 9:상 - q.append((i, j)) - visited[i][j] = 1 - graph.append(line) - - -def in_range(x, y): - return 0 <= x < n and 0 <= y < m - - -def bfs(): - while q: - x, y = q.popleft() - - for i in range(4): - dx, dy = dxs[i], dys[i] - nx, ny = x + dx, y + dy - - while in_range(nx, ny): - # 방문 체크 - visited[nx][ny] = 1 - # 에어컨 위치로 이동한 경우 - if graph[nx][ny] == 9: - break - # 방향 전환 - if graph[nx][ny] == 3: - dx, dy = -dy, -dx - # 방향 전환 - elif graph[nx][ny] == 4: - dx, dy = dy, dx - # 1, 2 물건을 정면으로 마주치는 바람 이동 종료 - elif (graph[nx][ny] == 1 and dx == 0) or (graph[nx][ny] == 2 and dy == 0): - break - - nx += dx - ny += dy - - -bfs() - -answer = 0 -for i in range(n): - for j in range(m): - if visited[i][j] == 1: - answer += 1 - -print(answer) diff --git "a/easyhooon/7\354\233\224 3\354\243\274\354\260\250/\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" "b/easyhooon/7\354\233\224 3\354\243\274\354\260\250/\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" deleted file mode 100644 index 335d66e..0000000 --- "a/easyhooon/7\354\233\224 3\354\243\274\354\260\250/\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" +++ /dev/null @@ -1,15 +0,0 @@ -# 전화번호 목록 -# 다른 번호의 접두어인 경우가 있으면 false -# n <= 1,000,000 -> 2차원 포문으로 풀이 불가능, nlogn -# 같은 값이 들어있지 않음 -> 굳이 Counter 안써도 될듯 -# slice 도 O(n) 이라서 n^2 임 -# 무조건 첫번째 번호랑만 비교하는 문제가 아님 (문제 잘못 이해) - -def solution(phone_book): - n = len(phone_book) - phone_book.sort() - - for i in range(1, n): - if phone_book[i].startswith(phone_book[i - 1]): - return False - return True diff --git "a/easyhooon/7\354\233\224 3\354\243\274\354\260\250/\355\221\234\355\230\204 \352\260\200\353\212\245\355\225\234 \354\235\264\354\247\204\355\212\270\353\246\254.py" "b/easyhooon/7\354\233\224 3\354\243\274\354\260\250/\355\221\234\355\230\204 \352\260\200\353\212\245\355\225\234 \354\235\264\354\247\204\355\212\270\353\246\254.py" deleted file mode 100644 index 1f1499f..0000000 --- "a/easyhooon/7\354\233\224 3\354\243\274\354\260\250/\355\221\234\355\230\204 \352\260\200\353\212\245\355\225\234 \354\235\264\354\247\204\355\212\270\353\246\254.py" +++ /dev/null @@ -1,38 +0,0 @@ -# binary 라는 이진수의 L번지 부터 R번지 까지가 올바르게 포화 이진트리로 표현되느냐? -def solve(binary, L, R): - if L == R: - return True - - mid = (L + R) // 2 - root = binary[mid] - - left_child = binary[(L + (mid - 1)) // 2] - right_child = binary[((mid + 1) + R) // 2] - - if left_child == '1' and root == '0': - return False - - if right_child == '1' and root == '0': - return False - - return solve(binary, L, mid - 1) and solve(binary, mid + 1, R) - - -def solution(numbers): - answer = [] - - for elem in numbers: - binary = bin(elem)[2:] - tree_size = 1 - - while tree_size < len(binary): - tree_size = tree_size * 2 + 1 - - binary = '0' * (tree_size - len(binary)) + binary - - if solve(binary, 0, len(binary) - 1): - answer.append(1) - else: - answer.append(0) - - return answer diff --git "a/easyhooon/7\354\233\224 4\354\243\274\354\260\250/11779.py" "b/easyhooon/7\354\233\224 4\354\243\274\354\260\250/11779.py" deleted file mode 100644 index 5f0b98d..0000000 --- "a/easyhooon/7\354\233\224 4\354\243\274\354\260\250/11779.py" +++ /dev/null @@ -1,72 +0,0 @@ -# 최소 비용 구하기 2 - -# 최소 비용 -# 최소 비용을 갖는 경로에 포함되어있는 도시의 개수(출발, 도착 도시 포함 -# 경로를 방문하는 도시 순서대로 출력 - -import sys -import heapq - -si = sys.stdin.readline - - -def dijkstra(start, dist, edges): - pq = [] - heapq.heappush(pq, (0, start)) - dist[start] = 0 - - while pq: - # 현재 가장 가까운 노드와 그 노드까지의 거리 - min_dist, min_idx = heapq.heappop(pq) - - # 현재 노드가 이미 처리된 적이 있다면 무시 - if dist[min_idx] != min_dist: - continue - - # 현재 노드와 연결된 다른 노드를 확인 - for target_idx, target_dist in edges[min_idx]: - # 새로운 경로의 거리 - new_dist = dist[min_idx] + target_dist - # 새 경로의 거리가 기존 경로보다 짧다면 - if dist[target_idx] > new_dist: - # 경로 길이 갱신 - dist[target_idx] = new_dist - # 경로 정보 갱신(target_idx 로 가는 최단 경로 상에 바로 직전에 방문한 노드 min_idx) - path[target_idx] = min_idx - heapq.heappush(pq, (new_dist, target_idx)) - - return dist - - -n = int(si()) -m = int(si()) - -dist = [sys.maxsize for _ in range(n + 1)] -edges = [[] for _ in range(n + 1)] -path = [0] * (n + 1) - -for _ in range(m): - x, y, w = map(int, si().split()) - edges[x].append((y, w)) - -# 출발점의 도시번호, 도착점의 도시번호가 주어짐 -> 다익스트라 -start, end = map(int, si().split()) - -dist = dijkstra(start, dist, edges) -print(dist[end]) - -# 역순으로 경로를 구함 -# 도착지 end 에서 시작하여 -# 시작점 start 가 나올기 전 까지 path를 따라 움직임 -x = end -nodes = [] -nodes.append(end) - -while x != start: - x = path[x] - nodes.append(x) - -print(len(nodes)) - -for node in nodes[::-1]: - print(node, end = " ") \ No newline at end of file diff --git "a/easyhooon/7\354\233\224 4\354\243\274\354\260\250/17142.py" "b/easyhooon/7\354\233\224 4\354\243\274\354\260\250/17142.py" deleted file mode 100644 index a3075d5..0000000 --- "a/easyhooon/7\354\233\224 4\354\243\274\354\260\250/17142.py" +++ /dev/null @@ -1,65 +0,0 @@ -# 연구소3 -# 모든 빈칸에 바이러스를 퍼뜨리는 -# 비활성 바이러스 자리에는 바이러스를 퍼뜨릴 필요가 없다... -import sys -from collections import deque -from itertools import combinations - -si = sys.stdin.readline - -dx = [1, -1, 0, 0] -dy = [0, 0, 1, -1] - -n, m = map(int, si().split()) -virus = [] - -board = [list(map(int, si().split())) for _ in range(n)] - -for i in range(n): - for j in range(n): - if board[i][j] == 2: - virus.append((i, j)) - - -def in_range(x, y): - return 0 <= x < n and 0 <= y < n - - -def bfs(viruses): - dist = [[-1] * n for _ in range(n)] - q = deque(viruses) - for x, y in viruses: - dist[x][y] = 0 - - while q: - x, y = q.popleft() - for i in range(4): - nx, ny = x + dx[i], y + dy[i] - if in_range(nx, ny) and board[nx][ny] != 1 and dist[nx][ny] == -1: - dist[nx][ny] = dist[x][y] + 1 - q.append((nx, ny)) - - return dist - - -min_value = sys.maxsize -for com in combinations(virus, m): - dist = bfs(com) - # -sys.maxsize 같은 값으로 초기화 하면 안됨 - max_value = 0 - flag = True - for i in range(n): - for j in range(n): - # 바이러스 칸에는 방문을 안해도 된다. - if board[i][j] == 0 and dist[i][j] == -1: - flag = False - break - else: - if board[i][j] != 2: - max_value = max(max_value, dist[i][j]) - if not flag: - break - if flag: - min_value = min(min_value, max_value) - -print(min_value if min_value != sys.maxsize else -1) diff --git "a/easyhooon/7\354\233\224 4\354\243\274\354\260\250/5639.py" "b/easyhooon/7\354\233\224 4\354\243\274\354\260\250/5639.py" deleted file mode 100644 index 65a83f0..0000000 --- "a/easyhooon/7\354\233\224 4\354\243\274\354\260\250/5639.py" +++ /dev/null @@ -1,55 +0,0 @@ -# 이진 검색 트리 -import sys - -sys.setrecursionlimit(10 ** 6) - -si = sys.stdin.readline - -# 전위 순위 결과의 순서의 리스트를 통해 이진 탐색 트리를 구성하고 -# 그 트리의 후위 순회 결과를 출력 - -# (루트, 완쪽, 오른쪽) - - -# 후위 순위 -# start: 서브 트리의 시작 인덱스 -# end: 서브 트리의 끝 인덱스 -def post_order(start, end): - # 시작 인덱스가 끝 인덱스보다 크면 재귀 종료 - if start > end: - return - - # 루트 노드의 오른쪽 서브 트리가 시작되는 인덱스 - # 루트 노드보다 큰 값이 나오는 첫번재 인덱스 - division = end + 1 - # 전위 순회 리스트를 순회 하면서 - for i in range(start + 1, end + 1): - # 루트보다 큰 값을 찾으면 - if pre_order[start] < pre_order[i]: - # 그 인덱스를 division 으로 설정하고 - division = i - # 탈출 - break - - # 후위 순위 - # 루트의 왼쪽 서브 트리에 대해 같은 작업을 수행 - post_order(start + 1, division - 1) - # 루트의 오른쪽 서브트리에 대해 같은 작업을 수행 - post_order(division, end) - # 모든 자식 노드를 방문한 후에 루트 노드를 출력 - print(pre_order[start]) - - -pre_order = [] - -for line in sys.stdin: - pre_order.append(int(line)) - -# eof (end of file) -# while True: -# try: -# pre_order.append(int(si())) -# except: -# break - -post_order(0, len(pre_order) - 1) diff --git "a/easyhooon/7\354\233\224 4\354\243\274\354\260\250/\354\206\214\354\210\230 \354\260\276\352\270\260.py" "b/easyhooon/7\354\233\224 4\354\243\274\354\260\250/\354\206\214\354\210\230 \354\260\276\352\270\260.py" deleted file mode 100644 index 09825a0..0000000 --- "a/easyhooon/7\354\233\224 4\354\243\274\354\260\250/\354\206\214\354\210\230 \354\260\276\352\270\260.py" +++ /dev/null @@ -1,48 +0,0 @@ -from itertools import permutations -import math - - -# len(numbers) <= 7 -# 11과 011은 같은 숫자로 취급 - -def solution(numbers): - answer = 0 - # print(list(numbers)) - lst = [] - for i in range(1, len(numbers) + 1): - for elem in list(permutations(list(numbers), i)): - lst.append(elem) - - num_list = [] - for elem in lst: - num_list.append(int("".join(elem))) - # print(num_list) - num_list.sort() - n = num_list[-1] - - ### 에라토스테네스의 체 - is_prime = [True for _ in range(n + 1)] - sqrt_of_num = int(math.sqrt(n)) - - for i in range(2, sqrt_of_num + 1): - if not is_prime[i]: - continue - else: - j = 2 - while i * j <= n: - if is_prime[i * j]: - is_prime[i * j] = False - j += 1 - ### - - visited = [False for _ in range(n + 1)] - - for elem in num_list: - if elem < 2: - continue - - if is_prime[elem] and not visited[elem]: - visited[elem] = True - answer += 1 - - return answer \ No newline at end of file diff --git "a/easyhooon/7\354\233\224 4\354\243\274\354\260\250/\354\265\234\354\206\214 \354\247\201\354\202\254\352\260\201\355\230\225.py" "b/easyhooon/7\354\233\224 4\354\243\274\354\260\250/\354\265\234\354\206\214 \354\247\201\354\202\254\352\260\201\355\230\225.py" deleted file mode 100644 index d963a42..0000000 --- "a/easyhooon/7\354\233\224 4\354\243\274\354\260\250/\354\265\234\354\206\214 \354\247\201\354\202\254\352\260\201\355\230\225.py" +++ /dev/null @@ -1,15 +0,0 @@ -def solution(sizes): - for size in sizes: - size.sort() - - print(sizes) - - max_width = 0 - for i in range(len(sizes)): - max_width = max(max_width, sizes[i][0]) - - max_height = 0 - for i in range(len(sizes)): - max_height = max(max_height, sizes[i][1]) - - return max_width * max_height diff --git "a/easyhooon/7\354\233\2241\354\243\274\354\260\250/17070.py" "b/easyhooon/7\354\233\2241\354\243\274\354\260\250/17070.py" deleted file mode 100644 index 256878d..0000000 --- "a/easyhooon/7\354\233\2241\354\243\274\354\260\250/17070.py" +++ /dev/null @@ -1,62 +0,0 @@ -# 파이프 옮기기 -# 파이프가 밀 수 있는 방향은 총 3가지 오른, 아래, 오른 아래 대각 -# 밀면서 회전 시킬 수 있음 회전은 45도로만 가능 -# 미는 방향은 오른쪽, 아래 또는 오른족 아래 대각선 방향 -# 파이프의 한쪽 끝을 (n, n)으로 이동시키는 방법의 개수를 구하라 -# 시작점 (1,1) 1,2) 로 fix -# 이동시킬 수 없는 경우 0을 출력 -# dp[i,j,k] := 파이프의 끝점이 (i, j) 로 k 방향으로 도착할 수 있는 경우의 수 -# 벽이 존재 -> 벽이 있으면 이동 불가 -# dfs 로 풀면 시간 초과 3^(n^n) -import sys - -si = sys.stdin.readline - -n = int(si()) - -graph = [list(map(int, si().split())) for _ in range(n)] -dp = [[[0] * 3 for _ in range(n)] for _ in range(n)] -dist = [[0] * n for _ in range(n)] - -# 기저 -# 90도 꺾을 수 없기 때문에 모든 열의 0, 1 번 칸으론 이동 불가능 -# 이전 위치의 방향도 알 필요가 있음 -> 따라서 3차원으로 -# 0: 오른쪽, 1: 대각선, 2: 아래 -# 파이프의 길이가 존재, 파이프의 머리의 위치 -> 현재 위치의 k 값을 통해 파이프의 머리 위치는 확정 -# 대각으로 이동할때 대각선칸만 0이면 되는게 아니라 오른, 아래 모두 0이 아니여야 한다. -# 벽이 있을 경우의 대한 처리 -for i in range(1, n): - if graph[0][i] == 1: - break - else: - dp[0][i][0] = 1 - -for i in range(1, n): - for j in range(2, n): - for k in range(3): - if graph[i][j] == 0: - if k == 0: - dp[i][j][k] += dp[i][j - 1][0] - # if graph[i - 1][j] == 0 and graph[i][j - 1] == 0: - dp[i][j][k] += dp[i][j - 1][1] - - elif k == 1: - if graph[i - 1][j] == 0 and graph[i][j - 1] == 0: - dp[i][j][k] += dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1] + dp[i - 1][j - 1][2] - - elif k == 2: - dp[i][j][k] += dp[i - 1][j][2] - # if graph[i - 1][j] == 0 and graph[i][j - 1] == 0: - dp[i][j][k] += dp[i - 1][j][1] - -# print(dp[n - 1][n - 1]) -print(sum(dp[n - 1][n - 1])) - -# for i in range(n): -# for j in range(n): -# dist[i][j] = sum(dp[i][j]) -# -# for i in range(n): -# for j in range(n): -# print(dist[i][j], end=" ") -# print() diff --git "a/easyhooon/7\354\233\2241\354\243\274\354\260\250/2146.py" "b/easyhooon/7\354\233\2241\354\243\274\354\260\250/2146.py" deleted file mode 100644 index 4b666e3..0000000 --- "a/easyhooon/7\354\233\2241\354\243\274\354\260\250/2146.py" +++ /dev/null @@ -1,103 +0,0 @@ -# 다리 만들기 1 -# 1. BFS or DFS 로 각각의 섬 다르게 넘버링 해주기 -# 2. 두 섬을 잇는 최단거리의 다리를 찾는다 - -import sys -from collections import deque - -si = sys.stdin.readline - -# n <= 100 -n = int(si()) - -graph = [list(map(int, si().split())) for _ in range(n)] -num_graph = [[0] * n for _ in range(n)] -visited1 = [[False] * n for _ in range(n)] - -dx = [-1, 0, 1, 0] -dy = [0, -1, 0, 1] - - -def in_range(x, y): - return 0 <= x < n and 0 <= y < n - - -def inside(x, y, start_num): - flag = True - for i in range(4): - nx = x + dx[i] - ny = y + dy[i] - if in_range(nx, ny): - if num_graph[nx][ny] != start_num: - flag = False - return flag - - return flag - - -def bfs1(i, j, cnt): - q = deque() - q.append((i, j)) - - while q: - x, y = q.popleft() - for i in range(4): - nx = x + dx[i] - ny = y + dy[i] - if in_range(nx, ny) and not visited1[nx][ny] and graph[nx][ny] != 0: - visited1[nx][ny] = True - num_graph[nx][ny] = cnt - q.append((nx, ny)) - - -def bfs2(i, j, start_num): - visited2 = [[False] * n for _ in range(n)] - q = deque() - q.append((i, j, 0)) - visited2[i][j] = True - - while q: - x, y, cnt = q.popleft() - if num_graph[x][y] != start_num and num_graph[x][y] != 0: - # print(i, j, x, y) - # print(num_graph[i][j], num_graph[x][y]) - # print(cnt) - return cnt - - for i in range(4): - nx = x + dx[i] - ny = y + dy[i] - if in_range(nx, ny) and not visited2[nx][ny] and num_graph[nx][ny] != start_num: - visited2[nx][ny] = True - q.append((nx, ny, cnt + 1)) - - return sys.maxsize - - -cnt = 0 -for i in range(n): - for j in range(n): - if not visited1[i][j] and graph[i][j] != 0: - visited1[i][j] = True - cnt += 1 - num_graph[i][j] = cnt - bfs1(i, j, cnt) - -# print(num_graph) -# 최단 거리를 잇는 다리의 길이를 구하기 -min_len = sys.maxsize - -# 2개의 섬 씩 매칭을 시켜보면서 최단거리를 구해보자 -# n 이 100이라 4중 포문까지 해도 됨 -for i in range(1, cnt): - for k in range(n): - for l in range(n): - if num_graph[k][l] == i: - # 하지만 bfs 까지 들어가면 시간초과 -> 최적화 필요 (섬 외곽이 아닌 섬 내부점에서 시작할 경우 반드시 최소가 아님) - if not inside(k, l, i): - # 굳이 여기서 start_num과 end_num 을 지정해야 하나? - # 시작점과 0이 아닌 다른 점에 도달했을때 그 최초의 거리를 구하면 되는건데(도착점이 어떤 섬인지와 관계 없이) - min_len = min(min_len, bfs2(k, l, i)) - -print(min_len - 1) - diff --git "a/easyhooon/7\354\233\2241\354\243\274\354\260\250/21758.py" "b/easyhooon/7\354\233\2241\354\243\274\354\260\250/21758.py" deleted file mode 100644 index 2f56c49..0000000 --- "a/easyhooon/7\354\233\2241\354\243\274\354\260\250/21758.py" +++ /dev/null @@ -1,39 +0,0 @@ -# 꿀따기 -# 그리디, 누적합 -import sys - -si = sys.stdin.readline - -n = int(si()) -arr = [0] + list(map(int, si().split())) -max_honey_sum = -sys.maxsize -# 왼쪽부터 누적합 -# 오른쪽부터 누적합 차례로 구해놓자 -# 꿀통 i j 일때는 꿀통, j 가 양끝일때가 최대 -# i 꿀통 j 일때는 i, j 가 양끝일때가 최대 -# i j 꿀통일때는 i, 꿀통이 양끝일때가 최대 -# 왼쪽 부터 누적합 -prefix_sum = [0] * (n + 2) - -# 벌의 위치는 서로 다름, 벌통도 -# 꿀은 무조건 오른쪽 끝에 있는게 합을 크게 만들 수 있다.(꿀 위치 고정) -# 아 아님 꿀이 가운데에 있고 두 벌이 가운데로 향하는 방법도 있음(그래서 예제 3번이 답이 10) -# 일단 완탐으로 먼저 풀고 그다음에 최적화를 고민 -# 누적합은 방향에 따라 그 합이 달라진다 -> 그래두 한쪽 방향의 누적합으로도 풀 수 있다. - -for i in range(1, n + 1): - prefix_sum[i] = prefix_sum[i - 1] + arr[i] - -# 벌1, 벌2, 꿀통 -for i in range(2, n): - max_honey_sum = max(max_honey_sum, (prefix_sum[n] - prefix_sum[1] - arr[i]) + (prefix_sum[n] - prefix_sum[i])) - -# 꿀통 벌1, 벌2 -for i in range(2, n): - max_honey_sum = max(max_honey_sum, prefix_sum[i - 1] + prefix_sum[n - 1] - arr[i]) - -# 벌1 꿀통 벌2 -for i in range(2, n): - max_honey_sum = max(max_honey_sum, (prefix_sum[i] - arr[1]) + (prefix_sum[n - 1] - prefix_sum[i - 1])) - -print(max_honey_sum) diff --git "a/easyhooon/7\354\233\2241\354\243\274\354\260\250/\352\260\234\354\235\270\354\240\225\353\263\264 \354\210\230\354\247\221 \354\234\240\355\232\250\352\270\260\352\260\204.py" "b/easyhooon/7\354\233\2241\354\243\274\354\260\250/\352\260\234\354\235\270\354\240\225\353\263\264 \354\210\230\354\247\221 \354\234\240\355\232\250\352\270\260\352\260\204.py" deleted file mode 100644 index 421aa74..0000000 --- "a/easyhooon/7\354\233\2241\354\243\274\354\260\250/\352\260\234\354\235\270\354\240\225\353\263\264 \354\210\230\354\247\221 \354\234\240\355\232\250\352\270\260\352\260\204.py" +++ /dev/null @@ -1,72 +0,0 @@ -# 유효기간이 지났다면 반드시 수집된 개인정보는 파기해야 함 -# 오늘 날짜로 파기해야 할 개인정보 번호들을 구하려 함 -# 모든 달은 28일 까지 있다고 가정 -def solution(today, terms, privacies): - temp = today.split(".") - today = [] - for t in temp: - today.append(int(t)) - rule = {} - # 1 <= term <= 100 - for term in terms: - term_key = term[0] - term_value = int(term[1:]) - rule[term_key] = rule.get(term_key, 0) + term_value - - print(rule) - - n = len(privacies) - answer = [] - for i in range(n): - temp = privacies[i].split(" ") - start_day_str = temp[0] - rule_key = temp[1] - temp = start_day_str.split(".") - start_day = [] - - for t in temp: - start_day.append(int(t)) - - end_day = [] - plus_year = rule[rule_key] // 12 - plus_month = rule[rule_key] % 12 - # print(plus_year, plus_month) - - end_day.append(start_day[0] + plus_year) - end_day.append(start_day[1] + plus_month) - end_day.append(start_day[2] - 1) - - # print(end_day) - - # 날짜가 1일이었을때 - 1 해서 0 - if end_day[2] == 0: - end_day[1] -= 1 - end_day[2] = 28 - - # 문제의 부분 - if end_day[1] > 12: - # print(end_day[1], end_day[1] // 12, end_day[1] % 12) - add_plus_year = end_day[1] // 12 - - end_day[0] += add_plus_year - end_day[1] -= (12 * add_plus_year) - - # print(start_day, end_day) - - # 날짜 비교 - if today[0] > end_day[0]: - answer.append(i + 1) - continue - - elif today[0] == end_day[0]: - if today[1] > end_day[1]: - answer.append(i + 1) - continue - elif today[1] == end_day[1]: - if today[2] > end_day[2]: - answer.append(i + 1) - continue - - # print(answer) - - return answer \ No newline at end of file diff --git "a/easyhooon/7\354\233\2241\354\243\274\354\260\250/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" "b/easyhooon/7\354\233\2241\354\243\274\354\260\250/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" deleted file mode 100644 index 0631b85..0000000 --- "a/easyhooon/7\354\233\2241\354\243\274\354\260\250/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" +++ /dev/null @@ -1,39 +0,0 @@ -import heapq - -def solution(operations): - min_pq = [] - max_pq = [] - - for op in operations: - if op.startswith('I'): - num = int(op.split(' ')[1]) - heapq.heappush(max_pq, -num) - heapq.heappush(min_pq, num) - - elif op.startswith('D'): - # "-1" 이거 int 씌우면 -1 되나 -> 됨 - num = int(op.split(' ')[1]) - # 최댓값 삭제 - if num == 1: - if max_pq: - max_value = heapq.heappop(max_pq) - min_pq.remove(-max_value) - - # 최솟값 삭제 - else: - if min_pq: - min_value = heapq.heappop(min_pq) - max_pq.remove(-min_value) - # print(max_pq) - # print(min_pq) - # print() - - if max_pq and min_pq: - answer = [-max_pq[0], min_pq[0]] - - else: - answer = [0, 0] - - return answer - -# print(solution(["I 16", "I -5643", "D -1", "D 1", "D 1", "I 123", "D -1"])) \ No newline at end of file diff --git "a/easyhooon/8\354\233\224 2\354\243\274\354\260\250/12851.py" "b/easyhooon/8\354\233\224 2\354\243\274\354\260\250/12851.py" deleted file mode 100644 index 329aa11..0000000 --- "a/easyhooon/8\354\233\224 2\354\243\274\354\260\250/12851.py" +++ /dev/null @@ -1,58 +0,0 @@ -# 숨박꼭질 2 -from collections import deque -import sys - -# 방법의 가지수도 출력해야 함 - -si = sys.stdin.readline -# n 번째 칸을 가장 빠른 시간으로 찾는 방법 m 가지 -# 큰 수로 초기화 해놓고 -# n 번째 칸 (가장 빠른 시간, 방법 수) -# visited = [[sys.maxsize, 0]] * 100001 -visited = [[sys.maxsize, 0] for _ in range(100001)] - - -def bfs(start): - q = deque() - q.append((start, 0)) - visited[start][0] = 0 - visited[start][1] = 1 - while q: - num, cnt = q.popleft() - # print(num, cnt) - - if num == k: - print(visited[num][0]) - print(visited[num][1]) - return - - if (num * 2) <= 100000: - if cnt + 1 < visited[num * 2][0]: - visited[num * 2][0] = cnt + 1 - visited[num * 2][1] = 1 - q.append((num * 2, cnt + 1)) - elif cnt + 1 == visited[num * 2][0]: - visited[num * 2][1] += 1 - q.append((num * 2, cnt + 1)) - - if (num + 1) <= 100000: - if cnt + 1 < visited[num + 1][0]: - visited[num + 1][0] = cnt + 1 - visited[num + 1][1] = 1 - q.append((num + 1, cnt + 1)) - elif cnt + 1 == visited[num + 1][0]: - visited[num + 1][1] += 1 - q.append((num + 1, cnt + 1)) - - if (num - 1) >= 0: - if cnt + 1 < visited[num - 1][0]: - visited[num - 1][0] = cnt + 1 - visited[num - 1][1] = 1 - q.append((num - 1, cnt + 1)) - elif cnt + 1 == visited[num - 1][0]: - visited[num - 1][1] += 1 - q.append((num - 1, cnt + 1)) - - -n, k = map(int, si().split()) -bfs(n) diff --git "a/easyhooon/8\354\233\224 3\354\243\274\354\260\250/17352.py" "b/easyhooon/8\354\233\224 3\354\243\274\354\260\250/17352.py" deleted file mode 100644 index fb94ea9..0000000 --- "a/easyhooon/8\354\233\224 3\354\243\274\354\260\250/17352.py" +++ /dev/null @@ -1,44 +0,0 @@ -# 여러분의 다리가 되어 드리겠습니다! - -# 유니온 파인드를 통해 연결하는 것이 아닌, 유니온 파인드의 결과로 연결되지 않은 두 섬을 찾는 문제 -import sys -sys.setrecursionlimit(10**6) - -si = sys.stdin.readline - - -def union(x, y): - x = find(x) - y = find(y) - uf[x] = y - - -def find(x): - if uf[x] == x: - return x - - root_node = find(uf[x]) - uf[x] = root_node - return root_node - - -n = int(si()) -uf = [0] * (n + 1) - -for i in range(1, n + 1): - uf[i] = i - -for _ in range(n - 2): - x, y = map(int, si().split()) - union(x, y) - -roots = set() -for i in range(1, n + 1): - roots.add(uf[i]) - # roots.add(uf[i]) -> 틀림 - # roots.add(find(i)) - -# print(roots[0], roots[1]) -roots = list(roots) -# print(roots) -print(roots[0], roots[1]) diff --git "a/easyhooon/8\354\233\224 3\354\243\274\354\260\250/1744.py" "b/easyhooon/8\354\233\224 3\354\243\274\354\260\250/1744.py" deleted file mode 100644 index f81c495..0000000 --- "a/easyhooon/8\354\233\224 3\354\243\274\354\260\250/1744.py" +++ /dev/null @@ -1,46 +0,0 @@ -# 수 묶기 -import sys - -si = sys.stdin.readline - -n = int(si()) - -# arr = [] -# arr.sort() -# print(arr) - -positive_num = [] -negative_num = [] -zero = 0 -answer = 0 - -for _ in range(n): - num = int(si()) - if num > 1: - positive_num.append(num) - elif num == 1: - answer += 1 - elif num == 0: - zero += 1 - else: - negative_num.append(num) - -positive_num.sort(reverse=True) -negative_num.sort() - -while len(positive_num) > 1: - answer += positive_num.pop(0) * positive_num.pop(0) - -if positive_num: - answer += positive_num[0] - -while len(negative_num) > 1: - answer += negative_num.pop(0) * negative_num.pop(0) - -if negative_num and zero > 0: - negative_num.pop() - -if negative_num: - answer += negative_num[0] - -print(answer) diff --git "a/easyhooon/8\354\233\224 4\354\243\274\354\260\250/14226.py" "b/easyhooon/8\354\233\224 4\354\243\274\354\260\250/14226.py" deleted file mode 100644 index eb3ed18..0000000 --- "a/easyhooon/8\354\233\224 4\354\243\274\354\260\250/14226.py" +++ /dev/null @@ -1,48 +0,0 @@ -# 이모티콘 -import sys -from collections import deque - -si = sys.stdin.readline - -S = int(si()) - -# 화면에 이미 이모티콘 1개를 입력했다. -# 복사해서 클립보드에 저장 -# 붙혀넣기 -# 이모티콘 1개를 삭제 - -# 클립 보드가 비어있는 상태에는 붙혀넣기 불가능, 일부만 클립보드가 복사할 수 없음, 클립보드에 이모티콘 중 일부를 삭제할 수 없음 - - -# visited[화면의 이모티콘 수][클립보드의 이모티콘 수] = 방문 여부 -visited = [[0] * (2002) for _ in range(2002)] - - -def bfs(): - # 화면 이모티콘 수, 클립보드 이모티콘 수, 시간 - q = deque([(1, 0, 0)]) - - while q: - s, c, time = q.popleft() - - if s == S: - return time - - # 화면의 이모티콘을 클립보드에 복사 - if not visited[s][s]: - visited[s][s] = 1 - q.append((s, s, time + 1)) - - # 클립보드의 이모티콘을 화면에 붙여넣기 - # <= 1001 로 두면 범위 1001 x 1001 로 둬도 인덱스 에러가 나지 않는다 - if 0 < c <= S and not visited[s + c][c]: - visited[s + c][c] = 1 - q.append((s + c, c, time + 1)) - - # 화면의 이모티콘을 하나 삭제 - if 0 < s and not visited[s - 1][c]: - visited[s - 1][c] = 1 - q.append((s - 1, c, time + 1)) - - -print(bfs()) diff --git "a/easyhooon/8\354\233\224 4\354\243\274\354\260\250/20303.py" "b/easyhooon/8\354\233\224 4\354\243\274\354\260\250/20303.py" deleted file mode 100644 index 9e39a62..0000000 --- "a/easyhooon/8\354\233\224 4\354\243\274\354\260\250/20303.py" +++ /dev/null @@ -1,71 +0,0 @@ -# 할로윈의 양아치 - -# union-fin -# 최대로 뺏을 수 있는 사탕의 양(dp?) -import sys - -sys.setrecursionlimit(10 ** 6) - -si = sys.stdin.readline - - -def union(x, y): - x = find(x) - y = find(y) - uf[x] = y - - -def find(x): - if uf[x] == x: - return x - - root_node = find(uf[x]) - uf[x] = root_node - return root_node - - -# N 거리에 있는 아이들의 수, -# M 아이들의 친구 관계 수, -# K는 울음소리가 공명하기 위한 최소 아이의 수 -n, m, k = map(int, si().split()) -candy_arr = [0] + list(map(int, si().split())) - -print(candy_arr) - -uf = [0] * (n + 1) - -for i in range(1, n + 1): - uf[i] = i - -for _ in range(m): - x, y = map(int, si().split()) - union(x, y) - -print(uf) - -group_candy = [0] * (n + 1) -group_size = [0] * (n + 1) - -for i in range(1, n + 1): - root = find(i) - group_candy[root] += candy_arr[i] - group_size[root] += 1 - -arr = [] -for i in range(1, n + 1): - if group_size[i] > 0: - arr.append((group_size[i], group_candy[i])) - -print(arr) - -# dp[i] := i 명의 아이들한테 뺏을 수 있는 최대 사탕의 개수 -dp = [0] * (k + 1) -for size, candy in arr: - # 한 그룹을 여러번 선택하는 것을 방지하기 위해 역방향으로 순회 - for j in range(k, -1, -1): - # j(현재 용량) > size 일 경우 - if j - size >= 0: - dp[j] = max(dp[j], dp[j - size] + candy) - -# print(dp) -print(dp[k - 1]) diff --git "a/easyhooon/8\354\233\224 4\354\243\274\354\260\250/2138.py" "b/easyhooon/8\354\233\224 4\354\243\274\354\260\250/2138.py" deleted file mode 100644 index 7495a16..0000000 --- "a/easyhooon/8\354\233\224 4\354\243\274\354\260\250/2138.py" +++ /dev/null @@ -1,49 +0,0 @@ -# 전구와 스위치 -import sys - -si = sys.stdin.readline - -n = int(si()) -initial = list(si().strip()) -target = list(si().strip()) - -# 최댓값 sys.maxsize - -def flip(lst, idx): - if idx > 0: - lst[idx - 1] = '0' if lst[idx - 1] == '1' else '1' - lst[idx] = '0' if lst[idx] == '1' else '1' - if idx < n - 1: - lst[idx + 1] = '0' if lst[idx + 1] == '1' else '1' - - -# 임의의 큰 값을 sys.maxsize 로 두면 틀림 -def count_flips(current, target): - count = 0 - for i in range(1, n): - if current[i - 1] != target[i - 1]: - flip(current, i) - count += 1 - if current == target: - return count - - # return n + 2 - # return sys.maxsize - return float('inf') - - -# 첫 번째 전구를 누르는 경우와 누르지 않는 경우 -no_flip = initial[:] -flip_first = initial[:] -flip(flip_first, 0) - -result1 = count_flips(no_flip, target) -result2 = count_flips(flip_first, target) + 1 - - -# if result1 == sys.maxsize and result2 == sys.maxsize: -# if result1 == n + 2 and result2 == n + 2: -if result1 == float('inf') and result2 == float('inf'): - print(-1) -else: - print(min(result1, result2)) diff --git "a/easyhooon/8\354\233\224 4\354\243\274\354\260\250/2239.py" "b/easyhooon/8\354\233\224 4\354\243\274\354\260\250/2239.py" deleted file mode 100644 index 9b231b5..0000000 --- "a/easyhooon/8\354\233\224 4\354\243\274\354\260\250/2239.py" +++ /dev/null @@ -1,51 +0,0 @@ -# 스도쿠 - -import sys - -si = sys.stdin.readline - -row = [[False] * 10 for _ in range(10)] # i 번 행에 j라는 숫자가 이미 존재 -col = [[False] * 10 for _ in range(10)] # i 열에 j 라는 숫자가 이미 존재 -square = [[False] * 10 for _ in range(10)] # i번째 사각형에 j 라는 숫자가 존재 -board = [[0] * 9 for _ in range(9)] - - -def dfs(cnt): - x = cnt // 9 - y = cnt % 9 - if cnt == 81: - for i in range(9): - for j in range(9): - print(board[i][j], end="") - print() - exit(0) - - if board[x][y] == 0: - for i in range(1, 10): - if not row[x][i] and not col[y][i] and not square[(x // 3) * 3 + (y // 3)][i]: - row[x][i] = True - col[y][i] = True - square[(x // 3) * 3 + (y // 3)][i] = True - board[x][y] = i - - dfs(cnt + 1) - - board[x][y] = 0 - row[x][i] = False - col[y][i] = False - square[(x // 3) * 3 + (y // 3)][i] = False - else: - dfs(cnt + 1) - - -for i in range(9): - inp = si().strip() - for j in range(9): - board[i][j] = int(inp[j]) - if board[i][j] != 0: - # print(board[i][j]) - row[i][board[i][j]] = True - col[j][board[i][j]] = True - square[(i // 3) * 3 + (j // 3)][board[i][j]] = True - -dfs(0) \ No newline at end of file diff --git "a/easyhooon/8\354\233\224 4\354\243\274\354\260\250/temp123.py" "b/easyhooon/8\354\233\224 4\354\243\274\354\260\250/temp123.py" deleted file mode 100644 index 72df33e..0000000 --- "a/easyhooon/8\354\233\224 4\354\243\274\354\260\250/temp123.py" +++ /dev/null @@ -1,7 +0,0 @@ -import sys - -print(float('inf') < float('inf') + 1) - -print(float('inf')) -print(float('inf') + 1) -print(sys.maxsize) \ No newline at end of file diff --git "a/easyhooon/8\354\233\224 5\354\243\274\354\260\250/16637.py" "b/easyhooon/8\354\233\224 5\354\243\274\354\260\250/16637.py" deleted file mode 100644 index 5a106bf..0000000 --- "a/easyhooon/8\354\233\224 5\354\243\274\354\260\250/16637.py" +++ /dev/null @@ -1,74 +0,0 @@ -# 괄호 추가하기 -import sys - -si = sys.stdin.readline - -INT_MIN = -sys.maxsize - -max_result = INT_MIN - -def calc(num, op): - while op: - oper = op.pop(0) - n1, n2 = num.pop(0), num.pop(0) - if oper == '+': - num.insert(0, n1 + n2) - elif oper == '-': - num.insert(0, n1 - n2) - elif oper == '*': - num.insert(0, n1 * n2) - - return num[0] - - -# 백트래킹 -# cnt: 현재까지 고려한 연산자 수 -# num 숫자 모음 -# op 연산자 모음 -def choose(cnt, num, op): - global max_result - - # 종료 조건 - if cnt == n // 2 or len(num) == 1: - max_result = max(max_result, calc(num, op)) - return - - # 연산자를 사용하지 않는 경우 - choose(cnt + 1, num[:], op[:]) - - # 연산자를 사용하는 경우 - # -> num 리스트에서 2개의 원소가 있어야 하므로 조건을 추가 - if cnt + 1 < len(num): - n1, n2 = num[cnt], num[cnt + 1] - oper = op[cnt] - if oper == '+': - num[cnt] = n1 + n2 - elif oper == '-': - num[cnt] = n1 - n2 - elif oper == '*': - num[cnt] = n1 * n2 - - # 인덱스로 배열의 원소를 제거 - # del num[cnt + 1] - # del op[cnt] - num.pop(cnt + 1) - op.pop(cnt) - - choose(cnt + 1, num[:], op[:]) - -n = int(si()) -exp = si().strip() - -# 숫자와 연산자를 분리하여 담기 -num = [] -op = [] - -for i in range(n): - if i % 2 == 0: - num.append(int(exp[i])) - else: - op.append(exp[i]) - -choose(0, num, op) - -print(max_result) diff --git "a/easyhooon/8\354\233\224 5\354\243\274\354\260\250/20056.py" "b/easyhooon/8\354\233\224 5\354\243\274\354\260\250/20056.py" deleted file mode 100644 index 3dddcb1..0000000 --- "a/easyhooon/8\354\233\224 5\354\243\274\354\260\250/20056.py" +++ /dev/null @@ -1,84 +0,0 @@ -# 마법사 상어와 파이어볼 -import sys -from collections import defaultdict - -dx = [-1, -1, 0, 1, 1, 1, 0, -1] -dy = [0, 1, 1, 1, 0, -1, -1, -1] - -si = sys.stdin.readline - -n, m, k = map(int, si().split()) -graph = [[0] * n for _ in range(n)] -fireballs = [] - -# def move(): - - -# def merge(): - - -for i in range(1, m + 1): - # 위치(r, c), 질량 mi, 속력 s, 방향 d(0~7) - # r, c, mi, s, d = map(int, si().split()) - fireball = list(map(int, si().split())) - fireballs.append(fireball) - -info = defaultdict(list) -for r, c, m, s, d in fireballs: - info[(r - 1, c - 1)].append((m, s, d)) - -for _ in range(k): - new_info = defaultdict(list) - # move - for (x, y), vals in info.items(): - for m, s, d in vals: - # 격자의 행과 열은 1번부터 N번까지 번호가 매겨져 있고, 1번 행은 N번과 연결되어 있고, 1번 열은 N번 열과 연결되어 있다. - nx, ny = (x + dx[d] * s) % n, (y + dy[d] * s) % n - new_info[(nx, ny)].append((m, s, d)) - - # merge - for (x, y), vals in new_info.items(): - if len(vals) > 1: - total_mass = 0 - for m, _, _ in vals: - total_mass += m - total_speed = 0 - for _, s, _ in vals: - total_speed += s - directions = [] - for _, _, d in vals: - directions.append(d % 2) - - is_all_even = True - is_all_odd = True - - for _, _, d in vals: - if d % 2 == 0: - is_all_odd = False - - else: - is_all_even = False - - if is_all_even or is_all_odd: - new_fireballs = [] - for i in range(4): - # 질량이 0 보다 큰 것만 필터링 - if total_mass // 5 > 0: - new_fireballs.append((total_mass // 5, total_speed // len(vals), i * 2)) - new_info[(x, y)] = new_fireballs - - else: - new_fireballs = [] - for i in range(4): - if total_mass // 5 > 0: - new_fireballs.append((total_mass // 5, total_speed // len(vals), i * 2 + 1)) - new_info[(x, y)] = new_fireballs - - info = new_info - -result = 0 -for (x, y), vals in info.items(): - for m, _, _ in vals: - result += m - -print(result) diff --git "a/easyhooon/8\354\233\224 5\354\243\274\354\260\250/2573.py" "b/easyhooon/8\354\233\224 5\354\243\274\354\260\250/2573.py" deleted file mode 100644 index 358d47f..0000000 --- "a/easyhooon/8\354\233\224 5\354\243\274\354\260\250/2573.py" +++ /dev/null @@ -1,73 +0,0 @@ -# 빙산 -# bfs 진행 -> 마을의 개수가 처음으로 2개 이상일때 - -import sys -from collections import deque - -si = sys.stdin.readline - -dx = [-1, 0, 1, 0] -dy = [0, -1, 0, 1] - - -def in_range(x, y): - return 0 <= x < n and 0 <= y < m - - -def bfs(i, j): - q = deque() - q.append((i, j)) - - while q: - x, y = q.popleft() - - for k in range(4): - nx = x + dx[k] - ny = y + dy[k] - if in_range(nx, ny) and not visited[nx][ny] and board[nx][ny] == 0: - if board[x][y] > 0: - board[x][y] -= 1 - elif in_range(nx, ny) and not visited[nx][ny] and board[nx][ny] > 0: - visited[nx][ny] = True - q.append((nx, ny)) - - -n, m = map(int, si().split()) -board = [list(map(int, si().split())) for _ in range(n)] -time = 0 - - -while True: - visited = [[False] * m for _ in range(n)] - cnt = 0 - - for i in range(n): - for j in range(m): - if board[i][j] != 0 and not visited[i][j]: - visited[i][j] = True - bfs(i, j) - cnt += 1 - - # print(cnt) - # for i in range(n): - # for j in range(m): - # print(board[i][j], end=" ") - # print() - - # 빙산이 처음으로 분리된 경우 - if cnt > 1: - break - - # time 증가 - time += 1 - - # 빙산이 모두 녹았지만, 분리되지 않은 경우 - if cnt == 0: - time = 0 - break - -print(time) - - - - diff --git "a/easyhooon/9\354\233\224 1\354\243\274\354\260\250/1715.py" "b/easyhooon/9\354\233\224 1\354\243\274\354\260\250/1715.py" deleted file mode 100644 index dc347fc..0000000 --- "a/easyhooon/9\354\233\224 1\354\243\274\354\260\250/1715.py" +++ /dev/null @@ -1,24 +0,0 @@ -# 카드 정렬하기 - -import sys -import heapq - -si = sys.stdin.readline - -n = int(si()) -pq = [] - -for _ in range(n): - num = int(si()) - heapq.heappush(pq, num) - -min_sum = 0 -while len(pq) > 1: - num1 = heapq.heappop(pq) - num2 = heapq.heappop(pq) - min_sum += num1 + num2 - - heapq.heappush(pq, num1 + num2) - -print(min_sum) - diff --git "a/easyhooon/9\354\233\224 1\354\243\274\354\260\250/20057.py" "b/easyhooon/9\354\233\224 1\354\243\274\354\260\250/20057.py" deleted file mode 100644 index c47a8e8..0000000 --- "a/easyhooon/9\354\233\224 1\354\243\274\354\260\250/20057.py" +++ /dev/null @@ -1,168 +0,0 @@ -# 마법사 상어와 토네이도 -# 토네이도가 소멸되었을 때, 격자의 밖으로 나간 모래의 양을 구해보자. -import sys - -si = sys.stdin.readline - -n = int(si()) - -board = [list(map(int, si().split())) for _ in range(n)] -before_sand = 0 -for i in range(n): - for j in range(n): - if board[i][j] > 0 : - before_sand += board[i][j] - -map_dir = [ - # 왼쪽(0, -1) - [ - [0, 0, 2, 0, 0],볼 - [0, 10, 7, 1, 0], - [5, -1, 0, 0, 0], - [0, 10, 7, 1, 0], - [0, 0, 2, 0, 0] - ], - # 아래쪽(1, 0) - [ - [0, 0, 0, 0, 0], - [0, 1, 0, 1, 0], - [2, 7, 0, 7, 2], - [0, 10, -1, 10, 0], - [0, 0, 5, 0, 0] - ], - # 오른쪽(0, 1) - [ - [0, 0, 2, 0, 0], - [0, 1, 7, 10, 0], - [0, 0, 0, -1, 5], - [0, 1, 7, 10, 0], - [0, 0, 2, 0, 0] - ], - # 윗쪽(0, - 1) - [ - [0, 0, 5, 0, 0], - [0, 10, -1, 10, 0], - [2, 7, 0, 7, 2], - [0, 1, 0, 1, 0], - [0, 0, 0, 0, 0] - ] -] - -dxs, dys = [0, 1, 0, -1], [-1, 0, 1, 0] -x, y = n // 2, n // 2 -# 이동 방향 -move_dir = 0 -# 이동 횟수 -move_num = 1 - - -def in_range(r, c): - return 0 <= r < n and 0 <= c < n - - -def end(): - return not in_range(x, y) - - -def tornado(x, y, dx, dy): - # 토네이도가 이동하는 곳의 모래의 원래 양 - total_sand = board[x][y] - moved_sand = 0 - - # before - # for i in range(n): - # for j in range(n): - # print(board[i][j], end=" ") - # print() - - # 왼쪽 - if dx == 0 and dy == -1: - d = 0 - # 아래 - elif dx == 1 and dy == 0: - d = 1 - # 오른쪽 - elif dx == 0 and dy == 1: - d = 2 - # 위 - elif dx == -1 and dy == 0: - d = 3 - - # 모래가 퍼짐 - # a 로 이동하는 모래의 양은 비율이 적혀있는 칸으로 이동하지 않은 남은 모래의 양과 같다. - for i in range(5): - for j in range(5): - if map_dir[d][i][j] != 0: - val = 0 - # a 의 위치 일 경우 - if map_dir[d][i][j] == -1: - # 아직 안 퍼진 모래 양을 계산 - # val = total_sand - moved_sand - pass - else: - # 해당 위치에 퍼짐 비율만큼 모래 양을 계산 - val = (total_sand * map_dir[d][i][j]) // 100 - - # 퍼진 모래의 총량 갱신 - moved_sand += val - - # 실제 퍼짐 위치 계산(문제의 원인 후보) - # board 내에 좌표 - # 이게 아닌가 - nx = x + (i - 2) - ny = y + (j - 2) - - if in_range(nx, ny): - # 퍼진 그 위치에 모래를 추가 - board[nx][ny] += val - - - # a 위치에 모래 양 계산 - a_sand = total_sand - moved_sand - # # a 의 위치 - # if d == 0: - # a_x, a_y = x, y - 1 - # elif d == 1: - # a_x, a_y = x + 1, y - # elif d == 2: - # a_x, a_y = x, y + 1 - # else: - # a_x, a_y = x - 1, y - 1 - a_x, a_y = x + dx, y + dy - - if in_range(a_x, a_y): - # a 위치에 이미 모래가 존재할 수 있기 때문에 대입이 아니라 '추가' - board[a_x][a_y] += a_sand - # 원래 위치에 존재 했던 모래를 모두 제거 - board[x][y] -= total_sand - # print("total_sand", total_sand) - # print("moved_sand", moved_sand) - - # after - # for i in range(n): - # for j in range(n): - # print(board[i][j], end=" ") - # print() - - -# 빙글 빙글 시뮬레이션 -while not end(): - for _ in range(move_num): - x, y = x + dxs[move_dir], y + dys[move_dir] - if end(): - break - else: - # print(x, y) - tornado(x, y, dxs[move_dir], dys[move_dir]) - - move_dir = (move_dir + 1) % 4 - if move_dir == 0 or move_dir == 2: - move_num += 1 - -after_sand = 0 -for i in range(n): - for j in range(n): - if board[i][j] > 0: - after_sand += board[i][j] - -print(before_sand - after_sand) diff --git "a/easyhooon/9\354\233\224 1\354\243\274\354\260\250/2482.py" "b/easyhooon/9\354\233\224 1\354\243\274\354\260\250/2482.py" deleted file mode 100644 index badc2f2..0000000 --- "a/easyhooon/9\354\233\224 1\354\243\274\354\260\250/2482.py" +++ /dev/null @@ -1,51 +0,0 @@ -# 색상환 -import sys - -si = sys.stdin.readline -MOD = 10 ** 9 + 3 - -# 색상환에 포함된 색의 개수 -n = int(si()) -# 색상환에서 선택할 색의 개수 -k = int(si()) - -# n 색상환에서 어떤 인접한 두 색도 동시에 선택하지 않고 k개의 색을 고를 수 있는 경우의 수 -# 1 2 3 4 -# 1 3 -# 2 4 -# 2 (원형이기 때문에 1, 4 이렇게 고르면 1, 4 가 인접 -# dp[i][j]:= i 색상환에서 어떤 인접한 두 색도 동시에 선택하지 않고 j개의 색을 고를 수 있는 경우의 수 -# j는 i // 2 까지 -# rgb 거리 문제랑 비슷 -# 첫번째 칸 부터 채우느냐(마지막 칸 채울 수 없음), 두번째 칸 부터 채우느냐(마지막 칸 채울 수 있음) -# 둘다 안채워도 되긴하네 - -if n // 2 < k: - print(0) - exit(0) - -dp = [[0] * (k + 1) for _ in range(n + 1)] - -# 기저 조건 -for i in range(n + 1): - # 하나도 안채우는 경우 - dp[i][0] = 1 - # i 개의 칸 중에 1개만 택해서 채울 경우 - dp[i][1] = i - -# 점화식 채우기 -for i in range(2, n + 1): - for j in range(2, k + 1): - # dp[i][j] = (dp[i - 1][j] + dp[i - 2][j - 1]) % MOD - # i 번째 칸을 선택 하지 않을 경우 -> 이전 칸의 경우의 수 그대로 - dp[i][j] += dp[i - 1][j] % MOD - # i 번째 칸을 선택할 경우 -> i - 1 번째 칸 선택 불가, i - 2 번째 칸 까지, j - 1 개를 선택 - dp[i][j] += dp[i - 2][j - 1] % MOD - -# 마지막 칸을 선택하지 않는 경우와 선택하는 경우 -# 마지막 칸을 선택하면 사용할 수 있는 칸은 2번째 ~ n - 2번째 -# 이는 1번째 부터 n -3 번째까지 사용한 것과 같음 -print((dp[n - 1][k] + dp[n - 3][k - 1]) % MOD) - - - diff --git "a/easyhooon/9\354\233\224 1\354\243\274\354\260\250/3967.py" "b/easyhooon/9\354\233\224 1\354\243\274\354\260\250/3967.py" deleted file mode 100644 index 211840a..0000000 --- "a/easyhooon/9\354\233\224 1\354\243\274\354\260\250/3967.py" +++ /dev/null @@ -1,75 +0,0 @@ -# 매직스타 -import sys - -si = sys.stdin.readline - -board = [list(si().strip()) for _ in range(5)] -positions = [ - (0, 4), - (1, 1), (1, 3), (1, 5), (1, 7), - (2, 2), (2, 6), - (3, 1), (3, 3), (3, 5), (3, 7), - (4, 4) -] -# 순서의 이유타 -lines = [ - [positions[0], positions[2], positions[5], positions[7]], - [positions[0], positions[3], positions[6], positions[10]], - [positions[1], positions[2], positions[3], positions[4]], - [positions[7], positions[8], positions[9], positions[10]], - [positions[11], positions[9], positions[6], positions[4]], - [positions[11], positions[8], positions[5], positions[1]] -] -filled = [False] * 12 - - -def get_val(ch): - return ord(ch) - ord('A') + 1 - - -def validate(): - for line in lines: - line_sum = 0 - for pos in line: - line_sum += get_val(board[pos[0]][pos[1]]) - - if line_sum != 26: - return False - - return True - - -def dfs(idx): - # 가지치기 추가 - - - if idx == 12: - if validate(): - for row in board: - print(''.join(row)) - exit(0) - return - - x, y = positions[idx] - if board[x][y] == 'x': - for i in range(12): - if not filled[i]: - char = chr(ord('A') + i) - filled[i] = True - board[x][y] = char - - dfs(idx + 1) - - board[x][y] = 'x' - filled[i] = False - else: - dfs(idx + 1) - - -# 이미 존재하는 알파벳 방문 체크 -for i in range(5): - for j in range(9): - if 'A' <= board[i][j] <= 'L': - filled[ord(board[i][j]) - ord('A')] = True - -dfs(0) diff --git "a/easyhooon/9\354\233\224 3\354\243\274\354\260\250/11000.py" "b/easyhooon/9\354\233\224 3\354\243\274\354\260\250/11000.py" deleted file mode 100644 index 5798b4a..0000000 --- "a/easyhooon/9\354\233\224 3\354\243\274\354\260\250/11000.py" +++ /dev/null @@ -1,53 +0,0 @@ -# import sys -# import heapq -# -# si = sys.stdin.readline -# -# # n <= 200,000 -# n = int(si()) -# -# pq = [] -# -# for _ in range(n): -# start, end = map(int, si().split()) -# heapq.heappush(pq, (start, end)) -# -# # cnt = 1 -# before_end = [0] -# -# for _ in range(n): -# start, end = heapq.heappop(pq) -# for i in range(len(before_end)): -# if start >= before_end[i]: -# before_end[i] = end -# break -# else: -# # cnt += 1 -# before_end.append(start) -# -# # print(before_end) -# # print(cnt) -# print(len(before_end)) - -import sys -import heapq - -si = sys.stdin.readline - -n = int(si()) - -arr = [] -for _ in range(n): - start, end = map(int, si().split()) - arr.append((start, end)) - -arr.sort(key=lambda x: x[0]) - -pq = [] - -for start, end in arr: - if pq and pq[0] <= start: - heapq.heappop(pq) - heapq.heappush(pq, end) - -print(len(pq)) \ No newline at end of file diff --git "a/easyhooon/9\354\233\224 3\354\243\274\354\260\250/1644.py" "b/easyhooon/9\354\233\224 3\354\243\274\354\260\250/1644.py" deleted file mode 100644 index 7ad067e..0000000 --- "a/easyhooon/9\354\233\224 3\354\243\274\354\260\250/1644.py" +++ /dev/null @@ -1,54 +0,0 @@ -import sys -import math - -si = sys.stdin.readline - -n = int(si()) - -is_prime = [True] * (n + 1) -sqrt_of_n = int(math.sqrt(n)) - -for i in range(2, sqrt_of_n + 1): - if not is_prime: - continue - - else: - j = 2 - while i * j <= n: - if is_prime[i * j]: - is_prime[i * j] = False - j += 1 - -prime = [] -for i in range(2, n + 1): - if is_prime[i]: - prime.append(i) - -# print(prime) - -if n == 1: - print(0) - exit(0) - -left = 0 -right = 0 -cnt = prime[0] -answer = 0 - -while left <= right < len(prime): - if cnt <= n: - if cnt == n: - # print(prime[left], prime[right]) - answer += 1 - - # right index out of range - right += 1 - if right == len(prime): - break - cnt += prime[right] - - else: - cnt -= prime[left] - left += 1 - -print(answer) diff --git "a/easyhooon/9\354\233\224 3\354\243\274\354\260\250/2631.py" "b/easyhooon/9\354\233\224 3\354\243\274\354\260\250/2631.py" deleted file mode 100644 index edf29f9..0000000 --- "a/easyhooon/9\354\233\224 3\354\243\274\354\260\250/2631.py" +++ /dev/null @@ -1,40 +0,0 @@ -# LIS -# 최장 증가 부분 수열의 길이 출력 -# dp[i], i번 위치 까지 최장 증가 부분 수열의 길이 - -import sys - -si = sys.stdin.readline - -n = int(si()) -arr = [] - -for _ in range(n): - arr.append(int(si())) - -dp = [0] * n - - -def preprocess(): - for i in range(n): - dp[i] = -sys.maxsize - - dp[0] = 1 - - -preprocess() - -for i in range(1, n): - dp[i] = 1 - for j in range(0, i): - if arr[j] < arr[i] and dp[j] + 1 > dp[i]: - dp[i] = dp[j] + 1 - -len_lis = 0 -for i in range(n): - len_lis = max(len_lis, dp[i]) - -# print(len_lis) -print(n - len_lis) - - diff --git "a/easyhooon/9\354\233\224 4\354\243\274\354\260\250/2533.py" "b/easyhooon/9\354\233\224 4\354\243\274\354\260\250/2533.py" deleted file mode 100644 index 201d5a6..0000000 --- "a/easyhooon/9\354\233\224 4\354\243\274\354\260\250/2533.py" +++ /dev/null @@ -1,48 +0,0 @@ -# 사회망 서비스 -# 얼리어답터가 아닌 사람들은 자신의 모든 친구들이 얼리 어답터일 때만 이 아이디어를 받아들인다. -# 부모 노드가 일반인 -> 자식노드는 전부 얼리어답터여야 함 -# -> 자식 노드의 dp 값을 모두 더해줘야 함 -# 부모 노드가 얼리어답터일 경우 자식 노드가 얼리어답터이거나, 아닐 경우 둘 중 작은 dp 값을 더해줌 -# 0 -> 일반인, 1 -> 얼리어답터 -# dp[parent][0] += dp[child][1] -# dp[parent][1] += min(dp[child][0], dp[child][0] -# 1번 노드를 트리의 루트로 설정 -import sys - -sys.setrecursionlimit(10 ** 6) - -si = sys.stdin.readline - -n = int(si()) -# 필요한 최소 얼리어답터 수 -graph = [[] for _ in range(n + 1)] -dp = [[0 for _ in range(2)] for _ in range(10 ** 6 + 1)] -visited = [False] * (10 ** 6 + 1) -answer = 0 - - -def dfs(root): - visited[root] = True - # 기저 조건 - dp[root][1] = 1 - # 점화식 - for i in range(len(graph[root])): - child = graph[root][i] - if not visited[child]: - dfs(child) - dp[root][0] += dp[child][1] - dp[root][1] += min(dp[child][0], dp[child][1]) - - -for _ in range(n - 1): - u, v = map(int, si().split()) - graph[u].append(v) - # 양방향 연결 반드시 필요 - graph[v].append(u) - -# print(graph) - -dfs(1) - -answer = min(dp[1][0], dp[1][1]) -print(answer) diff --git "a/easyhooon/9\354\233\224 5\354\243\274\354\260\250/14925.py" "b/easyhooon/9\354\233\224 5\354\243\274\354\260\250/14925.py" deleted file mode 100644 index 360e11c..0000000 --- "a/easyhooon/9\354\233\224 5\354\243\274\354\260\250/14925.py" +++ /dev/null @@ -1,42 +0,0 @@ -# 목장 건설하기 -import sys - -INT_MIN = -sys.maxsize - -si = sys.stdin.readline - -m, n = map(int, si().split()) -graph = [list(map(int, si().split())) for _ in range(m)] - -# for i in range(m): -# for j in range(n): -# print(graph[i][j], end = " ") -# print() - -# 완탐 1000^4 -> 시간 부족 -> dp 아닐끼? 추론 -# dp[i][j] := (i,j)를 오른쪽 아래 꼭짓점으로 하는 가장 큰 정사각형의 한변의 길이 -# 이미 아는 계산은 dp 배열에 저장 -dp = [[0] * n for _ in range(m)] - -max_length = INT_MIN - -# 기저조건 -for i in range(m): - if graph[i][0] == 0: - dp[i][0] = 1 - max_length = 1 - -for j in range(n): - if graph[0][j] == 0: - dp[0][j] = 1 - max_length = 1 - -# 점화식 채우기 -for i in range(1, m): - for j in range(1, n): - if graph[i][j] == 0: - # 왼쪽, 위, 왼쪽 대각선 위의 최소값 + 1을 현재 위치의 값으로 설정 - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]) + 1 - max_length = max(max_length, dp[i][j]) - -print(max_length) diff --git "a/makie082/5\354\233\2241\354\243\274\354\260\250/1043.py" "b/makie082/5\354\233\2241\354\243\274\354\260\250/1043.py" deleted file mode 100644 index 3a24e97..0000000 --- "a/makie082/5\354\233\2241\354\243\274\354\260\250/1043.py" +++ /dev/null @@ -1,20 +0,0 @@ -import sys -input = sys.stdin.readline - -n, m = map(int, input().split()) -truePerson = set(map(int, input().split()[1:])) - -parties = [] -for _ in range(m): - parties.append(set(map(int, sys.stdin.readline().split()[1:]))) - -# 진실을 말해야하는 파티: True, 아닌 파티: False -cnt = [False] * m - -for _ in range(m):# 진실만 말하는 파티 찾기 위해 - for i, partyPeople in enumerate(parties): - if truePerson & partyPeople: # 진실을 아는 사람이 파티에 있다면(교집합이면) - cnt[i] = True - truePerson = truePerson | partyPeople # 파티의 모든 사람이 진실을 알아야함 - -print(cnt.count(False)) # 과장된 이야기를 할 수 있는 파티의 수 \ No newline at end of file diff --git "a/makie082/5\354\233\2242\354\243\274\354\260\250/27940.py" "b/makie082/5\354\233\2242\354\243\274\354\260\250/27940.py" deleted file mode 100644 index a9f0d57..0000000 --- "a/makie082/5\354\233\2242\354\243\274\354\260\250/27940.py" +++ /dev/null @@ -1,17 +0,0 @@ -import sys -input = sys.stdin.readline # 이거 안해줘도 시간초과 뜸 ㅜ ㅜ - -n, m, k = map(int, input().split()) - -floor = 0 -for i in range(m): # 비 - t, r = map(int, input().split()) # 영향이 가는 층, 파괴량 - - # 어차피 1층은 항상 영향을 받으니까 - # 1층만 고려해주면 됨! - floor += r - if floor > k: - print(i+1, 1) - exit() - -print(-1) \ No newline at end of file diff --git "a/makie082/5\354\233\2243\354\243\274\354\260\250/11508.py" "b/makie082/5\354\233\2243\354\243\274\354\260\250/11508.py" deleted file mode 100644 index fe92c0a..0000000 --- "a/makie082/5\354\233\2243\354\243\274\354\260\250/11508.py" +++ /dev/null @@ -1,27 +0,0 @@ -import sys -from collections import deque -input = sys.stdin.readline - -n = int(input()) -arr = [] - -for _ in range(n): - arr.append(int(input())) - -arr.sort(reverse=True) -arr = deque(arr) - -ans = 0 - -for i in range(len(arr)%3): - ans += arr.pop() - -cnt = 0 -for a in arr: - if cnt == 2: - cnt = 0 - continue - cnt += 1 - ans += a - -print(ans) \ No newline at end of file diff --git "a/makie082/5\354\233\2243\354\243\274\354\260\250/1759.py" "b/makie082/5\354\233\2243\354\243\274\354\260\250/1759.py" deleted file mode 100644 index 10c4224..0000000 --- "a/makie082/5\354\233\2243\354\243\274\354\260\250/1759.py" +++ /dev/null @@ -1,31 +0,0 @@ -from itertools import combinations - -l, c = map(int, input().split()) -alpha = sorted(list(input().split())) # 입력을 받자마자 정렬해주어야함 - -aeiou = ['a','e','i','o','u'] -total_case = list(combinations(alpha,l)) -remove_pw = [] - -for case in total_case: - m_cnt = 0 - - for c in case: - if c in aeiou: - m_cnt += 1 - - if m_cnt < 1: # 모음이 1개 미만이면 - remove_pw.append(case) - - elif l - m_cnt < 2: # 자음이 2개 미만이라면 - remove_pw.append(case) - -answer = set(total_case) - set(remove_pw) -answer = list(answer) -answer = sorted(answer) - -for ans in answer: - answ = sorted(list(ans)) - for i in answ: - print(i, end='') - print("") diff --git "a/makie082/5\354\233\2243\354\243\274\354\260\250/2503.py" "b/makie082/5\354\233\2243\354\243\274\354\260\250/2503.py" deleted file mode 100644 index 84775ad..0000000 --- "a/makie082/5\354\233\2243\354\243\274\354\260\250/2503.py" +++ /dev/null @@ -1,29 +0,0 @@ -from itertools import permutations - -t = int(input()) -nums = list(permutations([1,2,3,4,5,6,7,8,9],3)) - -for _ in range(t): - guess, strike, ball = map(int,input().split()) - guess = list(str(guess)) - checked = [] - removed_cnt = 0 - - for num in nums: - b = 0 - s = 0 - - for n in range(3): - if str(num[n]) in guess: - if n == guess.index(str(num[n])): # 위치까지 같으면 - s += 1 # strike 올려줌 - else: # 위치는 다르면 - b += 1 # ball 추가 - - if s != strike or b != ball: - checked.append(num) - - nums = set(nums) - set(checked) - nums = list(nums) - -print(len(nums)) \ No newline at end of file diff --git "a/makie082/6\354\233\2241\354\243\274\354\260\250/2023.py" "b/makie082/6\354\233\2241\354\243\274\354\260\250/2023.py" deleted file mode 100644 index 900c5ac..0000000 --- "a/makie082/6\354\233\2241\354\243\274\354\260\250/2023.py" +++ /dev/null @@ -1,21 +0,0 @@ -n = int(input()) # n자리수 - -def checkSosu(num): - if num == 1: - return False - for i in range(2, int(num**0.5)+1): - if num % i == 0: - return False - return True - -def dfs(num): - if len(str(num)) == n: # n자리 수이면 - print(num) - return - for i in range(1,10,2): - if checkSosu(num*10+i): - dfs(num*10+i) - return - -for a in [2,3,5,7]: - dfs(a) \ No newline at end of file diff --git "a/makie082/6\354\233\2241\354\243\274\354\260\250/2212.py" "b/makie082/6\354\233\2241\354\243\274\354\260\250/2212.py" deleted file mode 100644 index a363186..0000000 --- "a/makie082/6\354\233\2241\354\243\274\354\260\250/2212.py" +++ /dev/null @@ -1,23 +0,0 @@ -n = int(input()) -k = int(input()) -sensor = list(map(int,input().split())) -sensor.sort() - -dis = [] - -for i in range(n-1): - dis.append(sensor[i+1]-sensor[i]) - -maxd = 0 -for d in dis: - if maxd < d: - maxd = d - -sorted_dis = sorted(dis) - -result = 0 -# 뒤에서 k-1개를 제외하고 더해줌 -for sd in range(len(sorted_dis)-k+1): - result += sorted_dis[sd] - -print(result) \ No newline at end of file diff --git "a/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/1041-\354\243\274\354\202\254\354\234\204.py" "b/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/1041-\354\243\274\354\202\254\354\234\204.py" deleted file mode 100644 index 6094343..0000000 --- "a/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/1041-\354\243\274\354\202\254\354\234\204.py" +++ /dev/null @@ -1,25 +0,0 @@ -# 주사위 - -N = int(input()) -arr = list(map(int, input().split())) - -dice = [0, 0, 0] -dice[0] = min(arr[0], arr[5]) -dice[1] = min(arr[1], arr[4]) -dice[2] = min(arr[2], arr[3]) -dice.sort() -# print(dice) - -if N != 1: - num1 = dice[0] - num2 = dice[0] + dice[1] - num3 = dice[0] + dice[1] + dice[2] - - edge = 4 # 모서리 4개 - side2 = (N-1)*4 + (N-2)*4 # 세로 기둥 4개 윗면 모서리 빼고 4개 - side1 = (N-1)*(N-2)*4 + (N-2)**2 # 나머지 4개 윗면 가운데 - ans = side1 * num1 + side2 * num2 + edge * num3 - print(ans) -else: - ans = sum(arr) - max(arr) - print(ans) \ No newline at end of file diff --git "a/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/10942-\355\216\240\353\246\260\353\223\234\353\241\254.py" "b/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/10942-\355\216\240\353\246\260\353\223\234\353\241\254.py" deleted file mode 100644 index cdb1177..0000000 --- "a/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/10942-\355\216\240\353\246\260\353\223\234\353\241\254.py" +++ /dev/null @@ -1,48 +0,0 @@ -# 펠린드롬 -import sys -input = sys.stdin.readline - -N = int(input()) -num = list(input().split()) -M = int(input()) -dp = [[0 for _ in range(N)] for _ in range(N)] - -for i in range(N): # 길이가 1 - dp[i][i] = 1 - -for i in range(N-1): # 길이가 2 - if num[i] == num[i+1]: - dp[i][i+1] = 1 - -for i in range(2, N): # 길이가 3이상 - for j in range(N-i): - # 양 끝이 같고 그사이의 값들이 다 펠린드롬일 경우 - if num[j] == num[j+i] and dp[j+1][j+i-1] == 1: - dp[j][i+j] = 1 - -for i in dp: - print(i) - -for i in range(M): - start, end = map(int, input().split()) - print(dp[start-1][end-1]) - - - - - - - - - - - -def function(a, b): - temp = num[a:b] - rev = list(reversed(temp)) - # print(temp) - # print(rev) - if temp == rev: - return 1 - else: - return 0 \ No newline at end of file diff --git "a/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/14719-\353\271\227\353\254\274.py" "b/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/14719-\353\271\227\353\254\274.py" deleted file mode 100644 index 99c185a..0000000 --- "a/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/14719-\353\271\227\353\254\274.py" +++ /dev/null @@ -1,30 +0,0 @@ -# 빗물 - -H, W = map(int, input().split()) -arr = list(map(int, input().split())) - -top = max(arr) -idx = arr.index(top) -# print(top, idx) - -ans = 0 -height = 0 -# 왼쪽 -for i in range(idx+1): # 최고 높이까지 - if height < arr[i]: # 왼쪽 벽을 갱신 - height = arr[i] - else: # 왼쪽 벽보다 낮으면 물이 채워짐 - ans += height-arr[i] # 왼쪽 높이 - 현재높이 - # print(ans) - -height = 0 - -# 오른쪽 -for i in range(W-1, idx, -1): - if height < arr[i]: - height = arr[i] - else: - ans += height - arr[i] - # print(ans) - -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/15486-\355\207\264\354\202\2542.py" "b/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/15486-\355\207\264\354\202\2542.py" deleted file mode 100644 index ddfda14..0000000 --- "a/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/15486-\355\207\264\354\202\2542.py" +++ /dev/null @@ -1,22 +0,0 @@ -# 퇴사2 - -N = int(input()) # N 입력 -day = [] # 날 -money = [] # 수익 -dp = [0] * (1500000 + 50) # dp 1500000 + 50 - -for i in range(N): # N 만큼 반복 - t, p = map(int, input().split()) # 상담일이랑 값 - day.append(t) # 추가 - money.append(p) # 추가 -# print(day) -# print(money) - -for i in range(N): # N 만큼 반복 - if dp[i] > dp[i + 1]: # 다음날 값보다 현재 수익이 크다면 - dp[i + 1] = dp[i] # 위치 바꾸기 - if dp[i + day[i]] < dp[i] + money[i]: # 현재수익과 i일 뒤의 수익 비교 - dp[i + day[i]] = dp[i] + money[i] # 큰걸로 갱신 - # print(dp) - -print(dp[N]) \ No newline at end of file diff --git "a/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/\354\235\264\353\252\250\355\213\260\354\275\230_\355\225\240\354\235\270\355\226\211\354\202\254.py" "b/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/\354\235\264\353\252\250\355\213\260\354\275\230_\355\225\240\354\235\270\355\226\211\354\202\254.py" deleted file mode 100644 index bbbf393..0000000 --- "a/parkjunyoung/4\354\233\2243\354\243\274\354\260\250/\354\235\264\353\252\250\355\213\260\354\275\230_\355\225\240\354\235\270\355\226\211\354\202\254.py" +++ /dev/null @@ -1,40 +0,0 @@ -# 이모티콘 할인 행사 -from itertools import product - - -def solution(users, emoticons): - answer = [] - num1 = len(emoticons) - num2 = len(users) - sale = [10, 20, 30, 40] - sales = list(product([10, 20, 30, 40], repeat=num1)) - max_cnt = 0 - max_hap = 0 - # 일단 순열을 다돌면서 가격정하고 구매하기 - for i in range(len(sales)): # 중복순열에서 나온 할인율 - user_hap = [0] * num2 # 유저의 이모티콘 가격의 합 - cnt = 0 # 서비스 가입자 수 - for j in range(num1): - temp = int(emoticons[j] * ((100 - sales[i][j]) * 0.01)) # 해당이모티콘의 가격 - for k in range(num2): - if users[k][0] <= sales[i][j]: # user의 할인율보다 클 경우 - user_hap[k] += temp # 구매 - # print(user_hap) - - # 이모티콘을 살지 말지 정하고 가입자수 정하기 - for j in range(num2): - if user_hap[j] >= users[j][1]: # 가격이상 이면 - cnt += 1 # 가입자 늘리고 - user_hap[j] = 0 # 구매가격 0 - # print(sum(user_hap), cnt) - - # 가입자의 최대값이 먼저고 그다음이 가격 - if cnt >= max_cnt: - if cnt == max_cnt: # 가입자수가 최대값이랑 같다면 - max_hap = max(max_hap, sum(user_hap)) # 구매가격 최대값 비교 - else: - max_hap = sum(user_hap) # 아니면 갱신 - max_cnt = cnt # 갱신 - - answer = [max_cnt, max_hap] - return answer \ No newline at end of file diff --git "a/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/1068-\355\212\270\353\246\254.py" "b/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/1068-\355\212\270\353\246\254.py" deleted file mode 100644 index f88a131..0000000 --- "a/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/1068-\355\212\270\353\246\254.py" +++ /dev/null @@ -1,24 +0,0 @@ -# 트리 - -N = int(input()) -node = list(map(int, input().split())) -remove_node = int(input()) - - -def dfs(num): - node[num] = 51 - for i in range(N): - if node[i] == num: - dfs(i) - - -dfs(remove_node) -# print(node) - -cnt = 0 -for i in range(N): - if node[i] != 51: - if i not in node: - cnt += 1 - -print(cnt) \ No newline at end of file diff --git "a/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/11404-\355\224\214\353\241\234\354\235\264\353\223\234.py" "b/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/11404-\355\224\214\353\241\234\354\235\264\353\223\234.py" deleted file mode 100644 index 744a65b..0000000 --- "a/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/11404-\355\224\214\353\241\234\354\235\264\353\223\234.py" +++ /dev/null @@ -1,37 +0,0 @@ -# 플로이드 -import sys -input = sys.stdin.readline -INF = int(1e9) - -n = int(input()) -m = int(input()) - -# 2차원 리스트를 만들고, 무한으로 초기화 -graph = [[INF] * (n + 1) for _ in range(n + 1)] -for a in range(1, n + 1): - for b in range(1, n + 1): - if a == b: - graph[a][b] = 0 - -# 각 간선에 대한 정보를 입력 받아, 그 값으로 초기화 -for _ in range(m): - # A에서 B로 가는 비용은 C라고 설정 - a, b, c = map(int, input().split()) - if graph[a][b] > c: - graph[a][b] = c - -# 점화식에 따라 플로이드 워셜 알고리즘을 수행 -for k in range(1, n +1): - for i in range(1, n + 1): - for j in range(1, n + 1): - if i != j and graph[i][j] > graph[i][k] + graph[k][j]: - graph[i][j] = graph[i][k] + graph[k][j] - - -for a in range(1, n + 1): - for b in range(1, n + 1): - if graph[a][b] == INF: - print(0, end=" ") - else: - print(graph[a][b], end=" ") - print() diff --git "a/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/2342-Dance_Dance_Revolution.py" "b/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/2342-Dance_Dance_Revolution.py" deleted file mode 100644 index 7a86427..0000000 --- "a/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/2342-Dance_Dance_Revolution.py" +++ /dev/null @@ -1,42 +0,0 @@ -# Dance Dance Revolution - -cmd = list(map(int, input().split())) - -# 왼발 오른발에 따른 패턴 5 * 5 -# 전체 100000 - -dp = [[[999999 for _ in range(5)] for _ in range(5)] for _ in range(100001)] -# 초기값 -dp[0][0][0] = 0 - - -# 힘 계산 -def power(x, y): - if x == y: # 현재랑 같다면 - return 1 - elif x == 0: # 현재가 0이면 어딜가도 2 - return 2 - elif abs(x - y) == 1 or abs(x - y) == 3: # 차이가 1이나 3이면 - return 3 - else: # 나머지 4 - return 4 - - -for i in range(1, len(cmd)): - for r in range(5): - for l in range(5): - temp1 = power(r, cmd[i-1]) - temp2 = power(l, cmd[i-1]) - dp[i][cmd[i-1]][l] = min(dp[i][cmd[i-1]][l], dp[i-1][r][l] + temp1) - dp[i][r][cmd[i-1]] = min(dp[i][r][cmd[i-1]], dp[i-1][r][l] + temp2) - -# for i in range(len(cmd)): -# for j in dp[i]: -# print(j) - -hap = 999999 -for i in range(5): - for j in range(5): - hap = min(hap, dp[len(cmd)-1][i][j]) - -print(hap) \ No newline at end of file diff --git "a/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/7576_\355\206\240\353\247\210\355\206\240.py" "b/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/7576_\355\206\240\353\247\210\355\206\240.py" deleted file mode 100644 index 1a17da1..0000000 --- "a/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/7576_\355\206\240\353\247\210\355\206\240.py" +++ /dev/null @@ -1,46 +0,0 @@ -# 토마토 - -from collections import deque - -dr = [1, 0, -1, 0] # 하좌상우 -dc = [0, -1, 0, 1] - - -def bfs(): # bfs 함수 - while queue: # q 가 있으면 - r, c = queue.popleft() # pop 하고 - for d in range(4): # 방향 정해서 - nr = r + dr[d] - nc = c + dc[d] - if 0 <= nr < N and 0 <= nc < M and tomato[nr][nc] == 0: # 값이 0 일때 - tomato[nr][nc] = tomato[r][c] + 1 # 1씩 추가하고 - queue.append((nr, nc)) # q 에 추가 하고 - - -M, N = map(int, input().split()) # 상자 크기 입력 -tomato = [] # -for i in range(N): - mato = list(map(int, input().split())) # 토마토 상태 입력 - tomato.append(mato) -queue = deque() # q 를 여기서 안하면 bfs 돌릴때 1이 여러개일때 찾지 못햇음 -for i in range(N): # 상자를 다돌며 - for j in range(M): - if tomato[i][j] == 1: # 1 이 있다면 - queue.append((i, j)) # q 에 추가 -bfs() # bfs 를 돌린다. -min_day = 0 # 최소 날짜 -ans = 0 # -1 일 경우 -for i in tomato: # 전체 탐색 - for j in i: - if j == 0: # 0 이 있다면 - ans = -1 # 모두 안익어서 -1 - break # 멈춰 - else: # 0이 없으면 - min_day = (max(min_day, j)) # 최대값을 갱신하면서 저장한다 -if ans == -1: # ans -1 이면 - print(-1) # 모두안익어서 -1 출력 -else: - print(min_day-1) # 최소날짜에서 1빼기 - -for i in tomato: - print(i) \ No newline at end of file diff --git "a/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/9935-\353\254\270\354\236\220\354\227\264_\355\217\255\353\260\234.py" "b/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/9935-\353\254\270\354\236\220\354\227\264_\355\217\255\353\260\234.py" deleted file mode 100644 index a42304a..0000000 --- "a/parkjunyoung/4\354\233\2244\354\243\274\354\260\250/9935-\353\254\270\354\236\220\354\227\264_\355\217\255\353\260\234.py" +++ /dev/null @@ -1,19 +0,0 @@ -# 문자열 폭발 - -word = list(input()) -boom = list(input()) -num = len(boom) -stack = [] -for i in word: # 전체 리스트를 돌면서 - stack.append(i) # 하나씩 체크 - if num <= len(stack): # 현재 길이가 폭발 길이보다 길고 - if boom == stack[-num:]: # 스택의 뒤에서 체크했을때 폭발 문자열과 같으면 - for j in range(num): # 길이만큼 pop - stack.pop() - - # print(stack) - -if stack: - print("".join(stack)) -else: - print("FRULA") \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/1043-\352\261\260\354\247\223\353\247\220.py" "b/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/1043-\352\261\260\354\247\223\353\247\220.py" deleted file mode 100644 index 528bbee..0000000 --- "a/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/1043-\352\261\260\354\247\223\353\247\220.py" +++ /dev/null @@ -1,53 +0,0 @@ -# 거짓말 -from collections import deque - -N, M = map(int, input().split()) -true = list(map(int, input().split())) -true = true[1:] -know_member = [0] * (N+1) # 진실을 아는 사람 체크 -for i in true: - know_member[i] = 1 -# print(know_member) - -party_member = [] # 파티별 사람 체크 - - -tree = [[] for _ in range(N+1)] # 관계 트리? -for i in range(M): # 모든 파티를 돌면서 관계를 체크한다음 bfs 돌려야댐 - person = list(map(int, input().split())) - num = person[0] - person = person[1:] - party_member.append(person) # 파티 맴버에 넣어주고 - for j in range(num): - for k in range(j+1, num): - tree[person[j]].append(person[k]) # 관계 연결 - tree[person[k]].append(person[j]) # 쌍방향 - - -# print(tree) - - -def bfs(a): - q = deque() - q.append(a) - while q: - now = q.popleft() - for i in tree[now]: # 연결된 사람들 중 - if not know_member[i]: # 아는 사람에 체크가 안되어있으면 - know_member[i] = 1 # 체크하고 - q.append(i) # 다시 추가 - - -for i in range(len(know_member)): - if know_member[i]: # 내가 알고있다면 - bfs(i) # 나랑 만난사람들 체크 - -# print(know_member) -# print(party_member) -ans = M -for i in party_member: # 해당 파티에서 - for j in i: # 참가한 사람중에 - if know_member[j] == 1: # 거짓말을 안다면 - ans -= 1 # -1 - break -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/1106-\355\230\270\355\205\224.py" "b/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/1106-\355\230\270\355\205\224.py" deleted file mode 100644 index f38f9d2..0000000 --- "a/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/1106-\355\230\270\355\205\224.py" +++ /dev/null @@ -1,18 +0,0 @@ -# 호텔 - -C, N = map(int, input().split()) -dp = [9999999] * 1101 -dp[0] = 0 -ans = 9999999 -arr = [] -for i in range(N): - temp = list(map(int, input().split())) - arr.append(temp) - -for cost, num in arr: # 호텔들을 돌면서 - for i in range(num, 1101): # 1001로 햇더니 틀림... - dp[i] = min(dp[i], dp[i-num] + cost) # 현재고객 수 일때의 최솟 가격 - if i >= C: # 고객의 최솟값 - ans = min(ans, dp[i]) - -print(ans) diff --git "a/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/1202-\353\263\264\354\204\235_\353\217\204\353\221\221.py" "b/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/1202-\353\263\264\354\204\235_\353\217\204\353\221\221.py" deleted file mode 100644 index 2974a82..0000000 --- "a/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/1202-\353\263\264\354\204\235_\353\217\204\353\221\221.py" +++ /dev/null @@ -1,32 +0,0 @@ -# 보석 도둑 -import heapq -import sys -input = sys.stdin.readline - -N, K = map(int, input().split()) -items = [] -for i in range(N): - M, V = map(int, input().split()) - items.append([M, V]) -items.sort() - -bag = [] -for i in range(K): - C = int(input()) - bag.append(C) -bag.sort() -ans = [0] * K # 각 가방의 최대 보석의 크기 -temp = [] # 가능한 보석담기 - -for i in range(K): - while items and bag[i] >= items[0][0]: # for 문 돌리니 시간초과,, - w, cost = heapq.heappop(items) # 우선순위큐로 맨앞의 값을 빼고 - heapq.heappush(temp, (-cost, w)) # 넣어줄때 -로 넣어서 가장 큰 보석이 맨앞에 오도록 - - if temp: # 가능한 보석중에 - # print(temp) - w, cost = heapq.heappop(temp) # 제일 큰 보석 넣기 - ans[i] = -w # 부호 반대로 넣기 - - -print(sum(ans)) # 합 \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/14578-\354\230\201\355\233\210\354\235\264\354\235\230 \354\203\211\354\271\240\352\263\265\353\266\200.py" "b/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/14578-\354\230\201\355\233\210\354\235\264\354\235\230 \354\203\211\354\271\240\352\263\265\353\266\200.py" deleted file mode 100644 index 1ba0514..0000000 --- "a/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/14578-\354\230\201\355\233\210\354\235\264\354\235\230 \354\203\211\354\271\240\352\263\265\353\266\200.py" +++ /dev/null @@ -1,19 +0,0 @@ -# 영훈이의 색칠공부 - -N = int(input()) -ans = 0 - -dp = [0] * 100001 -dp[0] = 0 -dp[1] = 0 -dp[2] = 1 -fact = 1 - -for i in range(3, N+1): - dp[i] = ((i-1) * (dp[i-1]+dp[i-2])) % 1000000007 - -for i in range(1, N+1): - fact *= i - fact = fact % 1000000007 - -print((fact * dp[N]) % 1000000007) \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/16724-\355\224\274\353\246\254_\353\266\200\353\212\224_\354\202\254\353\202\230\354\235\264.py" "b/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/16724-\355\224\274\353\246\254_\353\266\200\353\212\224_\354\202\254\353\202\230\354\235\264.py" deleted file mode 100644 index 85b491a..0000000 --- "a/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/16724-\355\224\274\353\246\254_\353\266\200\353\212\224_\354\202\254\353\202\230\354\235\264.py" +++ /dev/null @@ -1,40 +0,0 @@ -# 피리 부는 사나이 - - -d = {'U': [-1, 0], 'D': [1, 0], 'L': [0, -1], 'R': [0, 1]} -N, M = map(int, input().split()) -pan = [] -for i in range(N): - arr = list(input()) - pan.append(arr) -# for i in pan: -# print(i) -visited = [[-1 for _ in range(M)] for _ in range(N)] -ans = 0 -cnt = 0 - - -def dfs(x, y, cnt): - global ans - if visited[x][y] != -1: # 방문을 했는데 - if visited[x][y] == cnt: # 지금이랑 같은 싸이클이면 - ans += 1 # + 1 - return # 멈춰 - visited[x][y] = cnt # 현재 싸이클 - dir = d[pan[x][y]] # 방향 - nx = x + dir[0] - ny = y + dir[1] - if 0 <= nx < N and 0 <= ny < M: # 범위 안이면 - dfs(nx, ny, cnt) # 싸이클 돌기 - - -for i in range(N): - for j in range(M): - if visited[i][j] == -1: # 방문 체크 - dfs(i, j, cnt) - cnt += 1 - -# for i in visited: -# print(i) - -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/2141-\354\232\260\354\262\264\352\265\255.py" "b/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/2141-\354\232\260\354\262\264\352\265\255.py" deleted file mode 100644 index 1594e5d..0000000 --- "a/parkjunyoung/5\354\233\2241\354\243\274\354\260\250/2141-\354\232\260\354\262\264\352\265\255.py" +++ /dev/null @@ -1,22 +0,0 @@ -# 우체국 -import sys -input = sys.stdin.readline -N = int(input()) -hap = 0 -arr = [] -for i in range(N): - X, A = map(int, input().split()) - arr.append([X, A]) - hap += A -arr.sort() # 마을의 위치 순으로 정렬 - -temp = 0 -ans = 0 - -for i in range(N): - temp += arr[i][1] # 마을 주민수 + - if temp >= (hap/2): # 전체 주민의 절반 이상일때 - ans = arr[i][0] # 현재 마을의 위치 저장 - break - -print(ans) diff --git "a/parkjunyoung/5\354\233\2242\354\243\274\354\260\250/1052-\353\254\274\353\263\221.py" "b/parkjunyoung/5\354\233\2242\354\243\274\354\260\250/1052-\353\254\274\353\263\221.py" deleted file mode 100644 index a1f64bd..0000000 --- "a/parkjunyoung/5\354\233\2242\354\243\274\354\260\250/1052-\353\254\274\353\263\221.py" +++ /dev/null @@ -1,8 +0,0 @@ -# 물병 - -N, K = map(int, input().split()) -ans = 0 -while bin(N).count('1') > K: - N += 1 - ans += 1 -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2242\354\243\274\354\260\250/1091-\354\271\264\353\223\234_\354\204\236\354\235\264.py" "b/parkjunyoung/5\354\233\2242\354\243\274\354\260\250/1091-\354\271\264\353\223\234_\354\204\236\354\235\264.py" deleted file mode 100644 index e0a7100..0000000 --- "a/parkjunyoung/5\354\233\2242\354\243\274\354\260\250/1091-\354\271\264\353\223\234_\354\204\236\354\235\264.py" +++ /dev/null @@ -1,33 +0,0 @@ -# 카드 섞이 - -N = int(input()) -P = list(map(int, input().split())) -S = list(map(int, input().split())) -change = [i for i in range(N)] -cnt = 0 -arr = [] -for i in range(N): - arr.append(P[i]) - -while 1: - flag = 1 - for i in range(N): - if change[i] % 3 != arr[i]: - flag = 0 - if flag == 1: - print(cnt) - exit() - - cnt += 1 - temp = [] - flag = 1 - for j in range(N): - if S[change[j]] != j: - flag = 0 - temp.append(S[change[j]]) - change = temp - - if flag == 1: - cnt = -1 - print(cnt) - exit() diff --git "a/parkjunyoung/5\354\233\2242\354\243\274\354\260\250/21923-\352\263\241\354\230\210_\353\271\204\355\226\211.py" "b/parkjunyoung/5\354\233\2242\354\243\274\354\260\250/21923-\352\263\241\354\230\210_\353\271\204\355\226\211.py" deleted file mode 100644 index 61a6782..0000000 --- "a/parkjunyoung/5\354\233\2242\354\243\274\354\260\250/21923-\352\263\241\354\230\210_\353\271\204\355\226\211.py" +++ /dev/null @@ -1,45 +0,0 @@ -# 곡예 비행 - -import sys -input = sys.stdin.readline - -N, M = map(int, input().split()) -score = [] -for i in range(N): - temp = list(map(int, input().split())) - score.append(temp) -dp = [[-10000000001 for _ in range(M)] for _ in range(N)] -dp[N-1][0] = 0 - -# for i in score: -# print(i) -# 상승 -for j in range(M): - for i in range(N-1, -1, -1): - if i != N-1: # 위쪽 - dp[i][j] = dp[i+1][j] - if j != 0: # 오른쪽 - dp[i][j] = max(dp[i][j], dp[i][j-1]) - dp[i][j] += score[i][j] - - -# print('---------------------') -# for i in dp: -# print(i) - -# 하강 -for j in range(M): - for i in range(N): - if i != 0: # 아래쪽 - dp[i][j] = max(dp[i][j], dp[i-1][j]) - if j != 0: # 오른쪽 - dp[i][j] = max(dp[i][j], dp[i][j-1]) - dp[i][j] += score[i][j] - -ans = 0 -# print('---------------------') -# for i in dp: -# print(i) - - -print(dp[N-1][M-1]) diff --git "a/parkjunyoung/5\354\233\2242\354\243\274\354\260\250/27940-\352\260\200\354\247\200_\354\202\260\354\202\254\355\203\234.py" "b/parkjunyoung/5\354\233\2242\354\243\274\354\260\250/27940-\352\260\200\354\247\200_\354\202\260\354\202\254\355\203\234.py" deleted file mode 100644 index a7bec57..0000000 --- "a/parkjunyoung/5\354\233\2242\354\243\274\354\260\250/27940-\352\260\200\354\247\200_\354\202\260\354\202\254\355\203\234.py" +++ /dev/null @@ -1,20 +0,0 @@ -# 가지 산사태 -import sys -input = sys.stdin.readline - -N, M, K = map(int, input().split()) -farm = [0] * N -flag = 0 -ans = [] -for i in range(M): - t, r = map(int, input().split()) - farm[0] += r # 어차피 1층에는 계속 쌓일 수 밖에 없다.... - if farm[0] > K: - ans.append(i+1) - ans.append(1) - break - -if ans: - print(*ans) -else: - print(-1) diff --git "a/parkjunyoung/5\354\233\2243\354\243\274\354\260\250/11508-2+1_\354\204\270\354\235\274.py" "b/parkjunyoung/5\354\233\2243\354\243\274\354\260\250/11508-2+1_\354\204\270\354\235\274.py" deleted file mode 100644 index 4887a08..0000000 --- "a/parkjunyoung/5\354\233\2243\354\243\274\354\260\250/11508-2+1_\354\204\270\354\235\274.py" +++ /dev/null @@ -1,18 +0,0 @@ -# 2+1 세일 - -N = int(input()) -C = [] -for i in range(N): - temp = int(input()) - C.append(temp) -ans = 0 -cnt = 0 -C.sort(reverse=True) -# print(C) -for i in range(N): - cnt += 1 - if cnt == 3: - C[i] = 0 - cnt = 0 - -print(sum(C)) \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2243\354\243\274\354\260\250/2503-\354\210\253\354\236\220_\354\225\274\352\265\254.py" "b/parkjunyoung/5\354\233\2243\354\243\274\354\260\250/2503-\354\210\253\354\236\220_\354\225\274\352\265\254.py" deleted file mode 100644 index 9de8f82..0000000 --- "a/parkjunyoung/5\354\233\2243\354\243\274\354\260\250/2503-\354\210\253\354\236\220_\354\225\274\352\265\254.py" +++ /dev/null @@ -1,27 +0,0 @@ -# 숫자 야구 -from itertools import permutations -N = int(input()) -arr = list(permutations(['1', '2', '3', '4', '5', '6', '7', '8', '9'], 3)) -ans = [1] * len(arr) - -for i in range(N): - num, s, b = map(int, input().split()) - num = list(str(num)) - for j in arr: - strike = 0 - ball = 0 - # print(j, num) - for k in range(3): - for l in range(3): - if j[k] == num[l]: - if k != l: - ball += 1 - if k == l: - strike += 1 - temp = arr.index(j) - if ans[temp] != 0 and s == strike and b == ball: - ans[temp] = 1 - else: - ans[temp] = 0 -# print(ans) -print(sum(ans)) diff --git "a/parkjunyoung/5\354\233\2243\354\243\274\354\260\250/3020-\352\260\234\353\230\245\353\262\214\353\240\210.py" "b/parkjunyoung/5\354\233\2243\354\243\274\354\260\250/3020-\352\260\234\353\230\245\353\262\214\353\240\210.py" deleted file mode 100644 index de206cd..0000000 --- "a/parkjunyoung/5\354\233\2243\354\243\274\354\260\250/3020-\352\260\234\353\230\245\353\262\214\353\240\210.py" +++ /dev/null @@ -1,44 +0,0 @@ -# 개똥벌레 - -N, H = map(int, input().split()) -sizes = [] -for i in range(N): - size = int(input()) - sizes.append(size-1) - -up = [0] * H -down = [0] * H - -for i in range(N): - if i % 2 == 0: - down[sizes[i]] += 1 # 몇층짜리가 몇개가 있는지 확인 - if i % 2 != 0: - up[sizes[i]] += 1 - -print(up) -print(down) - -hap_up = [N//2] # 위쪽 높이에 있는 장애물 수 -hap_down = [N//2] # 아래쪽 - -for i in range(1, H): - temp_up = up[i-1] - hap_up.append(hap_up[i-1]-temp_up) # 이전 높이 만큼 빼고 남은 높이 더하기 - - temp_down = down[i-1] - hap_down.append(hap_down[i-1]-temp_down) - -hap_down.reverse() # 역순 - -print(hap_up) -print(hap_down) - -hap = [] -for i in range(H): - hap.append(hap_up[i] + hap_down[i]) # 각 높이에 있는 장애물 수 -ans = min(hap) -cnt = hap.count(ans) -print(ans, cnt) - - - diff --git "a/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/1342-\355\226\211\354\232\264\354\235\230_\353\254\270\354\236\220\354\227\264.py" "b/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/1342-\355\226\211\354\232\264\354\235\230_\353\254\270\354\236\220\354\227\264.py" deleted file mode 100644 index f9efa03..0000000 --- "a/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/1342-\355\226\211\354\232\264\354\235\230_\353\254\270\354\236\220\354\227\264.py" +++ /dev/null @@ -1,26 +0,0 @@ -# 행운의 문자열 - -S = list(input()) -cnt = len(S) -alphabet = [0 for _ in range(26)] -ans = 0 - -for i in range(cnt): - alphabet[ord(str(S[i])) - 97] += 1 - - -def back(a, b): - global ans - if a == cnt: - ans += 1 - for i in range(26): - if alphabet[i] > 0 and i != b: - alphabet[i] -= 1 - back(a+1, i) - alphabet[i] += 1 - else: - pass - - -back(0, -1) -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/14620_\352\275\203\352\270\270.py" "b/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/14620_\352\275\203\352\270\270.py" deleted file mode 100644 index 8236ced..0000000 --- "a/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/14620_\352\275\203\352\270\270.py" +++ /dev/null @@ -1,56 +0,0 @@ -# 꽃길 - -import sys -sys.setrecursionlimit(10**6) - -N = int(input()) -pan = [] -for i in range(N): - temp = list(map(int, input().split())) - pan.append(temp) -visited = [[0 for _ in range(N)] for _ in range(N)] -dx = [0, 1, 0, -1, 0] -dy = [0, 0, 1, 0, -1] - - -def check(x, y): - for d in range(5): - nx = x + dx[d] - ny = y + dy[d] - if 0 <= nx < N and 0 <= ny < N: - if visited[nx][ny] == 1: - return 0 - return 1 - - -def hap(x, y): - cost = 0 - for d in range(5): - nx = x + dx[d] - ny = y + dy[d] - cost += pan[nx][ny] - return cost - - -def dfs(cnt, cost_hap): - global min_ans - if cnt == 3: - min_ans = min(min_ans, cost_hap) - return - for x in range(1, N-1): - for y in range(1, N-1): - if check(x, y) == 1: - for d in range(5): - nx = x + dx[d] - ny = y + dy[d] - visited[nx][ny] = 1 - dfs(cnt+1, cost_hap + hap(x, y)) - for d in range(5): - nx = x + dx[d] - ny = y + dy[d] - visited[nx][ny] = 0 - -min_ans = 3001 -dfs(0, 0) - -print(min_ans) \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/1577-\353\217\204\353\241\234\354\235\230_\352\260\234\354\210\230.py" "b/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/1577-\353\217\204\353\241\234\354\235\230_\352\260\234\354\210\230.py" deleted file mode 100644 index 3e564d0..0000000 --- "a/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/1577-\353\217\204\353\241\234\354\235\230_\352\260\234\354\210\230.py" +++ /dev/null @@ -1,37 +0,0 @@ -# 도로의 개수 - -N, M = map(int, input().split()) -k = int(input()) - -# visited = [[0 for _ in range(M + 1)] for _ in range(N + 1)] -dp = [[0 for _ in range(M + 1)] for _ in range(N + 1)] -dp[0][0] = 1 - -stop = [] -for _ in range(k): - a, b, c, d = map(int, input().split()) - stop.append(((a, b), (c, d))) - - -# for i in stop: -# print(i) - -dp[0][0] = 1 - -move = [(1, 0), (0, 1)] -for x in range(N + 1): - for y in range(M + 1): - for i in range(2): - nx = x + move[i][0] - ny = y + move[i][1] - if nx <= N and ny <= M: - if ((x, y), (nx, ny)) in stop or ((nx, ny), (x, y)) in stop: - continue - else: - dp[nx][ny] += dp[x][y] - # print(x,y) - -for i in dp: - print(i) - -print(dp[N][M]) \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/\352\270\260\353\221\245\352\263\274_\353\263\264_\354\204\244\354\271\230.py" "b/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/\352\270\260\353\221\245\352\263\274_\353\263\264_\354\204\244\354\271\230.py" deleted file mode 100644 index 2cbf492..0000000 --- "a/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/\352\270\260\353\221\245\352\263\274_\353\263\264_\354\204\244\354\271\230.py" +++ /dev/null @@ -1,49 +0,0 @@ -def check(x, y, a, ans): - # 기둥인가 - if a == 0: - # 바닥위에 있거나 - if y == 0: - return 1 - # 보의 한쪽 끝 부분 위에 있거나 - if ((x - 1, y, 1) in ans) or ((x, y, 1) in ans): - return 1 - # 다른 기둥위에 있거나 - if (x, y - 1, 0) in ans: - return 1 - return 0 - - # 보인가 - if a == 1: - # 한쪽 끝 부분이 기둥위에 있거나 - if ((x, y - 1, 0) in ans) or ((x + 1, y - 1, 0) in ans): - return 1 - # 양쪽 끝부분이 다른보와 동시에 연될되어있거나 - if ((x - 1, y, 1) in ans) and ((x + 1, y, 1) in ans): - return 1 - return 0 - - -def solution(n, build_frame): - ans = set() - for i in build_frame: - # x,y 좌표, a 기둥 or 보, b 설치 or 삭제 - x, y, a, b = i[0], i[1], i[2], i[3] - # 설치 - if b == 1: - if check(x, y, a, ans) == 1: - ans.add((x, y, a)) - # 삭제 - if b == 0: - # 삭제 - ans.remove((x, y, a)) - # 조건이 충족하는지 확인 - for x1, y1, a1 in ans: - if check(x1, y1, a1, ans) == 1: - continue - else: - # 아니면 다시 추가 - ans.add((x, y, a)) - break - ans = list(ans) - ans.sort() - return ans \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/\354\213\240\352\267\234_\354\225\204\354\235\264\353\224\224_\354\266\224\354\262\234.py" "b/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/\354\213\240\352\267\234_\354\225\204\354\235\264\353\224\224_\354\266\224\354\262\234.py" deleted file mode 100644 index 333176a..0000000 --- "a/parkjunyoung/5\354\233\2244\354\243\274\354\260\250/\354\213\240\352\267\234_\354\225\204\354\235\264\353\224\224_\354\266\224\354\262\234.py" +++ /dev/null @@ -1,43 +0,0 @@ -# 신규 아이디 추천 - -def solution(new_id): - answer = '' - # 1 - new_id = new_id.lower() - - # 2 - check = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', - 'c', 'v', 'b', 'n', 'm', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '_', '.'] - step2 = [] - for i in new_id: - if i in check: - step2.append(i) - new_id = ''.join(step2) - - # 3 - while '..' in new_id: - new_id = new_id.replace('..', '.') - - # 4 - if new_id[0] == '.': - if len(new_id) > 1: - new_id = new_id[1:] - if new_id[-1] == '.': - new_id = new_id[:-1] - - # 5 - if new_id == '': - new_id = 'a' - - # 6 - if len(new_id) >= 16: - new_id = new_id[:15] - if new_id[-1] == '.': - new_id = new_id[:-1] - - # 7 - if len(new_id) <= 2: - new_id = new_id + new_id[-1] * (3 - len(new_id)) - - answer = new_id - return answer \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2245\354\243\274\354\260\250/13164-\355\226\211\353\263\265_\354\234\240\354\271\230\354\233\220.py" "b/parkjunyoung/5\354\233\2245\354\243\274\354\260\250/13164-\355\226\211\353\263\265_\354\234\240\354\271\230\354\233\220.py" deleted file mode 100644 index 9eee217..0000000 --- "a/parkjunyoung/5\354\233\2245\354\243\274\354\260\250/13164-\355\226\211\353\263\265_\354\234\240\354\271\230\354\233\220.py" +++ /dev/null @@ -1,17 +0,0 @@ -# 행복 유치원 - -N, K = map(int, input().split()) -arr = list(map(int, input().split())) - -cha = [] -for i in range(1, N): - cha.append(arr[i]-arr[i-1]) - -cha.sort() -# print(cha) - -ans = 0 -for i in range(N-K): - ans += cha[i] - -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2245\354\243\274\354\260\250/16933-\353\262\275_\353\266\200\354\210\230\352\263\240_\354\235\264\353\217\231\355\225\230\352\270\260_3.py" "b/parkjunyoung/5\354\233\2245\354\243\274\354\260\250/16933-\353\262\275_\353\266\200\354\210\230\352\263\240_\354\235\264\353\217\231\355\225\230\352\270\260_3.py" deleted file mode 100644 index aed4e2c..0000000 --- "a/parkjunyoung/5\354\233\2245\354\243\274\354\260\250/16933-\353\262\275_\353\266\200\354\210\230\352\263\240_\354\235\264\353\217\231\355\225\230\352\270\260_3.py" +++ /dev/null @@ -1,50 +0,0 @@ -# 벽 부수고 이동하기 3 - -import sys -input = sys.stdin.readline -from collections import deque - -dx = [1, -1, 0, 0] -dy = [0, 0, -1, 1] -queue = deque() - - -def bfs(): - queue.append((0, 0, 0, 1)) # 0,0 좌표, 0 뿌순수 1 날짜 - flag = True # 낮, false = 밤 - - while queue: - for _ in range(len(queue)): # 벽에 막혔을때 q의 길이 만큼하지 않으면 꼬인다 - x, y, k, ans = queue.popleft() - if x == N-1 and y == M-1: - return ans - for i in range(4): - nx = x + dx[i] - ny = y + dy[i] - if 0 <= nx < N and 0 <= ny < M: - # 벽이 아닐때 - if wall[nx][ny] == '0' and visited[nx][ny][k] == 0: - visited[nx][ny][k] = 1 - queue.append((nx, ny, k, ans+1)) - # 벽일때 - if wall[nx][ny] == '1' and K > k and visited[nx][ny][k+1] == 0: - # 조건이 앞에 있나 뒤에 있나에 따라 range 에러가 발생... - if flag == True: - visited[nx][ny][k+1] = 1 - queue.append((nx, ny, k+1, ans+1)) - elif flag == False: - queue.append((x, y, k, ans+1)) - flag = not flag - return -1 - - -N, M, K = map(int, input().split()) -wall = [list(sys.stdin.readline().rstrip()) for _ in range(N)] -visited = [[[0] * (K + 1) for _ in range(M)] for _ in range(N)] -visited[0][0][0] = 1 -print(bfs()) -# for i in wall: -# print(i) -# for i in visited: -# print(i) - diff --git "a/parkjunyoung/5\354\233\2245\354\243\274\354\260\250/2023-\354\213\240\352\270\260\355\225\234_\354\206\214\354\210\230.py" "b/parkjunyoung/5\354\233\2245\354\243\274\354\260\250/2023-\354\213\240\352\270\260\355\225\234_\354\206\214\354\210\230.py" deleted file mode 100644 index b740ee0..0000000 --- "a/parkjunyoung/5\354\233\2245\354\243\274\354\260\250/2023-\354\213\240\352\270\260\355\225\234_\354\206\214\354\210\230.py" +++ /dev/null @@ -1,29 +0,0 @@ -# 신기한 소수 - -import math - -def is_prime_num(n): - for i in range(2, int(math.sqrt(n))+1): # n의 제곱근을 정수화 시켜준 후 + 1 - if n % i == 0: - return False - return True - - -N = int(input()) - - -def dfs(num): - if len(list(str(num))) == N: - print(num) - else: - for i in range(1, 10): - if i % 2 == 0: - continue - if is_prime_num(num*10 + i): - dfs(num*10 + i) - - -dfs(2) -dfs(3) -dfs(5) -dfs(7) \ No newline at end of file diff --git "a/parkjunyoung/5\354\233\2245\354\243\274\354\260\250/2212-\354\204\274\354\204\234.py" "b/parkjunyoung/5\354\233\2245\354\243\274\354\260\250/2212-\354\204\274\354\204\234.py" deleted file mode 100644 index 05faf42..0000000 --- "a/parkjunyoung/5\354\233\2245\354\243\274\354\260\250/2212-\354\204\274\354\204\234.py" +++ /dev/null @@ -1,18 +0,0 @@ -# 센서 - -N = int(input()) -K = int(input()) -arr = list(map(int, input().split())) -arr.sort() - -cha = [] -for i in range(1, N): - cha.append(arr[i]-arr[i-1]) - -cha.sort() - -ans = 0 -for i in range(N-K): - ans += cha[i] - -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2242\354\243\274\354\260\250/1149-RGB\352\261\260\353\246\254.py" "b/parkjunyoung/6\354\233\2242\354\243\274\354\260\250/1149-RGB\352\261\260\353\246\254.py" deleted file mode 100644 index f748f38..0000000 --- "a/parkjunyoung/6\354\233\2242\354\243\274\354\260\250/1149-RGB\352\261\260\353\246\254.py" +++ /dev/null @@ -1,13 +0,0 @@ -# RGB거리 - -N = int(input()) -dp = [] -for i in range(N): - dp.append(list(map(int, input().split()))) - -for i in range(1, N): - dp[i][0] = min(dp[i-1][1], dp[i-1][2]) + dp[i][0] - dp[i][1] = min(dp[i-1][0], dp[i-1][2]) + dp[i][1] - dp[i][2] = min(dp[i-1][0], dp[i-1][1]) + dp[i][2] - -print(min(dp[N-1][0], dp[N-1][1], dp[N-1][2])) \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2242\354\243\274\354\260\250/12869-\353\256\244\355\203\210\353\246\254\354\212\244\355\201\254.py" "b/parkjunyoung/6\354\233\2242\354\243\274\354\260\250/12869-\353\256\244\355\203\210\353\246\254\354\212\244\355\201\254.py" deleted file mode 100644 index 3ee2edc..0000000 --- "a/parkjunyoung/6\354\233\2242\354\243\274\354\260\250/12869-\353\256\244\355\203\210\353\246\254\354\212\244\355\201\254.py" +++ /dev/null @@ -1,35 +0,0 @@ -# 뮤탈리스크 - -from itertools import permutations - -N = int(input()) -scv = [0, 0, 0] -hp = list(map(int, input().split())) -for i in range(N): - scv[i] = hp[i] - -dp = [[[0 for _ in range(61)] for _ in range(61)] for _ in range(61)] -dp[scv[0]][scv[1]][scv[2]] = 1 -mutal = [9, 3, 1] -mutals = list(permutations([9, 3, 1])) -# print(mutals) -# print(dp) -for i in range(60, -1, -1): - for j in range(60, -1, -1): - for k in range(60, -1, -1): - if dp[i][j][k] > 0: - for a1, a2, a3 in mutals: - I = i - a1 - J = j - a2 - K = k - a3 - if i-a1 < 0: - I = 0 - if j-a2 < 0: - J = 0 - if k-a3 < 0: - K = 0 - if dp[I][J][K] == 0 or dp[I][J][K] > dp[i][j][k]+1: - dp[I][J][K] = dp[i][j][k]+1 - -print(dp[0][0][0]-1) - diff --git "a/parkjunyoung/6\354\233\2242\354\243\274\354\260\250/2157-\354\227\254\355\226\211.py" "b/parkjunyoung/6\354\233\2242\354\243\274\354\260\250/2157-\354\227\254\355\226\211.py" deleted file mode 100644 index 456f4d5..0000000 --- "a/parkjunyoung/6\354\233\2242\354\243\274\354\260\250/2157-\354\227\254\355\226\211.py" +++ /dev/null @@ -1,30 +0,0 @@ -# 여행 - -N, M, K = map(int, input().split()) -food = [[0 for _ in range(N+1)] for _ in range(N+1)] -for i in range(K): - a, b, c = map(int, input().split()) - if food[a][b] != 0: - food[a][b] = max(food[a][b], c) - else: - food[a][b] = c - -dp = [[-1 for _ in range(301)] for _ in range(301)] - - -def func(i, cnt): - if i != 1 and cnt == 1: - return -9999999 - if i == 1: - return 0 - if dp[i][cnt] != -1: - return dp[i][cnt] - dp[i][cnt] = -9999999 - for j in range(1, i): - if food[j][i]: - dp[i][cnt] = max(dp[i][cnt], func(j, cnt - 1) + food[j][i]) - - return dp[i][cnt] - - -print(func(N, M)) diff --git "a/parkjunyoung/6\354\233\2242\354\243\274\354\260\250/23757-\354\225\204\354\235\264\353\223\244\352\263\274_\354\204\240\353\254\274_\354\203\201\354\236\220.py" "b/parkjunyoung/6\354\233\2242\354\243\274\354\260\250/23757-\354\225\204\354\235\264\353\223\244\352\263\274_\354\204\240\353\254\274_\354\203\201\354\236\220.py" deleted file mode 100644 index 3065bac..0000000 --- "a/parkjunyoung/6\354\233\2242\354\243\274\354\260\250/23757-\354\225\204\354\235\264\353\223\244\352\263\274_\354\204\240\353\254\274_\354\203\201\354\236\220.py" +++ /dev/null @@ -1,22 +0,0 @@ -# 아이들과 선물 상자 -import heapq - -N, M = map(int, input().split()) -box = list(map(int, input().split())) -child = list(map(int, input().split())) -q = [] -for i in box: - heapq.heappush(q, -i) - - - -# print(q) -flag = 1 -for i in child: - temp = heapq.heappop(q) - if i > -temp: - flag = 0 - break - heapq.heappush(q, i + temp) - -print(flag) \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2243\354\243\274\354\260\250/15686_\354\271\230\355\202\250_\353\260\260\353\213\254.py" "b/parkjunyoung/6\354\233\2243\354\243\274\354\260\250/15686_\354\271\230\355\202\250_\353\260\260\353\213\254.py" deleted file mode 100644 index a60355d..0000000 --- "a/parkjunyoung/6\354\233\2243\354\243\274\354\260\250/15686_\354\271\230\355\202\250_\353\260\260\353\213\254.py" +++ /dev/null @@ -1,24 +0,0 @@ -# 치킨 배달 - -from itertools import combinations - -N, M = map(int, input().split()) # 도시, 치킨집집의 최대 개수 -city = [list(map(int, input().split())) for _ in range(N)] # 도시 입력 -house = [] # 집 -chicken = [] # 치킨집 -for i in range(N): # 전체탐색 - for j in range(N): - if city[i][j] == 1: # 집에 추가 - house.append((i, j)) - elif city[i][j] == 2: # 치킨집에 추가 - chicken.append((i, j)) - -arr = list(combinations(chicken, M)) # 조합 다 만들기 -dis = [0] * len(arr) # 거리의 합 -for i in house: # 집들중에서 - for j in range(len(arr)): # 조합들의 - cnt = 999999 # 치킨집과 집사이의 거리 - for k in arr[j]: # 각각의 값의 - cnt = min(cnt, abs(i[0]-k[0])+abs(i[1]-k[1])) # 거리의 차를 구해서 최소값을 구해서 - dis[j] += cnt # 거리의 합에 추가한다 -print(min(dis)) # 최소 거리값 \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2243\354\243\274\354\260\250/16929-Two_Dots.py" "b/parkjunyoung/6\354\233\2243\354\243\274\354\260\250/16929-Two_Dots.py" deleted file mode 100644 index 5c09966..0000000 --- "a/parkjunyoung/6\354\233\2243\354\243\274\354\260\250/16929-Two_Dots.py" +++ /dev/null @@ -1,54 +0,0 @@ -# Two Dots -dx = [1, -1, 0, 0] -dy = [0, 0, -1, 1] - -N, M = map(int, input().split()) -pan = [] -for i in range(N): - temp = list(input()) - pan.append(temp) - -flag = 0 -# for i in pan: -# print(i) - - -def dfs(x,y, start, color, cnt): - global flag - # 시작 위치랑 같고 4번이상움직였으면 사이클이 되는거 - if x == start[0] and y == start[1] and cnt >= 4: - flag = 1 - return flag - - if flag: - return - - visited[x][y] = 1 - for d in range(4): - nx = x + dx[d] - ny = y + dy[d] - if 0 <= nx < N and 0 <= ny < M: - # 방문하지 않았고 같은 색이면 계속 이동 - if visited[nx][ny] == 0 and color == pan[nx][ny]: - dfs(nx, ny, start, color, cnt+1) - # 방문했으면 - elif visited[nx][ny] == 1: - # 시작위치고 4번이상이면 - if nx == start[0] and ny == start[1] and cnt >= 4: - flag = 1 - return - return - - -for i in range(N): - for j in range(M): - visited = [[0 for _ in range(M)] for _ in range(N)] - visited[i][j] = 1 - start = [i, j] - color = pan[i][j] - dfs(i, j, start, color, 1) - -if flag: - print("Yes") -else: - print("No") \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2243\354\243\274\354\260\250/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.py" "b/parkjunyoung/6\354\233\2243\354\243\274\354\260\250/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.py" deleted file mode 100644 index 06f2777..0000000 --- "a/parkjunyoung/6\354\233\2243\354\243\274\354\260\250/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.py" +++ /dev/null @@ -1,40 +0,0 @@ -# 거리두기 확인하기 - -def check(place): - dx = [1, 0, -1, 0] - dy = [0, 1, 0, -1] - for i in range(5): - for j in range(5): - # 만약 사람이면 - if place[i][j] == "P": - for d in range(4): - nx = i + dx[d] - ny = j + dy[d] - if 0 <= nx < 5 and 0 <= ny < 5: - if place[nx][ny] == "P": - return 0 - # 만약 빈테이블이면 근처에 2명이 있으면 실패 - elif place[i][j] == "O": - cnt = 0 - for d in range(4): - nx = i + dx[d] - ny = j + dy[d] - if 0 <= nx < 5 and 0 <= ny < 5: - if place[nx][ny] == "P": - cnt += 1 - if cnt >= 2: - return 0 - - return 1 - - -def solution(places): - answer = [] - for place in places: - answer.append(check(place)) - - return answer - - -places = [["POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"], ["POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"], ["PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"], ["OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"], ["PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"]] -print(solution(places)) diff --git "a/parkjunyoung/6\354\233\2243\354\243\274\354\260\250/\354\226\221\352\266\201\353\214\200\355\232\214.py" "b/parkjunyoung/6\354\233\2243\354\243\274\354\260\250/\354\226\221\352\266\201\353\214\200\355\232\214.py" deleted file mode 100644 index 4b2503a..0000000 --- "a/parkjunyoung/6\354\233\2243\354\243\274\354\260\250/\354\226\221\352\266\201\353\214\200\355\232\214.py" +++ /dev/null @@ -1,54 +0,0 @@ -# 양궁 대회 - - -def solution(n, info): - def func(n, lion, idx): - nonlocal cha, answer # nonlocal 지역변수 전역변수에 따라 다르다는 걸 처음봄 - - # 화살을 다 쐈을때 - if idx > 10: - if n > 0: - lion[10] += n # 0점에 다 추가 - # 점수 계산 - score_apeach = 0 - score_lion = 0 - for idx in range(0, 11): - if lion[idx] > info[idx]: - score_lion += 10 - idx - elif info[idx]: - score_apeach += 10 - idx - - # 차이의 최대값을 저장하고 화살을 저장 - if cha < score_lion - score_apeach: - cha = score_lion - score_apeach - answer = lion[:] - - - # 차이가 같으면 가장 낮은 점수를 더 많이 맞힌 경우를 저장 - elif cha == score_lion - score_apeach: - # 0점부터 탐색하면서 더 낮은게 있으면 갱신해주기 - for i in range(10, -1, -1): - if answer[i] < lion[i]: - answer = lion[:] - break - elif answer[i] > lion[i]: - break - - # 위에서 더해줬던 부분을 빼는거 같은데 이유를 모르겠음 - if n > 0: - lion[10] -= n - return - - # 화살을 쏘는데 남은 - if info[idx] + 1 <= n: # 남은 화살수가 어피치의 점수 +1 보다 클때 - lion[idx] = info[idx] + 1 # 라이언이 점수를 어디 위해 채워주고 - func(n - info[idx] - 1, lion, idx + 1) # 뺀만큼 다시 쏜다 - lion[idx] = 0 # 돌고 나면 초기화 - func(n, lion, idx + 1) # 이건 어피치가 이기는 부분 - - lion = [0] * 11 - cha = 1 - answer = [] - func(n, lion, 0) - - return answer if answer else [-1] \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2244\354\243\274\354\260\250/2229-\354\241\260_\354\247\234\352\270\260.py" "b/parkjunyoung/6\354\233\2244\354\243\274\354\260\250/2229-\354\241\260_\354\247\234\352\270\260.py" deleted file mode 100644 index 58b557c..0000000 --- "a/parkjunyoung/6\354\233\2244\354\243\274\354\260\250/2229-\354\241\260_\354\247\234\352\270\260.py" +++ /dev/null @@ -1,22 +0,0 @@ -# 조 짜기 - -N = int(input()) - -arr = list(map(int, input().split())) -dp = [0] * 1001 -# 나이순으로 정렬되어있고 순서를 섞지 않는다 -# 앞에서 부터 조를 잘라가면서 탐색 - -dp[1] = abs(arr[1] - arr[0]) - -for i in range(1, N): - for j in range(1, i+1): - # print(i,j) - temp_max = max(arr[i-j+1:i+1]) - temp_min = min(arr[i-j+1:i+1]) - dp[i] = max(dp[i], dp[i-j] + temp_max - temp_min) - - - -# print(dp) -print(dp[N-1]) \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2244\354\243\274\354\260\250/2623-\354\235\214\354\225\205\355\224\204\353\241\234\352\267\270\353\236\250.py" "b/parkjunyoung/6\354\233\2244\354\243\274\354\260\250/2623-\354\235\214\354\225\205\355\224\204\353\241\234\352\267\270\353\236\250.py" deleted file mode 100644 index 0aadd9b..0000000 --- "a/parkjunyoung/6\354\233\2244\354\243\274\354\260\250/2623-\354\235\214\354\225\205\355\224\204\353\241\234\352\267\270\353\236\250.py" +++ /dev/null @@ -1,32 +0,0 @@ -# 음악프로그램 - -N, M = map(int, input().split()) -check = [[] for _ in range(N+1)] -visited = [0 for _ in range(N+1)] -cnt = [0 for _ in range(N+1)] - -for _ in range(M): - temp = list(map(int, input().split())) - a = temp.pop(0) - for i in range(a-1): - check[temp[i]].append(temp[i+1]) - cnt[temp[i+1]] += 1 - -# print(check) -# print(cnt) -ans = [] -while len(ans) < N: - flag = 0 - for i in range(1, N+1): - if not cnt[i] and visited[i] == 0: - flag = 1 - ans.append(i) - visited[i] = 1 - for j in check[i]: - cnt[j] -= 1 - if flag != 1: - ans = [0] - break - -for i in ans: - print(i) \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2244\354\243\274\354\260\250/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.py" "b/parkjunyoung/6\354\233\2244\354\243\274\354\260\250/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.py" deleted file mode 100644 index 2039495..0000000 --- "a/parkjunyoung/6\354\233\2244\354\243\274\354\260\250/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.py" +++ /dev/null @@ -1,40 +0,0 @@ -import math - - -def price(t, base_time, base_price, over_time, over_price): - if t <= base_time: - return base_price - over_times = math.ceil((t - base_time) / over_time) - return base_price + over_times * over_price - - -def solution(fees, records): - in_out = {} - parking_times = {} - for record in records: - t, car, inout = record.split() - a, b = t.split(':') - time = 60 * int(a) + int(b) - if inout == 'IN': - in_out[car] = time - if car in parking_times: - pass - else: - parking_times[car] = 0 - else: - parking_times[car] += time - in_out[car] - in_out.pop(car) - for car in in_out: - parking_times[car] += (60 * 23 + 59 - in_out[car]) - - temp = {} - for car in parking_times: - temp[car] = price(parking_times[car], fees[0], fees[1], fees[2], fees[3]) - answer = [] - temp = list(sorted(temp.items())) - for car, prices in temp: - answer.append(prices) - return answer - - -print(solution([180, 5000, 10, 600],["05:34 5961 IN", "06:00 0000 IN", "06:34 0000 OUT", "07:59 5961 OUT", "07:59 0148 IN", "18:59 0000 IN", "19:09 0148 OUT", "22:59 5961 IN", "23:00 5961 OUT"])) \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/1167-\355\212\270\353\246\254\354\235\230_\354\247\200\353\246\204.py" "b/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/1167-\355\212\270\353\246\254\354\235\230_\354\247\200\353\246\204.py" deleted file mode 100644 index a5441db..0000000 --- "a/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/1167-\355\212\270\353\246\254\354\235\230_\354\247\200\353\246\204.py" +++ /dev/null @@ -1,42 +0,0 @@ -# 트리의 지름 - -V = int(input()) -# 트리 -tree = [[] for _ in range(V+1)] -for i in range(V): - temp = list(map(int, input().split())) - # 2칸씩 점프하면서 노드와 거리를 추가 - for j in range(1, len(temp), 2): - if temp[j] == -1: - break - tree[temp[0]].append((temp[j], temp[j+1])) - -# 최대 거리를 저장 -max_1 = [-1 for _ in range(V + 1)] -# 1번 노드 부터 시작하면서 방문처리하고 거리를 저장 -max_1[1] = 0 - - -def dfs(start, tree, max_1): - for node, dis in tree[start]: - # 방문하지 않았다면 - if max_1[node] == -1: - # 거리를 추가 - max_1[node] = max_1[start] + dis - dfs(node, tree, max_1) - -# 1번 노드부터 탐색 -dfs(1, tree, max_1) - -# 최대 거리와 노드 뽑기 -temp = max(max_1) -ans = [temp, max_1.index(temp)] - -# 위에서 찾은 노드에서 최대 거리를 다시 탐색 -max_2 = [-1 for _ in range(V+1)] -# 방문 처리하고 위의 노드부터 시작 -max_2[ans[1]] = 0 -dfs(ans[1], tree, max_2) - -# 최대 지름 -print(max(max_2)) \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/2143-\353\221\220_\353\260\260\354\227\264\354\235\230_\355\225\251.py" "b/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/2143-\353\221\220_\353\260\260\354\227\264\354\235\230_\355\225\251.py" deleted file mode 100644 index c903f8a..0000000 --- "a/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/2143-\353\221\220_\353\260\260\354\227\264\354\235\230_\355\225\251.py" +++ /dev/null @@ -1,41 +0,0 @@ -# 두 배열의 합 -from collections import Counter - -T = int(input()) -n = int(input()) -A = list(map(int, input().split())) -m = int(input()) -B = list(map(int, input().split())) - -list_A = A # 부분집합 넣을거 -list_B = B # 부분집합 넣을거 - -for i in range(n): # 완탐하면서 각원소를 더하면서 추가 - hap = A[i] - for j in range(i+1, n): - hap += A[j] - list_A.append(hap) - -for i in range(m): - hap = B[i] - for j in range(i+1, m): - hap += B[j] - list_B.append(hap) - -# 완탐으로 탐색하면 시간 초과 난다 -# check = 0 -# for i in list_A: -# for j in list_B: -# if i+j == T: -# check += 1 -# print(check) -# 범위가 너무 커서 완탐은 시간초과 - -ans = 0 -# A의 부 배열을 Counter 를 통해 어떤 숫자가 몇개있는지 탐색 -num = Counter(list_A) - -# B의 부 배열의 합을 돌면서 T - B부배열의 합 = A부배열의 합 을 이용해서 ans 값을 추가 -for i in range(len(list_B)): - ans += num[T-list_B[i]] -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/2671-\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.py" "b/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/2671-\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.py" deleted file mode 100644 index 218d5b7..0000000 --- "a/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/2671-\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.py" +++ /dev/null @@ -1,15 +0,0 @@ -# 잠수함식별 - -import re -# 정규식으로 풀면 아주 간단한 문제였음 -sign = input() -# 규칙 컴파일, 패턴 생성 -# + 는 100~1 | 는 or 느낌 -pattern = re.compile('(100+1+|01)+') -# fullmatch로 패턴 일치 확인 -ans = pattern.fullmatch(sign) - -if ans: - print("SUBMARINE") -else: - print("NOISE") \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/2800-\352\264\204\355\230\270_\354\240\234\352\261\260.py" "b/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/2800-\352\264\204\355\230\270_\354\240\234\352\261\260.py" deleted file mode 100644 index 1a5fd03..0000000 --- "a/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/2800-\352\264\204\355\230\270_\354\240\234\352\261\260.py" +++ /dev/null @@ -1,43 +0,0 @@ -# 괄호 제거 -from itertools import combinations - -arr = input() -temp = list(arr) - -# 괄호의 쌍을 넣을 stack -stack = [] -# 모든 괄호 쌍의 idx -all_lr = [] -for i in range(len(temp)): - if temp[i] == '(': - stack.append(i) - elif temp[i] == ')': - l_idx = stack.pop() - all_lr.append((l_idx, i)) -# 부분집합으로 모든 괄호의 경우의 수를 담는다 -case = [] -for i in range(len(all_lr)+1): - case = case + list(combinations(all_lr, i)) -ans = [] -# 첫번째는 공집합이라 패스 -for i in range(1, len(case)): - now = temp.copy() - # 그냥 pop을 해버리면 index 에러가 발생해서 idx를 따로 뽑는다 - sort_case = [] - for (a, b) in case[i]: - sort_case.append(a) - sort_case.append(b) - # 큰 idx 부터 pop 해야하므로 정렬한번 해주고 - sort_case.sort(reverse=True) - for j in sort_case: - now.pop(j) - # 수식을 완성하고 추가 - now = ''.join(now) - # 여기서 중복이 발생할 수 있음 - if now not in ans: - ans.append(now) - -# 정렬해서 출력 -ans.sort() -for i in ans: - print(i) \ No newline at end of file diff --git "a/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/\353\254\264\354\235\270\353\217\204_\354\227\254\355\226\211.py" "b/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/\353\254\264\354\235\270\353\217\204_\354\227\254\355\226\211.py" deleted file mode 100644 index c392798..0000000 --- "a/parkjunyoung/6\354\233\2245\354\243\274\354\260\250/\353\254\264\354\235\270\353\217\204_\354\227\254\355\226\211.py" +++ /dev/null @@ -1,57 +0,0 @@ -# 무인도 여행 - -from collections import deque - - -def solution(maps): - answer = [] - N = len(maps) - M = len(maps[0]) - dx = [1, 0, -1, 0] - dy = [0, 1, 0, -1] - visited = [[0 for _ in range(M)] for _ in range(N)] - - - # 방문 처리하면서 bfs - def bfs(i, j): - q = deque() - q.append((i, j)) - visited[i][j] = 1 - # 식량의 총합 - hap = int(maps[i][j]) - while q: - x, y = q.popleft() - for d in range(4): - nx = x + dx[d] - ny = y + dy[d] - # 범위안에 있고 - if 0 <= nx < N and 0 <= ny < M: - # 바다가 아니거나 방문하지 않았으면 - if maps[nx][ny] != 'X' and visited[nx][ny] == 0: - visited[nx][ny] = 1 - # 식량의 총합 추가 - hap += int(maps[nx][ny]) - q.append((nx, ny)) - return hap - - - for i in range(N): - for j in range(M): - # 바다가 아니거나 방문하지 않았으면 - if maps[i][j] != 'X' and visited[i][j] == 0: - # 탐색 - temp = bfs(i, j) - answer.append(temp) - - # 오름차순으로 정렬 - answer.sort() - - # 답이 없다면 -1 출력 - if answer: - return answer - else: - return [-1] - - - -print(solution(["X591X", "X1X5X", "X231X", "1XXX1"])) \ No newline at end of file diff --git "a/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/17070-\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.py" "b/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/17070-\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.py" deleted file mode 100644 index a06e188..0000000 --- "a/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/17070-\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.py" +++ /dev/null @@ -1,35 +0,0 @@ -# 파이프 옮기기1 - -N = int(input()) -home = [] -for _ in range(N): - temp = list(map(int, input().split())) - home.append(temp) - -dp = [[[0] * N for _ in range(N)] for _ in range(3)] -# 0 가로 1 세로 2 대각 -dp[0][0][1] = 1 - - -# 1번행 채우기? -for i in range(2, N): - if home[0][i] == 0: - dp[0][0][i] = dp[0][0][i-1] - - -for i in range(1, N): - for j in range(1, N): - if home[i][j] == 0: - # 가로 = 가로랑 대각 - dp[0][i][j] = dp[0][i][j-1] + dp[2][i][j-1] - # 세로 = 세로랑 대각 - dp[1][i][j] = dp[1][i-1][j] + dp[2][i-1][j] - - if home[i][j] == 0 and home[i-1][j] == 0 and home[i][j-1] == 0: - # 대각 = 가로 세로 대각 - dp[2][i][j] = dp[0][i-1][j-1] + dp[1][i-1][j-1] + dp[2][i-1][j-1] -# print(dp) - -ans = dp[0][N-1][N-1] + dp[1][N-1][N-1] + dp[2][N-1][N-1] - -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/2146-\353\213\244\353\246\254_\353\247\214\353\223\244\352\270\260.py" "b/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/2146-\353\213\244\353\246\254_\353\247\214\353\223\244\352\270\260.py" deleted file mode 100644 index 71aab30..0000000 --- "a/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/2146-\353\213\244\353\246\254_\353\247\214\353\223\244\352\270\260.py" +++ /dev/null @@ -1,76 +0,0 @@ -# 다리 만들기 - -from collections import deque - -dx = [1, 0, -1, 0] -dy = [0, 1, 0, -1] - -N = int(input()) -pan = [] -for i in range(N): - temp = list(map(int, input().split())) - pan.append(temp) - -# 섬을 구분하기 위해서 cnt 부여 -def island(x, y, cnt): - q = deque() - q.append((x, y)) - check[x][y] = cnt - while q: - x, y = q.popleft() - for d in range(4): - nx = x + dx[d] - ny = y + dy[d] - if 0 <= nx < N and 0 <= ny < N: - if check[nx][ny] == 0: - if pan[nx][ny] != 0: - check[nx][ny] = cnt - q.append((nx, ny)) - - -check = [[0 for _ in range(N)] for _ in range(N)] -cnt = 1 -for i in range(N): - for j in range(N): - if pan[i][j] != 0 and check[i][j] == 0: - island(i, j, cnt) - cnt += 1 - -# 각 섬에서 출발해서 다른섬까지의 거리를 구한다 -def bfs(q, my_num): - while q: - x, y = q.popleft() - for d in range(4): - nx = x + dx[d] - ny = y + dy[d] - # 범위 안에 있고 - if 0 <= nx < N and 0 <= ny < N: - # 다른 섬일때 - if pan[nx][ny] == 1 and check[nx][ny] != my_num: - return visitied[x][y] - # 바다면서 방문하지 않았을때 - if check[nx][ny] == 0 and visitied[nx][ny] == -1: - visitied[nx][ny] = visitied[x][y] + 1 - q.append((nx, ny)) - -# 최솟값 변수 -min_ans = 10001 - -# 섬을 돌면서 -for c in range(1, cnt): - q = deque() - visitied = [[-1 for _ in range(N)] for _ in range(N)] - - # 여기가 제일 문제였는데 모든섬의 값을 q에 먼저 넣어서 섬의 모든 점에서 부터 시작하는 걸로 변경하였다. - # 그래야 최소값을 구할때 오류가 안생기는듯 - for i in range(N): - for j in range(N): - if check[i][j] == c: - q.append((i, j)) - visitied[i][j] = 0 - - # 거리를 구하고 최솟값이랑 비교 - ans = bfs(q, c) - min_ans = min(ans, min_ans) - -print(min_ans) \ No newline at end of file diff --git "a/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/21758-\352\277\200_\353\224\260\352\270\260.py" "b/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/21758-\352\277\200_\353\224\260\352\270\260.py" deleted file mode 100644 index 6cc2345..0000000 --- "a/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/21758-\352\277\200_\353\224\260\352\270\260.py" +++ /dev/null @@ -1,28 +0,0 @@ -# 꿀 따기 - -N = int(input()) -honey = list(map(int, input().split())) -hap = [0 for _ in range(N)] -hap[0] = honey[0] -for i in range(1, N): - hap[i] = hap[i-1] + honey[i] - - -# print(honey) -# print(hap) -ans = 0 -# 벌 벌 꿀 -for i in range(1, N-1): - # 첫번째 벌의 꿀 누적합 + 두번째 벌의 꿀 누적합 - 두번째 벌의 위치의 꿀 - ans = max(ans, (hap[N-1] - honey[0]) + (hap[N-1] - hap[i]) - honey[i]) -# 꿀 벌 벌 -for i in range(1, N-1): - # 첫번째 벌의 꿀 누적합 + 두번째 벌의 꿀 누적합 - 두번째 벌의 위치의 꿀 - ans = max(ans, hap[N-2] + hap[i-1] - honey[i]) -# 벌 꿀 벌 -for i in range(1, N-1): - # 양끝에 벌이 자리를 잡으면 최대일것이고 중간에 꿀통이 위치 - ans = max(ans, hap[N-2] - honey[0] + honey[i]) - - -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/\352\260\234\354\235\270\354\240\225\353\263\264 \354\210\230\354\247\221 \354\234\240\355\232\250\352\270\260\352\260\204.py" "b/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/\352\260\234\354\235\270\354\240\225\353\263\264 \354\210\230\354\247\221 \354\234\240\355\232\250\352\270\260\352\260\204.py" deleted file mode 100644 index 13f0d19..0000000 --- "a/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/\352\260\234\354\235\270\354\240\225\353\263\264 \354\210\230\354\247\221 \354\234\240\355\232\250\352\270\260\352\260\204.py" +++ /dev/null @@ -1,29 +0,0 @@ -# 개인정보 수집 유효기간 - -def solution(today, terms, privacies): - answer = [] - a, b, c = map(int, today.split(".")) - - # 오늘 날짜를 day 로 계산 - today = a * 12 * 28 + b * 28 + c - - # 유효기간 dict - term = {} - for i in terms: - x, y = i.split() - term[x] = int(y) - - # 유효기간을 더한 날짜를 day로 계산 - for i in range(len(privacies)): - day, t = privacies[i].split() - y, m, d = map(int, day.split(".")) - m += term[t] - check = y * 12 * 28 + m * 28 + d - - # 오늘이 유효기간보다 크거나 같으면 만료 (하루를 빼야하는데 그냥 같으면 만료로 해석) - if today >= check: - answer.append(i + 1) - - # 오름차순으로 정렬 - answer.sort() - return answer \ No newline at end of file diff --git "a/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" "b/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" deleted file mode 100644 index 95d385b..0000000 --- "a/parkjunyoung/7\354\233\2241\354\243\274\354\260\250/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" +++ /dev/null @@ -1,62 +0,0 @@ -# 이중우선순위큐 - - -import heapq - - -def heapsort(iterable): - h = [] - result = [] - for value in iterable: - heapq.heappush(h, value) - for i in range(len(h)): - result.append(heapq.heappop(h)) - return result - - -def heapsort_r(iterable): - h = [] - result = [] - for value in iterable: - heapq.heappush(h, -value) - for i in range(len(h)): - result.append(-heapq.heappop(h)) - return result - - -def solution(operations): - answer = [] - for i in operations: - a, b = i.split() - # I일 경우 숫자 삽입 - if a == "I": - answer.append(int(b)) - # D일 경우 - elif a == "D": - # 1이면 최댓값을 삭제 - if b == "1": - # 값이 있을경우만 - if answer: - # 최댓값을 찾기위해 reverse 로 우선순위 큐를 정렬 - answer = heapsort_r(answer) - # 맨앞이 최댓값이니까 삭제 - heapq.heappop(answer) - # -1이면 최솟값을 삭제 - elif b == "-1": - # 값이 있으면 - if answer: - # 최솟값을 찾기위해 우선순위 큐 정렬 - answer = heapsort(answer) - # 최솟값 삭제 - heapq.heappop(answer) - - # 다시 최대값으로 정렬 - answer = heapsort_r(answer) - if answer: - # [최댓값 최솟값] - return [answer[0], answer[-1]] - else: - return [0, 0] - - -print(solution(["I -45", "I 653", "D 1", "I -642", "I 45", "I 97", "D 1", "D -1", "I 333"])) \ No newline at end of file diff --git "a/parkjunyoung/7\354\233\2242\354\243\274\354\260\250/20040-\354\202\254\354\235\264\355\201\264_\352\262\214\354\236\204.py" "b/parkjunyoung/7\354\233\2242\354\243\274\354\260\250/20040-\354\202\254\354\235\264\355\201\264_\352\262\214\354\236\204.py" deleted file mode 100644 index 4d67f00..0000000 --- "a/parkjunyoung/7\354\233\2242\354\243\274\354\260\250/20040-\354\202\254\354\235\264\355\201\264_\352\262\214\354\236\204.py" +++ /dev/null @@ -1,40 +0,0 @@ -# 사이클 게임 -import sys -input = sys.stdin.readline - - -def find(n): - if cycle[n] == n: - return n - else: - cycle[n] = find(cycle[n]) - return cycle[n] - - -def union(a, b): - x = find(a) - y = find(b) - if x < y: - cycle[y] = x - elif x > y: - cycle[x] = y - - -n, m = map(int, input().split()) -cycle = [i for i in range(n)] - -ans = 0 -for i in range(1, m+1): - a, b = map(int, input().split()) - # 두 부모가 같다면 - if find(a) == find(b): - # 몇번째 차례인지 - ans = i - # 멈춰 - break - # 아니면 유니온 - union(a, b) - - -print(ans) -# print(cycle) \ No newline at end of file diff --git "a/parkjunyoung/7\354\233\2242\354\243\274\354\260\250/2258-\354\240\225\354\234\241\354\240\220.py" "b/parkjunyoung/7\354\233\2242\354\243\274\354\260\250/2258-\354\240\225\354\234\241\354\240\220.py" deleted file mode 100644 index 5c731a5..0000000 --- "a/parkjunyoung/7\354\233\2242\354\243\274\354\260\250/2258-\354\240\225\354\234\241\354\240\220.py" +++ /dev/null @@ -1,54 +0,0 @@ -# 정육점 - -N, M = map(int, input().split()) -arr = [] -for i in range(N): - w, p = map(int, input().split()) - arr.append((p, w)) - -# 가격 오름차순, 무게 내림차순 -arr = sorted(arr, key=lambda x: (x[0], -x[1])) - -# 누적합으로 가격을 누적 -sort_p = [(0, 0)] * (N+1) -for i in range(1, N+1): - sort_p[i] = (arr[i-1][0], arr[i-1][1] + sort_p[i-1][1]) - -# 누적합으로 무게을 누적 -hap_w = [(0, 0)] * (N+1) -for i in range(1, N+1): - if sort_p[i-1][0] == sort_p[i][0]: - hap_w[i] = (hap_w[i-1][0] + sort_p[i][0], sort_p[i][1]) - else: - hap_w[i] = sort_p[i] - -ans = 2147483648 - -# 최소 가격 찾기 -for i in range(1, N+1): - if hap_w[i][1] >= M: - ans = min(ans, hap_w[i][0]) - -if ans == 2147483648: - print(-1) -else: - print(ans) - - -print(arr) -hap_w.pop(0) -print(hap_w) - -# # 반례 답 15 오답 18 -# 11 55 -# 2 1 -# 2 1 -# 2 1 -# 3 1 -# 6 2 -# 7 3 -# 7 3 -# 8 3 -# 10 3 -# 8 3 -# 8 3 \ No newline at end of file diff --git "a/parkjunyoung/7\354\233\2242\354\243\274\354\260\250/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.py" "b/parkjunyoung/7\354\233\2242\354\243\274\354\260\250/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.py" deleted file mode 100644 index dcf0c4d..0000000 --- "a/parkjunyoung/7\354\233\2242\354\243\274\354\260\250/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.py" +++ /dev/null @@ -1,78 +0,0 @@ -# 자물쇠와 열쇠 - -# 시계 방향으로 회전하기 -def turn(key): - temp = list(map(list, zip(*key[::-1]))) - # for i in temp: - # print(i) - return temp - - -def solution(key, lock): - answer = True - num1 = len(lock) - num2 = len(key) - # 키가 들어갈 자리를 담는 배열 - lock_point = [] - for i in range(num1): - for j in range(num1): - if lock[i][j] == 0: - lock_point.append((i+num2-1, j+num2-1)) - cnt = len(lock_point) - - # key의 총개수 확인 - key_cnt = 0 - for i in range(num2): - for j in range(num2): - if key[i][j] == 1: - key_cnt += 1 - - # 배열을 자물쇠를 기준으로 양 옆을 키의 길이 -1 만큼씩 추가 - num3 = num1 + 2*num2 - 2 - pan = [[0 for _ in range(num3)] for _ in range(num3)] - - # 자물쇠를 가운데 배치 - for i in range(num1): - for j in range(num1): - if lock[i][j] == 1: - pan[i+num2-1][j+num2-1] = 1 - # for i in pan: - # print(i) - - - def check(i, j): - temp_lock = 0 - temp_key = 0 - # key의 범위 만큼 탐색 - for r in range(num2): - for c in range(num2): - # 각 점에서 만약 키값이 1 이고 - if key[r][c] == 1: - # 그점이 lock point이면 - if (i+r, j+c) in lock_point: - temp_lock += 1 - # 그점이 0이라면 - if pan[i+r][j+c] == 0: - temp_key += 1 - # 키에 다 맞아들어가고 - if cnt == temp_lock: - # 키가 범위를 벋어나도 배치가 된다면 - if key_cnt == temp_key: - return True - return False - - - for _ in range(4): - #끝까지 탐색할 필요는 없음 - for i in range(num3-num2+1): - for j in range(num3-num2+1): - # check - answer = check(i, j) - if answer: - return answer - # 회전 - key = turn(key) - return answer - - -print(solution([[0, 0, 0], [1, 0, 0], [0, 1, 1]],[[1, 1, 1], [1, 1, 0], [1, 0, 1]])) \ No newline at end of file diff --git "a/parkjunyoung/7\354\233\2243\354\243\274\354\260\250/11497-\355\206\265\353\202\230\353\254\264_\352\261\264\353\204\210\353\233\260\352\270\260.py" "b/parkjunyoung/7\354\233\2243\354\243\274\354\260\250/11497-\355\206\265\353\202\230\353\254\264_\352\261\264\353\204\210\353\233\260\352\270\260.py" deleted file mode 100644 index d2357c6..0000000 --- "a/parkjunyoung/7\354\233\2243\354\243\274\354\260\250/11497-\355\206\265\353\202\230\353\254\264_\352\261\264\353\204\210\353\233\260\352\270\260.py" +++ /dev/null @@ -1,32 +0,0 @@ -# 통나무 건너뛰기 - -from collections import deque -T = int(input()) - -for tc in range(T): - N = int(input()) - temp = list(map(int, input().split())) - # 정렬 - temp.sort() - temp = deque(temp) - # 2분탐색? 느낌 - arr = [0] * N - l = 0 - r = N-1 - # 왼쪽 오른쪽에 작은거를 계속 넣어준다 - for i in range(N//2): - arr[l] = temp.popleft() - arr[r] = temp.popleft() - l += 1 - r -= 1 - # 다돌고도 1개가 남을 수있으니까 가운데 넣어준다 - if temp: - arr[N//2] = temp.popleft() - - ans = 0 - # print(arr) - for i in range(N): - ans = max(ans, abs(arr[i] - arr[i-1])) - print(ans) - - diff --git "a/parkjunyoung/7\354\233\2243\354\243\274\354\260\250/1987-\354\225\214\355\214\214\353\262\263.py" "b/parkjunyoung/7\354\233\2243\354\243\274\354\260\250/1987-\354\225\214\355\214\214\353\262\263.py" deleted file mode 100644 index 29d8fe1..0000000 --- "a/parkjunyoung/7\354\233\2243\354\243\274\354\260\250/1987-\354\225\214\355\214\214\353\262\263.py" +++ /dev/null @@ -1,42 +0,0 @@ -# 알파벳 -import sys -input = sys.stdin.readline - -R, C = map(int, input().split()) - -dx = [1, 0, -1, 0] -dy = [0, 1, 0, -1] - -pan = [] -for i in range(R): - temp = list(input()) - pan.append(temp) - -# for i in pan: -# print(i) - -visited = [0 for _ in range(26)] -visited[ord(pan[0][0])-65] = 1 -max_cnt = 0 -# print(visited) - - -def dfs(x, y, cnt): - global max_cnt - if cnt >= max_cnt: - max_cnt = cnt - for d in range(4): - nx = x + dx[d] - ny = y + dy[d] - if 0 <= nx < R and 0 <= ny < C: - if visited[ord(pan[nx][ny])-65] == 0: - visited[ord(pan[nx][ny])-65] = 1 - dfs(nx, ny, cnt + 1) - visited[ord(pan[nx][ny])-65] = 0 - - -dfs(0, 0, 1) -# for i in visited: -# print(i) -print(max_cnt) -# print(len(check_alpha)) \ No newline at end of file diff --git "a/parkjunyoung/7\354\233\2243\354\243\274\354\260\250/2096-\353\202\264\353\240\244\352\260\200\352\270\260.py" "b/parkjunyoung/7\354\233\2243\354\243\274\354\260\250/2096-\353\202\264\353\240\244\352\260\200\352\270\260.py" deleted file mode 100644 index c1ab6fe..0000000 --- "a/parkjunyoung/7\354\233\2243\354\243\274\354\260\250/2096-\353\202\264\353\240\244\352\260\200\352\270\260.py" +++ /dev/null @@ -1,36 +0,0 @@ -# 내려가기 -import sys -input = sys.stdin.readline -N = int(input()) -arr = [] -max_dp = [0, 0, 0] -min_dp = [0, 0, 0] -max_temp = [0, 0, 0] -min_temp = [0, 0, 0] - -for i in range(N): - a, b, c = map(int, input().split()) - - for j in range(3): - # 1번위치에서 - if j == 0: - # 1번 위치 2번 위치 중 최대 최소를 더하면 현재위치의 최대 최소 - max_dp[0] = max(max_temp[j], max_temp[j+1]) + a - min_dp[0] = min(min_temp[j], min_temp[j+1]) + a - # 2번 위치에서 - elif j == 1: - # 1번 2번 3번 중 최대 최소 - max_dp[1] = max(max_temp[j-1], max_temp[j], max_temp[j+1]) + b - min_dp[1] = min(min_temp[j-1], min_temp[j], min_temp[j+1]) + b - # 3번 위치에서 - elif j == 2: - # 2번 3번 중 최대 최소 - max_dp[2] = max(max_temp[j-1], max_temp[j]) + c - min_dp[2] = min(min_temp[j-1], min_temp[j]) + c - max_temp = max_dp.copy() - min_temp = min_dp.copy() - # print(max_dp) - - - # print(min_dp) -print(max(max_dp), min(min_dp)) \ No newline at end of file diff --git "a/parkjunyoung/7\354\233\2243\354\243\274\354\260\250/\354\240\204\355\231\224\353\262\210\355\230\270_\353\252\251\353\241\235.py" "b/parkjunyoung/7\354\233\2243\354\243\274\354\260\250/\354\240\204\355\231\224\353\262\210\355\230\270_\353\252\251\353\241\235.py" deleted file mode 100644 index b387a65..0000000 --- "a/parkjunyoung/7\354\233\2243\354\243\274\354\260\250/\354\240\204\355\231\224\353\262\210\355\230\270_\353\252\251\353\241\235.py" +++ /dev/null @@ -1,21 +0,0 @@ -# 전화 번호 목록 - - -def solution(phone_book): - answer = True - # 정렬 - phone_book.sort() - # 반복 - for i in range(len(phone_book)-1): - # 그다음 전화번호의 앞부분[:] 이 현재 전화번호의 길이랑 비교해서 접두어 이면 - if phone_book[i] in phone_book[i+1][:len(phone_book[i])]: - answer = False - return answer - return answer - - -phone_book = ["12","123","1235","567","88"] - -print(solution(phone_book)) - - diff --git "a/parkjunyoung/8\354\233\2241\354\243\274\354\260\250/12851-\354\210\250\353\260\224\352\274\255\354\247\2102.py" "b/parkjunyoung/8\354\233\2241\354\243\274\354\260\250/12851-\354\210\250\353\260\224\352\274\255\354\247\2102.py" deleted file mode 100644 index 03ea955..0000000 --- "a/parkjunyoung/8\354\233\2241\354\243\274\354\260\250/12851-\354\210\250\353\260\224\352\274\255\354\247\2102.py" +++ /dev/null @@ -1,49 +0,0 @@ -# 숨바꼭질 2 - -from collections import deque - -N, K = map(int, input().split()) -q = deque() -q.append(N) - -# 방문처리 -visited = [0] * 100001 -visited[N] = 1 - - -def bfs(q): - time = 0 - cnt = 0 - while q: - x = q.popleft() - # K에 도착하면 개수 +1 시간을 저장하는데 처음부터 1을 줘서 1을 뺀다 - if x == K: - cnt += 1 - time = visited[K]-1 - - # 2배일 경우 - if 0 <= x*2 < 100001: - # 방문하지 않았거나 같은 시간안에 도착한곳이라면 - if visited[x*2] == 0 or visited[x*2] == visited[x]+1: - # 현재위치의 시간을 갱신하고 q 에 추가 - visited[x*2] = visited[x]+1 - q.append(x*2) - # +1 할 경우 - if 0 <= x+1 < 100001: - if visited[x+1] == 0 or visited[x+1] == visited[x]+1: - visited[x+1] = visited[x]+1 - q.append(x+1) - # -1 할 경우 - if 0 <= x-1 < 100001: - if visited[x-1] == 0 or visited[x-1] == visited[x]+1: - visited[x-1] = visited[x]+1 - q.append(x-1) - - return [time, cnt] - - -ans = [] -ans = bfs(q) - -for i in ans: - print(i) \ No newline at end of file diff --git "a/parkjunyoung/8\354\233\2241\354\243\274\354\260\250/17144-\353\257\270\354\204\270\353\250\274\354\247\200_\354\225\210\353\205\225!.py" "b/parkjunyoung/8\354\233\2241\354\243\274\354\260\250/17144-\353\257\270\354\204\270\353\250\274\354\247\200_\354\225\210\353\205\225!.py" deleted file mode 100644 index f0d8c61..0000000 --- "a/parkjunyoung/8\354\233\2241\354\243\274\354\260\250/17144-\353\257\270\354\204\270\353\250\274\354\247\200_\354\225\210\353\205\225!.py" +++ /dev/null @@ -1,94 +0,0 @@ -# 미세먼지 안녕! - -R, C, T = map(int, input().split()) -room = [[int(i) for i in input().split()] for _ in range(R)] - -# for i in range(R): -# print(room[i]) - -cleaner = [] -flag = False -for i in range(R): - for j in range(C): - if room[i][j] == -1: - flag = True - cleaner = [[i, j], [i+1, j]] - break - if flag == True: - break -# print(cleaner) - - -def dust(): - copyroom = [[0]*C for _ in range(R)] # 새로운 배열 - dx = [1, 0, -1, 0] # 우 상 좌 하 - dy = [0, -1, 0, 1] - for i in range(R): - for j in range(C): - if room[i][j] != 0 and room[i][j] != -1: # 미세먼지가 잇으면 - temp = room[i][j] - for k in range(4): # 4방향을 확인하고 - nx = i + dx[k] - ny = j + dy[k] - if 0 <= nx < R and 0 <= ny < C: # 범위안에 있고 - if room[nx][ny] != -1: # 청소기가 아니면 - copyroom[nx][ny] += (room[i][j]//5) # 새로운 배열에 확산값을 더해주고 - temp -= (room[i][j]//5) # 기존 값은 확산된값을 빼주고 - copyroom[i][j] += temp # 4방향 다 확산하면 기존값을 갱신 - for i, j in cleaner: - copyroom[i][j] = -1 - - return copyroom - - -def wind(room): - # 위쪽 바람 - for i in range(cleaner[0][0]-1, 0, -1): # 위에서 아래로 - room[i][0] = room[i-1][0] - room[0][0] = 0 - - for i in range(0, C-1): # 왼쪽으로 - room[0][i] = room[0][i+1] - room[0][C - 1] = 0 - - for i in range(0, cleaner[0][0]): # 위로 - room[i][C-1] = room[i+1][C-1] - room[cleaner[0][0]][C-1] = 0 - - for i in range(C-1, 1, -1): # 오른쪽으로 부는 바람 - room[cleaner[0][0]][i] = room[cleaner[0][0]][i-1] - room[cleaner[0][0]][1] = 0 - - # 아래바람 - for i in range(cleaner[1][0]+2, R): # 위로 부는 바람 - room[i-1][0] = room[i][0] - room[R-1][0] = 0 - - for i in range(0, C-1): # 왼쪽으로 부는 바람 - room[R-1][i] = room[R-1][i + 1] - room[R-1][C-1] = 0 - - for i in range(R-1, cleaner[1][0], -1): # 아래로 부는 바람 - room[i][C-1] = room[i-1][C-1] - room[cleaner[1][0]][C-1] = 0 - - for i in range(C-1, 1, -1): # 오른쪽으로 부는 바람 - room[cleaner[1][0]][i] = room[cleaner[1][0]][i-1] - room[cleaner[1][0]][1] = 0 - - -for i in range(T): - room = dust() - wind(room) - # for j in range(R): - # print(room[j]) - - -ans = 0 -for i in range(R): - for j in range(C): - ans += room[i][j] - -ans += 2 - -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/8\354\233\2241\354\243\274\354\260\250/17281-\354\225\274\352\265\254\352\263\265.py" "b/parkjunyoung/8\354\233\2241\354\243\274\354\260\250/17281-\354\225\274\352\265\254\352\263\265.py" deleted file mode 100644 index 961fdf5..0000000 --- "a/parkjunyoung/8\354\233\2241\354\243\274\354\260\250/17281-\354\225\274\352\265\254\352\263\265.py" +++ /dev/null @@ -1,38 +0,0 @@ -# 야구공 -from itertools import permutations - -N = int(input()) -arr = [i for i in range(1, 9)] -per = list(permutations(arr, 8)) -board = [] -for i in range(N): - temp = list(map(int, input().split())) - board.append(temp) -ans = 0 - -for i in per: - taja = list(i[:3]) + [0] + list(i[3:]) - score = 0 - now = 0 - for j in range(N): - out = 0 - b1, b2, b3 = 0, 0, 0 - while out < 3: - if board[j][taja[now]] == 0: - out += 1 - elif board[j][taja[now]] == 1: - score += b3 - b1, b2, b3 = 1, b1, b2 - elif board[j][taja[now]] == 2: - score += (b2 + b3) - b1, b2, b3 = 0, 1, b1 - elif board[j][taja[now]] == 3: - score += (b1 + b2 + b3) - b1, b2, b3 = 0, 0, 1 - elif board[j][taja[now]] == 4: - score += (b1 + b2 + b3 + 1) - b1, b2, b3 = 0, 0, 0 - now = (now+1) % 9 - ans = max(ans, score) - -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/8\354\233\2241\354\243\274\354\260\250/1915-\352\260\200\354\236\245_\355\201\260_\354\240\225\354\202\254\352\260\201\355\230\225.py" "b/parkjunyoung/8\354\233\2241\354\243\274\354\260\250/1915-\352\260\200\354\236\245_\355\201\260_\354\240\225\354\202\254\352\260\201\355\230\225.py" deleted file mode 100644 index 68e17b5..0000000 --- "a/parkjunyoung/8\354\233\2241\354\243\274\354\260\250/1915-\352\260\200\354\236\245_\355\201\260_\354\240\225\354\202\254\352\260\201\355\230\225.py" +++ /dev/null @@ -1,34 +0,0 @@ -# 가장 큰 정사각형 - -n, m = map(int, input().split()) -pan = [] -for _ in range(n): - row = input() - pan.append([int(ch) for ch in row]) - -dp = [[0 for _ in range(m)] for _ in range(n)] -maxSize = 0 - -# 첫 번째 행과 첫 번째 열은 그대로 dp 배열에 저장 -for i in range(n): - dp[i][0] = pan[i][0] - maxSize = max(maxSize, dp[i][0]) - -for j in range(m): - dp[0][j] = pan[0][j] - maxSize = max(maxSize, dp[0][j]) - - -# 나머지 칸들을 계산하여 dp 배열에 저장 -for i in range(1, n): - for j in range(1, m): - if pan[i][j] == 1: - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]) + 1 - maxSize = max(maxSize, dp[i][j]) - - for i in dp: - print(i) - print('-------------------------') - -print(maxSize **2) # 가장 큰 정사각형의 넓이 출력 - diff --git "a/parkjunyoung/8\354\233\2244\354\243\274\354\260\250/14226-\354\235\264\353\252\250\355\213\260\354\275\230.py" "b/parkjunyoung/8\354\233\2244\354\243\274\354\260\250/14226-\354\235\264\353\252\250\355\213\260\354\275\230.py" deleted file mode 100644 index 8e94c2b..0000000 --- "a/parkjunyoung/8\354\233\2244\354\243\274\354\260\250/14226-\354\235\264\353\252\250\355\213\260\354\275\230.py" +++ /dev/null @@ -1,38 +0,0 @@ -# 이모티콘 - -from collections import deque - -S = int(input()) - - -# [화면, 클립보드] -dp = [[-1 for _ in range(1001)] for _ in range(1001)] -# 초기값 1초 -dp[1][0] = 0 - -q = deque() -q.append((1, 0)) -while q: - desktop, clipboard = q.popleft() - # 1 - if dp[desktop][desktop] == -1: - dp[desktop][desktop] = dp[desktop][clipboard] + 1 - q.append((desktop, desktop)) - - # 2 - if 1 < desktop+clipboard < 1001 and dp[desktop+clipboard][clipboard] == -1: - dp[desktop+clipboard][clipboard] = dp[desktop][clipboard] + 1 - q.append((desktop+clipboard, clipboard)) - - # 3 - if 1 < desktop-1 and dp[desktop-1][clipboard] == -1: - dp[desktop-1][clipboard] = dp[desktop][clipboard] + 1 - q.append((desktop-1, clipboard)) - -# print(dp[S]) -ans = 9999 -for i in dp[S]: - if i != -1: - ans = min(ans, i) - -print(ans) \ No newline at end of file diff --git "a/parkjunyoung/8\354\233\2244\354\243\274\354\260\250/2138-\354\240\204\352\265\254\354\231\200_\354\212\244\354\234\204\354\271\230.py" "b/parkjunyoung/8\354\233\2244\354\243\274\354\260\250/2138-\354\240\204\352\265\254\354\231\200_\354\212\244\354\234\204\354\271\230.py" deleted file mode 100644 index 74d3169..0000000 --- "a/parkjunyoung/8\354\233\2244\354\243\274\354\260\250/2138-\354\240\204\352\265\254\354\231\200_\354\212\244\354\234\204\354\271\230.py" +++ /dev/null @@ -1,62 +0,0 @@ -# 전구와 스위치 - -N = int(input()) -arr_1 = list(input()) -for x in range(len(arr_1)): - if arr_1[x] == '0': - arr_1[x] = False - else: - arr_1[x] = True -arr_2 = arr_1.copy() -ans = list(input()) -for x in range(len(ans)): - if ans[x] == '0': - ans[x] = False - else: - ans[x] = True - - -cnt_1 = 0 -cnt_2 = 1 - - -# 처음스위치를 패스 -for i in range(1, N): - # i-1 이랑 같지 않으면 - if arr_1[i - 1] != ans[i - 1]: - cnt_1 += 1 - # 앞 현재 뒤 변경 - arr_1[i] = not arr_1[i] - arr_1[i - 1] = not arr_1[i - 1] - # 마지막일때는 index 에러 방지 - if i != N - 1: - arr_1[i + 1] = not arr_1[i + 1] - - - - -if arr_1 != ans: - cnt_1 = 9999999 - - -# 처음 스위치 누를때 -arr_2[0] = not arr_2[0] -arr_2[1] = not arr_2[1] - -for i in range(1, N): - if arr_2[i - 1] != ans[i - 1]: - cnt_2 += 1 - # 앞 현재 뒤 변경 - arr_2[i] = not arr_2[i] - arr_2[i - 1] = not arr_2[i - 1] - # 마지막일때는 index 에러 방지 - if i != N - 1: - arr_2[i + 1] = not arr_2[i + 1] - -if arr_2 != ans: - cnt_2 = 9999999 - -if cnt_1 == 9999999 and cnt_2 == 9999999: - print(-1) -else: - print(min(cnt_1, cnt_2)) \ No newline at end of file diff --git a/python_codingTest b/python_codingTest new file mode 160000 index 0000000..78048ef --- /dev/null +++ b/python_codingTest @@ -0,0 +1 @@ +Subproject commit 78048effa60d78cb1fbd5cc32404352f4d4fecb9