문제 확인하기
2. Solution (Python, memory: 31256KB, time: 52ms)
from itertools import permutations
digits = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
numbers = list(permutations(digits, 3))
num_tests = int(input())
for _ in range(num_tests):
target_num, strikes, balls = map(int, input().split())
target_digits = list(str(target_num))
remove_count = 0
for i in range(len(numbers)):
i -= remove_count
current_number = numbers[i]
current_strikes, current_balls = 0, 0
for j in range(3):
if current_number[j] == target_digits[j]:
current_strikes += 1
elif target_digits[j] in current_number:
current_balls += 1
if (current_strikes != strikes) or (current_balls != balls):
numbers.remove(current_number)
remove_count += 1
print(len(numbers))