강의

멘토링

커뮤니티

Inflearn Community Q&A

sskj46353791's profile image
sskj46353791

asked

Introduction to Python Algorithm Problem Solving (Coding Test Preparation)

10. Stoku Test

스토쿠 검사

Written on

·

425

0

이렇게 풀어도 정답 다 통과되던데 반례가 있을까요 ?

import sys 
import string as t 

sys.stdin = open("input.txt", "r")

a = [list(map(int, input().split())) for _ in range(9)]
True_flag = True 
nums = [i for i in range(1, 10)]
for y in range(0, 9, 3):
    for x in range(0, 9, 3):
        res = []
        res.extend(a[y : y + 3][0][x : x + 3])
        res.extend(a[y : y + 3][1][x : x + 3])
        res.extend(a[y : y + 3][2][x : x + 3])
        
        if len(nums) != len(set(res)):
            True_flag = False
            break 
    
if True_flag:
    print("YES")
else:
    print("NO")
python코딩-테스트

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

행과 열을 확인하지 않는 코드인것 같네요. 아래와 같은 입력은 NO인데 위 코드는 YES가 나오게 됩니다.

1 2 3 1 2 3 1 2 3
4 5 6 4 5 6 4 5 6
7 8 9 7 8 9 7 8 9
1 2 3 1 2 3 1 2 3
4 5 6 4 5 6 4 5 6
7 8 9 7 8 9 7 8 9
1 2 3 1 2 3 1 2 3
4 5 6 4 5 6 4 5 6
7 8 9 7 8 9 7 8 9
sskj46353791's profile image
sskj46353791

asked

Ask a question