아이공의 AI 공부 도전기

[Baekjoon] 13458번 : 시험 감독 (Python, 사칙연산)

 

     

 

 

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

 

13458번: 시험 감독

첫째 줄에 시험장의 개수 N(1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 각 시험장에 있는 응시자의 수 Ai (1 ≤ Ai ≤ 1,000,000)가 주어진다. 셋째 줄에는 B와 C가 주어진다. (1 ≤ B, C ≤ 1,000,000)

www.acmicpc.net

 

코드 링크

https://github.com/stellaluminary/Baekjoon

 

GitHub - stellaluminary/Baekjoon

Contribute to stellaluminary/Baekjoon development by creating an account on GitHub.

github.com

 

Python

 

방법 1 - 메모리 151548KB / 시간 684ms / 코드 길이 213B

 

import math
n = int(input())
arr = list(map(int, input().split()))
b,c = map(int,input().split())
cnt = 0
for a in arr:
    if a - b > 0:
        cnt += 1 + math.ceil((a-b)/c)
    else:
        cnt += 1
print(cnt)

 

방법 2 - 메모리 143496KB / 시간 428ms / 코드 길이 326B

 

from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
b,c = map(int,input().split())
cnt = 0

counts = Counter(arr)
for k, v in counts.items():
    p = 1
    k -= b
    if k > 0:
        div, mod = divmod(k, c)
        p += div
        if mod > 0:
            p += 1
    cnt += p*v

print(cnt)

 

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading