๐๋ฌธ์ :
๐ํ์ด:
๋ฌธ์ ๋ฅผ ๋๋ฌด ์ด๋ ต๊ฒ ์๊ฐํ๊ณ ๋ค๋ฅธ ๋ฐฉํฅ์ผ๋ก ํ๋ค ๋ณด๋ ์๊ฐ์ด ๋๋ฌด ์ค๋ ์์๋์๋ค. (1์๊ฐ ๋ฐ..)
๊ฒฐ๊ตญ ๊ตฌ๊ธ๋ง์ ํ์ฌ ๋ค๋ฅธ ์ฌ๋์ ์ฝ๋๋ฅผ ์ฐธ๊ณ ํจ.
๊ธฐ์กด์ ์ฝ๋๋ฅผ ์ง ๋ฐฉ์์ ์๋์ ๊ฐ๋ค.
๋ธ๋ฃจํธํฌ์ค ๋ฐฉ์์ผ๋ก ์ง๋ ค๊ณ ์๋ํ์ผ๋, ๊ฒฐ๊ณผ์ ๋ง๊ฒ ์ฝ๋๋ฅผ ์์ฑํด ๊ฒฝ์ฐ์ ์๋ฅผ ์ขํ๋๊ฐ๋ ค๋ค ๋ณด๋๊น ์์ ํ๋ ์ฝ๋ฉ์ด ๋์ด ๋ฒ๋ ธ๋ค..
์ด๋ป๊ฒ ์ฝ๋๋ฅผ ๊ฐ์ํ ์ํฌ ์ ์์์ง, ๋ฐ๋ณต๋๋ ๋ถ๋ถ์ ์ค์ผ ์ ์์์ง๋ฅผ ๋ง์ด ๊ณ ๋ฏผํด์ผ ํ ๊ฒ ๊ฐ๋ค.
'''
https://www.acmicpc.net/problem/2503
๋ฌธ์ : ์ซ์ ์ผ๊ตฌ
๋์ด๋: ์ค๋ฒ3
'''
answer_box = []
# ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ์ฐ์ ์
for i in range(1, 10):
for j in range(1, 10):
for k in range(1, 10):
if i != j and j != k and i != k:
answer_box.append(str(i*100 + j *10 + k))
three_strike = False
testCase = int(input())
for _ in range(testCase):
num, s, b = map(str, input().split())
this_case_box = []
if s == '3': # 3์คํธ๋ผ์ดํฌ: ์ ๋ต์ด ํ๋๋ก ํ์ ๋จ
answer_box = [num]
break
elif s == '2': # 2์คํธ๋ผ์ดํฌ
for i in range(1, 10):
if num[0] != str(i):
this_case_box.append(str(i)+num[1]+num[2])
if num[1] != str(i):
this_case_box.append(num[0]+str(i)+num[2])
if num[2] != str(i):
this_case_box.append(num[0]+num[1]+str(i))
elif s == '1': # 1์คํธ๋ผ์ดํฌ
# 1์คํธ๋ผ์ดํฌ & 2๋ณผ
if b == '2':
this_case_box.append(num[0]+num[2]+num[1])
this_case_box.append(num[2]+num[1]+num[0])
this_case_box.append(num[1]+num[0]+num[2])
# 1์คํธ๋ผ์ดํฌ & 1๋ณผ
elif b == '1':
for i in range(1, 10):
this_case_box.append(num[0]+num[2]+str(i))
this_case_box.append(num[0]+str(i)+num[1])
this_case_box.append(str(i)+num[1]+num[0])
this_case_box.append(num[2]+num[1]+str(i))
this_case_box.append(str(i)+num[0]+num[2])
this_case_box.append(num[1]+str(i)+num[2])
# 1์คํธ๋ผ์ดํฌ & 0๋ณผ
elif b == '0':
for i in range(1, 10):
for j in range(1, 10):
if str(i) != num[1] or str(j) != num[2] or str(i) != num[2] or str(j) != num[1]:
this_case_box.append(num[0]+str(i)+str(j))
if str(i) != num[0] or str(j) != num[2] or str(i) != num[2] or str(j) != num[0]:
this_case_box.append(str(i)+num[1]+str(j))
if str(i) != num[0] or str(j) != num[1]:
this_case_box.append(str(i)+str(j)+num[2])
elif s == '0': # 0์คํธ๋ผ์ดํฌ
# 0์คํธ๋ผ์ดํฌ & 3๋ณผ
if b == '3':
this_case_box.append(num[1]+num[2]+num[0])
this_case_box.append(num[2]+num[0]+num[1])
# 0์คํธ๋ผ์ดํฌ & 2๋ณผ
if b == '2':
for i in range(1, 10):
this_case_box.append(str(i)+num[0]+num[1])
this_case_box.append(str(i)+num[2]+num[0])
this_case_box.append(str(i)+num[2]+num[1])
this_case_box.append(num[1]+str(i)+num[0])
this_case_box.append(num[2]+str(i)+num[0])
this_case_box.append(num[1]+num[0]+str(i))
this_case_box.append(num[1]+num[2]+str(i))
this_case_box.append(num[2]+num[0]+str(i))
# 0์คํธ๋ผ์ดํฌ & 1๋ณผ
if b == '1':
for i in range(1, 10):
for j in range(1, 10):
if str(i) != num[1] or str(j) != num[2] or str(i) != num[2] or str(j) != num[1]:
this_case_box.append(str(i)+num[0]+str(j))
if str(i) != num[1] or str(j) != num[2] or str(i) != num[2] or str(j) != num[1]:
this_case_box.append(str(i)+str(j)+num[0])
if str(i) != num[0] or str(j) != num[2] or str(i) != num[2] or str(j) != num[0]:
this_case_box.append(num[1]+str(i)+str(j))
if str(i) != num[0] or str(j) != num[2] or str(i) != num[2] or str(j) != num[0]:
this_case_box.append(str(i)+str(j)+num[1])
if str(i) != num[0] or str(j) != num[1] or str(i) != num[1] or str(j) != num[0]:
this_case_box.append(num[2]+str(i)+str(j))
if str(i) != num[0] or str(j) != num[1] or str(i) != num[1] or str(j) != num[0]:
this_case_box.append(str(i)+num[2]+str(j))
# 0์คํธ๋ผ์ดํฌ & 0๋ณผ
if b == '0':
for i in range(1, 10):
for j in range(1, 10):
for k in range(1, 10):
if i != num[0] or i != num[1] or i != num[2] or j != num[0] or j != num[1] or j != num[2] or k != num[0] or k != num[1] or k != num[2]:
this_case_box.append(str(i)+str(j)+str(k))
answer_box = list(set(answer_box) & set(this_case_box))
print(answer_box)
print(len(answer_box))
โ๏ธ์ ๋ต ์ฝ๋:
'''
https://www.acmicpc.net/problem/2503
๋ฌธ์ : ์ซ์ ์ผ๊ตฌ
๋์ด๋: ์ค๋ฒ3
'''
import sys
from itertools import permutations
input = sys.stdin.readline
n = int(input())
nums = list(permutations(list(range(1, 10)), 3)) # 1๋ถํฐ 9๊น์ง์ ์๋ก ๋ค๋ฅธ 3์๋ฆฌ ์ซ์ ๋ชจ์
for _ in range(n):
num, s, b = map(int, input().split())
tmp = [] # ํ์ฌ ์กฐ๊ฑด์ ๋ง๋ ์ซ์๊ฐ ๋ค์ด๊ฐ ๋ฐฐ์ด
for check in nums: # 3์๋ฆฌ ์ซ์ ๋ชจ์ ํ์
cnt_s, cnt_b = 0, 0 # ์คํธ๋ผ์ดํฌ์ ๋ณผ์ ๊ฐฏ์
for i, str_num in enumerate(str(num)): # ์
๋ ฅํ ์ซ์๋ฅผ ๋ฌธ์์ด๋ก ๋ฐ๊พธ์ด ์ซ์์ ์์น์ ๊ฐ์ ํ ๋ฒ์ ํ์ธ
if int(str_num) == check[i]: # ํ์ฌ ํ์์ค์ธ ์ซ์์ ์
๋ ฅํ ์ซ์ ์ค ์์น์ ๊ฐ์ด ๊ฐ์ ์๊ฐ ์๋ค๋ฉด
cnt_s += 1 # ์คํธ๋ผ์ดํฌ ๊ฐฏ์ ์ฆ๊ฐ
if int(str_num) != check[i] and int(str_num) in check: # ์์น๋ ๋ค๋ฅด๋ ์ซ์๊ฐ ํฌํจ๋์ด ์๋ค๋ฉด
cnt_b += 1 # ๋ณผ ๊ฐฏ์ ์ฆ๊ฐ
if s == cnt_s and b == cnt_b: # ์คํธ๋ผ์ดํฌ์ ๋ณผ์ ๊ฐฏ์๊ฐ ์
๋ ฅ๊ฐ๊ณผ ๊ฐ๋ค๋ฉด
tmp.append(check) # tmp์ ํ์ฌ ์ซ์ ์ถ๊ฐ
nums = tmp # ๊ธฐ์กด 3์๋ฆฌ ์ซ์์ ๋ชจ์์ ํ์ฌ๊น์ง์ ์กฐ๊ฑด์ ๋ง์ถฐ ์ต์ ํ
print(len(nums)) # ์ต์ข
์กฐ๊ฑด์ ๋ง๋ ์๋ค์ ๊ธธ์ด ์ถ๋ ฅ
๐๋งํฌ:
'๐งฉps > ๐ฅHard' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค 18115๋ฒ] ์นด๋ ๋๊ธฐ (0) | 2024.09.30 |
---|