Post

๐ŸฆŠ ๊ฑฐ๋ฆฌ๋‘๊ธฐ ํ™•์ธํ•˜๊ธฐ

1. ๋ฌธ์ œ ๋งํฌ

๊ฑฐ๋ฆฌ๋‘๊ธฐ ํ™•์ธํ•˜๊ธฐ


2. ์ฝ”๋“œ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def solution(places):            
    answer = []
    
    for MAP in places:
        persons = []
        
        for i in range(5):
            for j in range(5):
                if MAP[i][j] == 'P':
                    persons.append((i, j))
        answer.append(check(MAP, persons))
    return answer

def check(MAP, persons):    
    for i in range(len(persons) - 1):
        x1, y1 = persons[i]
        for j in range(i + 1, len(persons)):
            x2, y2 = persons[j]
            
            diff_x = abs(x1 - x2)
            diff_y = abs(y1 - y2)
            dist = diff_x + diff_y
            # ๋ถ™์–ด์žˆ์œผ๋ฉด ๊ฑฐ๋ฆฌ๋‘๊ธฐ ์•ˆ์ง€ํ‚ด
            if dist < 2:
                return 0

            if dist == 2:
                # ๊ฐ€๋กœ๋กœ ์ •๋ ฌ
                if diff_x == 2 and MAP[min(x1, x2) + 1][y1] != 'X':
                    return 0
                # ์„ธ๋กœ๋กœ ์ •๋ ฌ
                elif diff_y == 2 and MAP[x1][min(y1, y2) + 1] != 'X':
                    return 0
                # ๋Œ€๊ฐ์„ ์œผ๋กœ
                elif MAP[x1][y2] == 'O' or MAP[x2][y1] == 'O':
                    return 0
    return 1
  • ์‹คํ–‰ ๊ฒฐ๊ณผ

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    
      ์ฑ„์ ์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.
      ์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
      ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.10ms, 10.1MB)
      ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.1MB)
      ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (0.07ms, 10.1MB)
      ํ…Œ์ŠคํŠธ 21 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.1MB)
      ํ…Œ์ŠคํŠธ 24 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 25 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 26 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 27 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 28 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.1MB)
      ํ…Œ์ŠคํŠธ 29 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 30 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 31 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.2MB)
      ์ฑ„์  ๊ฒฐ๊ณผ
      ์ •ํ™•์„ฑ: 100.0
      ํ•ฉ๊ณ„: 100.0 / 100.0
    


3. ํ•ด์„ค

  • ํ•ด์„ค

    ๋งจํ•ดํŠผ ๊ฑฐ๋ฆฌ๊ฐ€ 2 ๋ฏธ๋งŒ์ผ ๊ฒฝ์šฐ ๋”ฑ ๋ถ™์–ด ์žˆ๋Š” ๊ฒƒ์œผ๋กœ ๊ฑฐ๋ฆฌ๋‘๊ธฐ๋ฅผ ์ง€ํ‚ค์ง€ ์•Š์Œ

    ๋งจํ•ดํŠผ ๊ฑฐ๋ฆฌ๊ฐ€ 2์ผ ๊ฒฝ์šฐ ํ•œ์ค„์— ์žˆ์„ ๊ฒฝ์šฐ ํŒŒํ‹ฐ์…˜์ด 1๊ฐœ,

    ๋Œ€๊ฐ์„ ์ผ ๊ฒฝ์šฐ ํŒŒํ‹ฐ์…˜์ด 2๊ฐœ๊ฐ€ ์žˆ์–ด์•ผํ•จ

    ๊ทธ๊ฒƒ์„ ๊ฒ€์‚ฌ

This post is licensed under CC BY 4.0 by the author.