브루트포스

10973번 – 이전수열

1

문제 풀이 코드 def intJoin(arr): return " ".join([str(i) for i in arr]) def answer(): global arr for i in range(len(arr)-1, 0, -1): if arr[i] > arr[i-1]: continue left = arr[:i] right = sorted(arr[i:], reverse=True) for j in range(len(right)): if left[-1] > right[j]: temp = left[-1] left[-1] = right[j] right[j] = temp break return intJoin(left+sorted(right, reverse=True)) return -1 n = int(input()) arr...

14499번 – 주사위 굴리기

1

문제 풀이 코드 def answer(): global n, m, y, x, k, board, operations BOTTOM = 6 UP = 1 dirs = [0, (0, 1), (0, -1), (-1, 0), (1, 0)] d = [0, 0, 0, 0, 0, 0, 0] ds = [ 0, [0, 4, 2, 1, 6, 5, 3], # 동 [0, 3, 2, 6, 1, 5, 4], # 서 [0, 5, 1, 3, 4, 6, 2], # 북 [0, 2, 6, 3, 4, 1, 5] # 남 ] for op in operations: _y, _x = y, x # 백업 y, x = (y+dirs[op][0], x+dirs[op][1]) if y < 0 or y >= n or x < 0 or x >= m: y, x...

10819번 – 차이를 최대로

1

문제

풀이

코드

from itertools import permutations

def answer():
global n, arr
perms = list(permutations(arr, len(arr)))
maxArr = []
for case in perms:
diffSum = 0
for i in range(1, len(case)):
diffSum += abs(case[i] - case[i-1])
maxArr.append(diffSum)
print(max(maxArr))

n = int(input())
arr = list(map(int, input().split()))
answer()

17136번 – 색종이 붙이기

1

문제 풀이 코드 # 17136-색종이 붙이기 def 사용한색종이개수(papers): return 25 - sum([papers[i] for i in range(1, 6)]) def 범위가모두일인가(y, x, k): global board for i in range(y, y+k): for j in range(x, x+k): if board[i][j] == 0: return False return True def 색종이붙이기(y, x, k): global board for i in range(y, y+k): for j in range(x, x+k): board[i][j] = 0 def 색종이떼기(y, x, k): global board for i in range(y, y+k): for j in range(x...

1065번 – 한수

1

문제

풀이

코드

def check(n):
if n < 100: return True
arr = [int(i) for i in str(n)]
diff = arr[1] - arr[0]
for i in range(2, len(arr)):
if (arr[i] - arr[i-1]) != diff: return False
return True

def answer(n):
count = 0
for i in range(1, n+1):
if check(i): count += 1
return count

n = int(input())
print(answer(n))

2309번 – 일곱난쟁이

2

문제

풀이

코드

def answer(arr):
_sum = sum(arr)
ans = []
for i in range(len(arr)-1):
for j in range((i+1), len(arr)):
if _sum - (arr[i]+arr[j]) == 100:
for k in range(len(arr)):
if k not in [i,j]: ans.append(arr[k])
ans = sorted(ans)
for i in range(len(ans)): print(ans[i])
return
arr = []
for _ in range(9): arr.append(int(input()))
answer(arr)

14888번 – 연산자끼워넣기

1

문제 풀이 코드 from itertools import permutations from math import ceil def divide(a, b): if a < 0 and b > 0: return -1*((a*-1)//b) return a//b def answer(): global n, nums, operations PLUS, MINUS, MULTIPLE, DIVIDE = (1, 2, 3, 4) opArr = [] for i in range(len(operations)): if operations[i] > 0: opArr = opArr + [(i+1) for _ in range(operations[i])] perms = list(permutations(opArr, len(opArr)))...

17406번 – 배열돌리기4

1

문제 풀이 코드 from collections import deque from copy import deepcopy from itertools import permutations import math def minSum(matrix): return min([sum(matrix[i]) for i in range(len(matrix))]) def getCoords(matrix, r, c, s): dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)] start, sideLength, count, idx = ((r-s, c-s), s*2, 0, 0) coords = [] while(idx != len(dirs)): coords.append(start) count += 1 start =...

1748번 – 수 이어 쓰기 1

1

문제

풀이

코드

def answer():
global n
i, ans = (1, 0)
while(i < len(str(n))+1):
if n >= 10**i:
ans += i*(((10**i)-1) - 10**(i-1) + 1)
else:
ans += i*(n - 10**(i-1) + 1)
i += 1
print(ans)

n = int(input())
answer()

1476번 – 날짜 계산

1

문제

풀이

코드

def check(esm, target):
return bool(esm[0] == target[0] and esm[1] == target[1] and esm[2] == target[2])

def answer():
global target, limits
ans, esm = (1, [1, 1, 1])
while(check(esm, target) is False):
ans += 1
for i in range(3):
esm[i] = esm[i] + 1
if esm[i] > limits[i]: esm[i] = 1
print(ans)

target = list(map(int, input().split()))
limits = [15, 28, 19]
answer()