ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [๋ฐฑ์ค€] 1531 ํˆฌ๋ช… with Python
    PS 2022. 3. 12. 02:20
    728x90
    ๋ฐ˜์‘ํ˜•

    ๐Ÿ“Œ BOJ 1531 ํˆฌ๋ช…

    ๐Ÿ’ก ์กฐ๊ฑด

    1. ์„ธ์ค€์ด๋Š” 1ร—1ํฌ๊ธฐ์˜ ๊ทธ๋ฆผ์œผ๋กœ ๋ชจ์ž์ดํฌํ•œ 100ร—100ํฌ๊ธฐ์˜ ๊ทธ๋ฆผ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.
    2. ์–ด๋Š ๋‚  ์ด ๋ชจ์ž์ดํฌ ์ค‘ ์ผ๋ถ€ ๊ทธ๋ฆผ์ด ๋„ˆ๋ฌด ๋ณด๊ธฐ ์‹ซ์–ด์„œ N๊ฐœ์˜ ๋ถˆํˆฌ๋ช…ํ•œ ์ข…์ด๋กœ ๊ทธ๋ฆผ์„ ๊ฐ€๋ฆฌ๊ธฐ ์‹œ์ž‘ํ–ˆ๋‹ค.
    3. ๊ทธ๋ฆผ์˜ ํ˜„์žฌ ๋ถ€๋ถ„ ์œ„์— M๊ฐœ ์ดํ•˜์˜ ์ข…์ด๊ฐ€ ์˜ฌ๋ ค์ ธ ์žˆ์œผ๋ฉด ๊ทธ๋ฆผ์€ ๊ทธ ๋ถ€๋ถ„์—์„œ ๋ณด์ด๊ฒŒ ๋œ๋‹ค.
    4. N์€ 0๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. M์€ 0๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค.
    5. ์™ผ์ชฝ ์•„๋ž˜ ๋ชจ์„œ๋ฆฌ์˜ x, y์ขŒํ‘œ, ์˜ค๋ฅธ์ชฝ ์œ„ ๋ชจ์„œ๋ฆฌ์˜ x, y์ขŒํ‘œ ์ˆœ์œผ๋กœ ์ฃผ์–ด์ง„๋‹ค.
      ๋ชจ๋“  ์ขŒํ‘œ๋Š” 100๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค.
    6. ์‹œ๋ฎฌ๋ ˆ์ด์…˜, ๊ตฌํ˜„

    ๐Ÿ–ฅ ์†Œ์Šค ์ฝ”๋“œ

    from sys import stdin
    
    board = [[False] * 101 for _ in range(101)]
    n, m = map(int, stdin.readline().split())
    
    for _ in range(n):
        x1, y1, x2, y2 = map(int, stdin.readline().split())
    
        for i in range(x1, x2 + 1):
            for j in range(y1, y2 + 1):
                if board[i][j] is False:
                    board[i][j] = 1
                else:
                    board[i][j] += 1
    
    res = 0
    for i in range(1, 101):
        for j in range(1, 101):
            if board[i][j] > m:
                res += 1
    
    print(res)

    ๐Ÿ”– ์˜ˆ์ œ ๋ฐ ์‹คํ–‰๊ฒฐ๊ณผ

    ์˜ˆ์ œ

    3 1
    21 21 80 80
    41 41 60 60
    71 71 90 90

    ์‹คํ–‰๊ฒฐ๊ณผ

    500

    โŒจ๏ธ ๋ฌธ์ œ ํ’€์ด

    1. N๊ฐœ์˜ ๋ถˆํˆฌ๋ช…ํ•œ ์ข…์ด์˜ ์ขŒํ‘œ๋ฅผ ๋ฐ›์•„์„œ x1๋ถ€ํ„ฐ x2๊นŒ์ง€, y1๋ถ€ํ„ฐ y2๊นŒ์ง€ ์ˆœํšŒํ•œ๋‹ค.
    2. ์ˆœํšŒํ•˜๋ฉด์„œ ํ•ด๋‹นํ•˜๋Š” ์ธ๋ฑ์Šค์— ํ•ด๋‹นํ•˜๋Š” ๋ฐฐ์—ด์˜ ๊ฐ’์ด False๋ผ๋ฉด 1๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค.
    3. ์ˆœํšŒํ•˜๋ฉด์„œ ํ•ด๋‹นํ•˜๋Š” ์ธ๋ฑ์Šค์— ํ•ด๋‹นํ•˜๋Š” ๋ฐฐ์—ด์˜ ๊ฐ’์ด False๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด + 1 ํ•ด์ค€๋‹ค.
    4. 100 * 100 ํฌ๊ธฐ์˜ ์ขŒํ‘œ๋ฅผ ์ˆœํšŒํ•˜๋ฉด์„œ m ์ด์ƒ์˜ ํฌ๊ธฐ๊ฐ€ ์žˆ๋‹ค๋ฉด res + 1 ํ•ด์ค€๋‹ค.

    ๐Ÿ’พ ๋Š๋‚€์ 

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.