문제 6일차. 문자열 나누기

def slice_str(N, S):
	cases = []
	all_str = set()
	
	for i in range(N - 2):
		for j in range(i + 1, N - 1):
			for k in range(j + 1, N):
				s1, s2, s3 = S[:j], S[j:k], S[k:]
				cases.append([s1, s2, s3])
				all_str.update([s1, s2, s3])
	
	return cases, all_str
	

def get_max_score(N, S):
	cases, all_str = slice_str(N, S)
	score_dict = {key: value + 1 for value, key in enumerate(sorted(list(all_str)))}
	result = 0
	
	for s1, s2, s3 in cases:
		result = max(result, score_dict[s1] + score_dict[s2] + score_dict[s3])
	
	return result
	

N = int(input())
S = input()
print(get_max_score(N, S))

문제 7일차. 구름 찾기 깃발

N, K = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(N)]

dx = [-1, 1, 0, 0, -1, -1, 1, 1]
dy = [0, 0, -1, 1, -1, 1, -1, 1]
cnt_arr = []
for x in range(N):
	for y in range(N):
		if board[x][y] == 1: continue
		cnt = 0
		for i in range(8):
			nx, ny = x + dx[i], y + dy[i]
			if 0 <= nx < N and 0 <= ny < N and board[nx][ny] == 1:
				cnt += 1
		cnt_arr.append(cnt)

print(cnt_arr.count(K))

문제 8일차. 통증

items = [14, 7, 1]

N = int(input())
cnt = 0

for item in items:
	if N < item: continue
	cnt += N // item
	N %= item

print(cnt)

문제 9일차. 폭탄 구현하기 (2)

import sys
input=sys.stdin.readline

N, K = map(int, input().split())
land = [input().rstrip().split() for _ in range(N)]
arr = [[0] * N for _ in range(N)]

for _ in range(K):
	y, x = map(int, input().split())
	if 0 < x <= N and 0 < y <= N:
		for dx, dy in zip([0, -1, 1, 0, 0], [0, 0, 0, -1, 1]):
			nx, ny = x + dx - 1, y + dy - 1
			if 0 <= nx < N and 0 <= ny < N:
				if land[ny][nx] == '@':
					arr[ny][nx] += 2
				elif land[ny][nx] == '0':
					arr[ny][nx] += 1

print(max([max(i) for i in arr]))

문제 10일차. GameJam

def game_jam(N, board, r, c):
	weight = {'U': (-1, 0), 'D': (1, 0), 'R': (0, 1), 'L': (0, -1)}
	visited = [[False] * N for _ in range(N)]
	
	result = 1
	visited[r][c] = True
	
	while True:	
		count, command = int(board[r][c][:-1]), board[r][c][-1]
		dr, dc = weight[command]
		
		while count:
			r, c = (r + dr) % N, (c + dc) % N
			if visited[r][c] is True:
				return result
			visited[r][c] = True
			count -= 1
			result += 1
	
	return result

N = int(input())
goorm_r, goorm_c = map(int, input().split())
player_r, player_c = map(int, input().split())
board = [input().split() for _ in range(N)]

goorm_score = game_jam(N, board, goorm_r - 1, goorm_c - 1)
player_score = game_jam(N, board, player_r - 1, player_c - 1)

print("goorm", goorm_score) if goorm_score > player_score else print("player", player_score)