Python

Python

[백준] 5430 AC (Python)

[Gold V] AC - 5430 [골드 5] AC - 5430 문제 링크: https://www.acmicpc.net/problem/5430 예제 입력 1) 4 RDD 4 [1,2,3,4] DD 1 [42] RRD 6 [1,1,2,3,5,8] D 0 [] 예제 출력 1) [2,1] error [1,2,3,5,8] error 전체 코드 1) 가장 짧은 코드 from collections import deque for _ in range(int(input())): c=input() n=int(input()) q=deque(eval(input())) try: step=1 for p in c: if p=="R": step*=-1 else: q.popleft() if step==1 else q.pop() pri..

Python

[백준] 2606 바이러스 (Python)

[실버3] 문제 링크 : https://www.acmicpc.net/problem/2606 ⌨️예제 입력 1 7 6 1 2 2 3 1 5 5 2 5 6 4 7 🖥️예제 출력 1 4 🪄전체 코드 def dfs(v=1): #시작 기본값 1번 컴퓨터 visited[v]=True for i in graph[v]: if not visited[i]: dfs(i) n=int(input()) graph=[[] for _ in range(n+1)] visited=[False]*(n+1) for _ in range(int(input())): x,y=map(int,input().split()) graph[x].append(y) graph[y].append(x) dfs() print(sum(visited)-1) 📄설명 기본 ..

Python

[프로그래머스]거리두기 확인하기 BFS 안쓰고 풀기 (파이썬)

문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/81302 검사했던 부분을 다시 검사해야 하기 때문에 비효율 적이지만, 데이터가 5X5 행렬 5개뿐이라 BFS를 쓰지 않고 풀 수 있을 것 같았다. 전체 코드 def solution(places): answer=[] for room in places: illigal=False for x in range(4): for y in range(4): squere=room[x][y:y+2]+room[x+1][y:y+2] #2X2 사각형 만들기 if (squere.count("P")>=2) and ("O" in squere): #대각선 체크 illigal=True for x in range(5): if ("PP..

Python

[프로그래머스] 주차 요금 계산 (Python) - 숏코딩 3줄로 성공

2022 KAKAO BLIND RECRUITMENT [LV.2] 주차 요금 계산 문제 링크: https://programmers.co.kr/learn/courses/30/lessons/92341 물론, 짧은코드가 좋은코드는 아닙니다. 하지만 숏코딩은 내가 알고 있는 문법을 점검하기 좋은 기회이니 둘러보고 가세요!😊 백준은 숏코딩 순위가 나오지만, 프로그래머스에는 그런 기능이 없어서 올리게 되었다. 나만 보기 아까워서.. 코드 def solution(f,r): d={} for e in r:d[e[6:10]]=d.get(e[6:10],0)+(-1 if e[11:]=='IN' else 1)*(int(e[:2])*60+int(e[3:5])) return [(f[1]-(-max(0,d[n]+1439*(d[n] 형..

리즈(Liz)
'Python' 카테고리의 글 목록