목록Python (288)
홍우진의 개발새발
문제 링크https://www.acmicpc.net/problem/14468풀이 코드import sysline = sys.stdin.readline().strip()tot = 0for start in range(52): for end in range(start + 1, 52): if line[start] == line[end]: path = line[start + 1 : end] for cow in set(path): if path.count(cow) == 1: tot += 1 breakprint(tot // 2)코드 해석어떤 소의 경로 안(시작점과 끝점 사이)에 다른..
문제 링크https://www.acmicpc.net/problem/2891풀이 코드import sysN, S, R = map(int, sys.stdin.readline().split())damaged_teams = list(map(int, sys.stdin.readline().split()))reserve_teams = list(map(int, sys.stdin.readline().split()))kayaks = [1] * (N + 2)for team in damaged_teams: kayaks[team] -= 1for team in reserve_teams: kayaks[team] += 1for i in range(1, N + 1): if kayaks[i] == 0: if ..
문제 링크https://www.acmicpc.net/problem/9324풀이 코드for _ in range(int(input())): message = input() cnt = {} i = 0 while i = len(message) or message[i+1] != char: print("FAKE") break cnt[char] = 0 i += 1 i += 1 else: print("OK")코드 해석딕셔너리를 사용해서 해당 문자의 출현 횟수를 카운팅한다. 체감 난이도: ★★★☆☆
문제 링크https://www.acmicpc.net/problem/30804풀이 코드import sys# input = sys.stdin.readlineN = int(input())fruits = list(map(int, input().split()))left = 0max_len = 0cnt = {} for right in range(N): current_fruit = fruits[right] cnt[current_fruit] = cnt.get(current_fruit, 0) + 1 while len(cnt) > 2: left_fruit = fruits[left] cnt[left_fruit] -= 1 if cnt[left_fruit] == 0: ..
문제 링크https://www.acmicpc.net/problem/2630풀이 코드import sysinput = sys.stdin.readlinedef cut(x, y, size): global wh, bl start_color = paper[x][y] for i in range(x, x + size): for j in range(y, y + size): if paper[i][j] != start_color: half_size = size // 2 cut(x, y, half_size) cut(x, y + half_size, half_size) cut..
문제 링크https://www.acmicpc.net/problem/16439풀이 코드import sysfrom itertools import combinationsN, M = map(int, sys.stdin.readline().split())prefs = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]ans = 0for c1, c2, c3 in combinations(range(M), 3): total = 0 for i in range(N): total += max(prefs[i][c1], prefs[i][c2], prefs[i][c3]) ans = max(ans, total)print(ans)코드 해석it..
문제 링크https://www.acmicpc.net/problem/1544풀이 코드import sysn = int(sys.stdin.readline())representatives = [] for _ in range(n): word = sys.stdin.readline().strip() is_new = True for rep in representatives: if len(word) == len(rep) and word in rep * 2: is_new = False break if is_new: representatives.append(word)print(len(representatives)) 코드 해석 단어가 이미 ..
문제 링크https://www.acmicpc.net/problem/11008풀이 코드import sysT = int(sys.stdin.readline())for _ in range(T): s, p = sys.stdin.readline().split() count = s.count(p) remaining_chars = len(s) - (len(p) * count) result = count + remaining_chars print(result)코드 해석s에서 p가 몇 번 등장하는지 센 다음,그 횟수만큼 1초를 더하고,나머지 문자들은 1초씩 더해준다. 체감 난이도: ★☆☆☆☆