ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [๋ฐฑ์ค€] 20546 ๐Ÿœ ๊ธฐ์ ์˜ ๋งค๋งค๋ฒ• ๐Ÿœ with Python
    PS 2021. 12. 18. 20:01
    728x90
    ๋ฐ˜์‘ํ˜•

    ๐Ÿ“Œ BOJ 20546 ๐Ÿœ ๊ธฐ์ ์˜ ๋งค๋งค๋ฒ• ๐Ÿœ

    ๐Ÿ’ก ์กฐ๊ฑด

    1. ๋ชจ๋“  ๊ฑฐ๋ž˜๋Š” ์ „๋Ÿ‰ ๋งค์ˆ˜์™€ ์ „๋Ÿ‰ ๋งค๋„๋กœ ์ด๋ฃจ์–ด์ง„๋‹ค.

      • ํ˜„์žฌ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํ˜„๊ธˆ์ด 100์›์ด๊ณ  ์ฃผ๊ฐ€๊ฐ€ 11์›์ด๋ผ๋ฉด 99์›์–ด์น˜์˜ ์ฃผ์‹์„ ๋งค์ˆ˜ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.
      • ๋‹จ, ํ˜„๊ธˆ์ด 100์› ์žˆ๊ณ  ์ฃผ๊ฐ€๊ฐ€ 101์›์ด๋ผ๋ฉด ์ฃผ์‹์„ ์‚ด ์ˆ˜ ์—†๋‹ค.
      • ์„ฑ๋ฏผ์ด๋Š” ๋นš์„ ๋‚ด์„œ ์ฃผ์‹์„ ํ•˜์ง€๋Š” ์•Š๋Š”๋‹ค.
    2. 3์ผ ์—ฐ์† ๊ฐ€๊ฒฉ์ด ์ „์ผ ๋Œ€๋น„ ์ƒ์Šนํ•˜๋Š” ์ฃผ์‹์€ ๋‹ค์Œ๋‚  ๋ฌด์กฐ๊ฑด ๊ฐ€๊ฒฉ์ด ํ•˜๋ฝํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•œ๋‹ค.

      • ๋”ฐ๋ผ์„œ ํ˜„์žฌ ์†Œ์œ ํ•œ ์ฃผ์‹์˜ ๊ฐ€๊ฒฉ์ด 3์ผ์งธ ์ƒ์Šนํ•œ๋‹ค๋ฉด, ์ „๋Ÿ‰ ๋งค๋„ํ•œ๋‹ค.
      • ์ „์ผ๊ณผ ์˜ค๋Š˜์˜ ์ฃผ๊ฐ€๊ฐ€ ๋™์ผํ•˜๋‹ค๋ฉด ๊ฐ€๊ฒฉ์ด ์ƒ์Šนํ•œ ๊ฒƒ์ด ์•„๋‹ˆ๋‹ค.
    3. 3์ผ ์—ฐ์† ๊ฐ€๊ฒฉ์ด ์ „์ผ ๋Œ€๋น„ ํ•˜๋ฝํ•˜๋Š” ์ฃผ์‹์€ ๋‹ค์Œ๋‚  ๋ฌด์กฐ๊ฑด ๊ฐ€๊ฒฉ์ด ์ƒ์Šนํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•œ๋‹ค.

      • ๋”ฐ๋ผ์„œ ์ด๋Ÿฌํ•œ ๊ฒฝํ–ฅ์ด ๋‚˜ํƒ€๋‚˜๋ฉด ์ฆ‰์‹œ ์ฃผ์‹์„ ์ „๋Ÿ‰ ๋งค์ˆ˜ํ•œ๋‹ค.
      • ์ „์ผ๊ณผ ์˜ค๋Š˜์˜ ์ฃผ๊ฐ€๊ฐ€ ๋™์ผํ•˜๋‹ค๋ฉด ๊ฐ€๊ฒฉ์ด ํ•˜๋ฝํ•œ ๊ฒƒ์ด ์•„๋‹ˆ๋‹ค.
    4. 1์›” 14์ผ์˜ ์ž์‚ฐ์€ (ํ˜„๊ธˆ + 1์›” 14์ผ์˜ ์ฃผ๊ฐ€ ร— ์ฃผ์‹ ์ˆ˜)๋กœ ๊ณ„์‚ฐํ•œ๋‹ค.

    5. 1์›” 14์ผ ๊ธฐ์ค€ ์ค€ํ˜„์ด์˜ ์ž์‚ฐ์ด ๋” ํฌ๋‹ค๋ฉด "BNP"๋ฅผ, ์„ฑ๋ฏผ์ด์˜ ์ž์‚ฐ์ด ๋” ํฌ๋‹ค๋ฉด "TIMING"์„ ์ถœ๋ ฅํ•œ๋‹ค.

    6. Stack, ์ž๋ฃŒ๊ตฌ์กฐ ์œ ํ˜•์˜ ๋ฌธ์ œ

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

    from sys import stdin
    
    m = int(stdin.readline())
    arr = list(map(int, stdin.readline().split()))
    jm, sm, j, s, status = m, m, 0, 0, [0, '']
    yesterday = arr[0]
    
    
    for i in range(14):
        # ์ค€ํ˜„
        if jm // arr[i] != 0:
            temp = jm // arr[i]
            j += (jm // arr[i])
            jm -= temp * arr[i]
    
        # ์„ฑ๋ฏผ
        change = 0
        if yesterday < arr[i]:
            if status[1] == '-':
                change = 1
            status[1] = '+'
    
        elif yesterday > arr[i]:
            if status[1] == '+':
                change = 1
            status[1] = '-'
    
        yesterday = arr[i]
    
        if change:
            status[0] = 1
        elif status[1] != '':
            status[0] += 1
    
        if status[0] >= 3:
            if status[1] == '+':
                if sm // arr[i] != 0:
                    sm += s * arr[i]
                    s = 0
    
            if status[1] == '-':
                temp = sm // arr[i]
                s += (sm // arr[i])
                sm -= temp * arr[i]
    
    
    last_day = arr[-1]
    sm += (s * last_day)
    jm += (j * last_day)
    
    if sm == jm:
        print("SAMESAME")
    elif sm > jm:
        print("TIMING")
    else:
        print("BNP")

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

    ์˜ˆ์ œ

    100
    10 20 23 34 55 30 22 19 12 45 23 44 34 38

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

    BNP

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

    1. ๋ฌธ์ œ์—์„œ ์š”๊ตฌํ•œ 33 ๋งค๋งค๋ฒ•์˜ ์„ธ๊ฐ€์ง€ ๋ฃฐ์„ ๋จผ์ € ์ •๋ฆฌํ•˜๊ณ  ๊ตฌํ˜„์„ ํ•˜๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค.

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

    1. ๋‹จ์ˆœํ•œ ๊ตฌํ˜„๋ฌธ์ œ์˜€๋‹ค.
    2. ๋ฌธ์ œ๋ฅผ ์ž˜ ์ฝ๊ณ  ๋ฌธ์ œ๋ฅผ ์••์ถ•ํ•˜๊ณ  ์ •๋ฆฌํ•˜๋Š” ์—ฐ์Šต์ด ํ•„์š”ํ•˜๊ฒ ๋‹ค.
    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.