1. Problem
2. Others' Solutions
import sys
import math
tetrominos = [
[(0,0),(0,1),(0,2),(0,3)], # ㅡ
[(0,0),(1,0),(2,0),(3,0)], # ㅣ
[(0,0),(1,0),(0,1),(1,1)], # ㅁ
[(0,0),(1,0),(2,0),(2,1)], # ㄴ
[(1,0),(1,1),(1,2),(0,2)],
[(0,0),(0,1),(1,1),(2,1)],
[(0,0),(0,1),(0,2),(1,0)],
[(2,0),(2,1),(1,1),(0,1)],
[(0,0),(0,1),(0,2),(1,2)],
[(0,0),(0,1),(1,0),(2,0)],
[(0,0),(1,0),(1,1),(1,2)],
[(0,0),(1,0),(1,1),(2,1)], # ㄴㄱ
[(1,0),(1,1),(0,1),(0,2)],
[(0,1),(2,0),(1,1),(1,0)],
[(0,0),(0,1),(1,1),(1,2)],
[(0,1),(1,0),(1,1),(1,2)], # ㅗ
[(1,0),(0,1),(1,1),(2,1)],
[(0,0),(0,1),(0,2),(1,1)],
[(0,0),(1,0),(1,1),(2,0)]]
n,m = map(int, sys.stdin.readline().rstrip().split())
board = []
result = 0
for _ in range(n):
board.append(list(map(int,sys.stdin.readline().rstrip().split())))
for i in range(n): # 열 이동
for j in range(m): # 행 이동
for tetromino in tetrominos: # 19개의 테트로미노에서 하나씩 선택
temp = 0
for dx,dy in tetromino: # 기준 좌표 board[i][j]에서 테트로미노에 맞게 dx,dy 좌표 더해줌
ix = i + dx
jy = j + dy
if 0 <= ix < n and 0 <= jy < m:
temp += board[ix][jy]
else: # 범위를 넘어가면 result 로 채택될 수 없도록 -inf 값 지정
temp = -(math.inf)
break
if result < temp: # 테트로미노 하나씩 마다 result 갱신가능 여부 판단
result = temp
print(result)
3. Learned
1. Problem
2. My Solution
import sys
n = sys.stdin.readline().rstrip()
count = [0,9,180,2700,36000,450000,5400000,63000000,720000000]
res = 0
if len(n) == 1:
print(n)
else:
for i in range(1,len(n)):
res += count[i]
res += (int(n) - int('9' * (len(n) - 1))) * len(n)
print(res)
3. Others' Solutions
import sys
n = sys.stdin.readline().rstrip()
res = 0
for i in range(len(n)-1):
res += 9 * (10 ** i) * (i+1)
print(res + ((int(n) - (10 ** (len(n)-1)) + 1) * len(n)))
4. Learned
1. Problem
2. My Solution
import sys
def permutation(level):
if level >= m:
res.append(arr)
else:
for i in range(1, n+1):
if visited[i] == True:
continue
else:
arr[level] = i
visited[i] = True
permutation(level+1)
visited[i] = False
n, m = map(int,sys.stdin.readline().rstrip().split())
visited = [False] * (n+1)
arr = [0] * m
res = []
permutation(0)
for i in res:
print(' '.join(map(str,i)))
import sys
def permutation(level):
if level >= m:
res.append(arr.copy())
else:
for i in range(1, n+1):
if visited[i] == True:
continue
else:
arr[level] = i
visited[i] = True
permutation(level+1)
visited[i] = False
n, m = map(int,sys.stdin.readline().rstrip().split())
visited = [False] * (n+1)
arr = [0] * m
res = []
permutation(0)
for i in res:
print(' '.join(map(str,i)))
3. Others' Solutions
4. Learned