본문 바로가기
Problem Solving/BOJ

[BOJ][Python]4482번 풀이

by NoiB 2022. 5. 20.
반응형

이번에도 문제 자체는 그렇게 어렵지 않습니다. 문제가 무슨 말인가 조금 고민했지만 약간 애매할 때는 입력과 출력을 같이 보면서 하면 좀 쉽게 느껴지기 때문에 항상 입출력을 같이 확인하는 버릇을 들이시면 시간 낭비를 좀 줄이실 수 있을겁니다.

https://www.acmicpc.net/problem/4482

 

4482번: Tetrahedral Stacks of Cannonballs

For each problem, output the problem number (starting from 1), a colon and a blank, the number of cannonballs on each side of the base, one blank, and finally the total number of cannonballs in the tetrahedron.

www.acmicpc.net

t = int(input())
sub = [0 for _ in range(1000)]
sub1 = [0 for _ in range(1000)]
for i in range(1,1000):
    sub[i] = sub[i-1]+i
    sub1[i] = sub1[i-1]+sub[i]
for i in range(t):
    n = int(input())
    print(f'{i+1}: {n} {sub1[n]}')
    
#1,3,6,10,15,21
#1,4,10,20,35

아마 굳이 저처럼 리스트를 두 개 만들지 않고도 점화식을 세울 수 있을 것 같다는 느낌이 드는데요. 저는 바로 들었던 생각이 이거였기 때문에 이렇게 풀어봤습니다. 식을 세우신다면 메모리 관점에서 조금 이득을 볼 수 있겠죠.

반응형

'Problem Solving > BOJ' 카테고리의 다른 글

[BOJ][Python]23972번 풀이  (0) 2022.05.21
[BOJ][Python]2748번 풀이  (0) 2022.05.21
[BOJ][Python]9095번 풀이  (0) 2022.05.19
[BOJ][Python]15841번 풀이  (0) 2022.05.18