โ๋ฌธ์
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV15JEKKAM8CFAYD
SW Expert Academy
SW ํ๋ก๊ทธ๋๋ฐ ์ญ๋ ๊ฐํ์ ๋์์ด ๋๋ ๋ค์ํ ํ์ต ์ปจํ ์ธ ๋ฅผ ํ์ธํ์ธ์!
swexpertacademy.com
๋ฉ๋ชจ๋ฆฌ: 67,840 KB, ์๊ฐ: 298 ms
โ๐ปํ์ด
https://edder773.tistory.com/47
[SWEA 1242] ์ํธ์ฝ๋ ์ค์บ (python)
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV15JEKKAM8CFAYD SW Expert Academy SW ํ๋ก๊ทธ๋๋ฐ ์ญ๋ ๊ฐํ์ ๋์์ด ๋๋ ๋ค์ํ ํ์ต ์ปจํ ์ธ ๋ฅผ ํ์ธํ์ธ์! swexpertacademy.com ์ํธ์ฝ๋ ์ค์บ ๋ฌธ
edder773.tistory.com
์ ์ฌ์ดํธ๋ฅผ ์ฐธ๊ณ ํ์ฌ ํ์๋ค.
๐ป์ฝ๋
T = int(input())
num = {(2, 1, 1): 0, (2, 2, 1): 1, (1, 2, 2): 2, (4, 1, 1): 3, (1, 3, 2): 4,
(2, 3, 1): 5, (1, 1, 4): 6, (3, 1, 2): 7, (2, 1, 3): 8, (1, 1, 2): 9}
for tc in range(1, T + 1):
N, M = map(int, input().split())
codes = list(set([input() for _ in range(N)])) # ์ค๋ณต๋๋ ๋ฐฐ์ด ์ ๊ฑฐ
ans = 0
encoded = []
for code in codes:
decoded = format(int(code, 16), 'b').lstrip('0') # 1. 16์ง์ -> 2์ง์ ๋ณํ
p1, p2, p3 = 0, 0, 0
odd, even, cnt = 0, 0, 0
temp = ''
for c in decoded:
# 2. ๋น์จ์ ๋ง๋ ๋ฒํธ ์ฐพ๊ธฐ
if c == '1' and p2 == 0 and p3 == 0:
p1 += 1
elif c == '0' and p1 > 0 and p3 == 0:
p2 += 1
elif c == '1' and p1 > 0 and p2 > 0:
p3 += 1
elif p3 > 0:
r = min(p1, p2, p3)
new = num[(p1 // r, p2 // r, p3 // r)]
temp += str(new)
cnt += 1
# 3. ์ฝ๋ ์ ์ ์ฌ๋ถ
if cnt == 8:
if (odd * 3 + even + new) % 10 == 0 and temp not in encoded:
ans += odd + even + new
encoded.append(temp)
odd = even = cnt = 0
temp = ''
else:
if cnt % 2:
odd += new
else:
even += new
p1 = p2 = p3 = 0
print(f"#{tc} {ans}")
๐ํ๊ธฐ
์ฝ๋๊ฐ ์ ๊ทธ๋ ๊ฒ ๋ณํ๋์ง ์ดํดํ๋ ๊ฒ๋ถํฐ ๋๋ฌด ๋ง์ ์๊ฐ์ด ์์๋๋ค..
'Coding Test > Algorithms' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 14501. ํด์ฌ/Python - Silver3 (1) | 2025.07.23 |
---|---|
[SWEA] 2819. ๊ฒฉ์ํ์ ์ซ์ ์ด์ด๋ถ์ด๊ธฐ/Python - D4 (0) | 2025.07.22 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์ต์์ง์ฌ๊ฐํ/Python - Lv.1 (0) | 2025.07.16 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์ฒด์ก๋ณต/Python - Lv.1 (1) | 2025.07.15 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์์/Python - Lv.2 (0) | 2025.07.14 |