문제풀이

https://www.acmicpc.net/problem/16507코드import sysinput = sys.stdin.readliner, c, q = map(int, input().split())picture = [list(map(int, input().split())) for _ in range(r)]# 누적합 구하기acc = [[0]*(c+1) for _ in range(r+1)]for i in range(r): for j in range(c): acc[i+1][j+1] = acc[i][j+1] + acc[i+1][j] - acc[i][j] + picture[i][j]for _ in range(q): r1, c1, r2, c2 = map(int, input().split())..
https://www.acmicpc.net/problem/2910코드from heapq import heappop, heappushimport sysinput = sys.stdin.readlinen, c = map(int, input().split())arr = list(map(int, input().split()))count_dict = dict()for i in range(n): if arr[i] not in count_dict: count_dict[arr[i]] = [i, 1] else: count_dict[arr[i]][1] += 1hq = []for k, v in count_dict.items(): heappush(hq, [-v[1], v[0], k])w..
https://www.acmicpc.net/problem/2941코드croatia_alphabet = set(["c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="])input_str = input()n = len(input_str)answer = 0idx = 0while idx = n-1: break if idx  두 글자 이상의 알파벳은 집합에 따로 모아둔다.그리고 입력으로 주어진 문자열을 순회하며  1. 현재 인덱스부터 시작해서 2글자가 크로아티아 알파벳이라면 continue2. 현재 인덱스부터 시작해서 3글자가 크로아티아 알파벳인지 continue3. 둘 다 아니면 한 글자짜리 알파벳 이렇게 while문을 도는 횟수를 구하면 알파벳의 개수를 구할 ..
https://www.acmicpc.net/problem/16932코드from collections import dequeimport sysinput = sys.stdin.readlinen, m = map(int, input().split())matrix = [list(map(int, input().split())) for _ in range(n)]dx = [-1, 1, 0, 0]dy = [0, 0, -1, 1]def bfs(x, y, group_num): res = 1 q = deque([(x, y)]) matrix[x][y] = group_num while q: now_x, now_y = q.popleft() for i in range(4): ..
·문제풀이/DP
https://www.acmicpc.net/problem/13902코드import sysinput = sys.stdin.readlineINF = int(1e9)n, m = map(int, input().split())s = list(map(int, input().split()))wok_set = set(s)dp = [INF]*(n+1)for i in range(m): dp[s[i]] = 1 for j in range(i+1, m): if s[i]+s[j]  로직은 어렵지 않은데 시간 복잡도 줄이기가 정말 어려웠던 문제였다...조건문을 잘 사용해서 필요없는 연산은 최대한 넘어가는 것이 중요하다. 1. 웍으로 한 번에 조리 가능한 경우의 수를 wok_set에 저장할 때 dp에도 1로 ..
딜레이레이
'문제풀이' 카테고리의 글 목록 (13 Page)