IT/coding study 44

[acmicpc] 21610. 마법사 상어와 비바라기(python)

아주 오랜만에 풀어서 감을 잃어, 타 블로그도 참고해보았다. (구름 칸 인덱스를 담는 배열 생성하기!) [단계별 풀이] 1. 구름칸 이동하기 2. 구름칸에 1씩 더하기 3. 구름칸 비우기 4. 구름칸에 각 대각선 물의 개수 더하기 5. 구름 만들기 (물의 양 2이상, 이전 구름칸 미포함) 정답코드 import sys input=sys.stdin.readline diry=[0,-1,-1,-1,0,1,1,1] dirx=[-1,-1,0,1,1,1,0,-1] # 대각선: 1, 3, 5, 7 if __name__ == "__main__": N,M=map(int,input().split()) maps=[] methods=[] clouds=[[N-2,0],[N-2,1],[N-1,0],[N-1,1]] for _ in ..

IT/coding study 2021.10.20

[programmers] 베스트앨범(python)

1. key와 value를 갖고 있는 dictionary를 이용하여 문제를 풀었습니다. 2. index번호를 정답으로 출력시켜야하므로, value값에 (재생횟수와 index) 쌍을 저장하였습니다. 3. lambda를 이용하여 list와 dictionary에 정렬을 수행하였습니다. - a=[(1,2),(0,1)] 먼저 첫 번째 인자를 기준으로 오름차순으로 정렬하고, 그 다음 두 번째 인자를 기준으로 내림차순으로 정렬할 경우, a.sort(key=lambda x:(x[0],-x[1])) 정답 코드 def solution(genres, plays): answer = [] dict={} sum={} for i in range(len(genres)): if genres[i] not in dict: dict[gen..

IT/coding study 2021.03.18

[acmicpc] 11656. 접미사 배열(python)

s = input() arr=[] for i in range(0,len(s)): arr.append(s[i:]) arr = sorted(arr) for i in range(0,len(s)): print(arr[i]) : 평소 c++을 사용하다가 문자열을 다루는 문제는 python으로 간단하게 해결할 수 있어, python을 이용하여 풀어보았습니다. https://www.acmicpc.net/problem/11656 11656번: 접미사 배열 첫째 줄에 문자열 S가 주어진다. S는 알파벳 소문자로만 이루어져 있고, 길이는 1,000보다 작거나 같다. www.acmicpc.net

IT/coding study 2021.01.28

[acmicpc] 7576. 토마토(BFS)

bfs로 구현해보았습니다 메모리초과, 시간초과, ... 틀렸습니다에 이은 결과 값! #include #include int x, y; int arr[1000][1000]; int visit[1000][1000]; int depth[1000][1000]; using namespace std; int d_x[4] = { 0, 0, 1, -1 }; int d_y[4] = { 1, -1, 0, 0 }; queue qx; queue qy; int min_value; int cnt = 0; int flag = 0; void bfs() { while (!qx.empty() && !qy.empty()) { int temp_x = qx.front(); qx.pop(); int temp_y = qy.front(); qy...

IT/coding study 2020.09.26