[BOJ][๐ŸŸก4][๋ฐฑ์ค€#01027] ๊ณ ์ธต ๊ฑด๋ฌผ

์ž‘์„ฑ:    

์—…๋ฐ์ดํŠธ:

์นดํ…Œ๊ณ ๋ฆฌ:

ํƒœ๊ทธ: , , ,

๋ฌธ์ œ ์ถœ์ฒ˜

BAEKJOON Online Judge #1027


๋ฌธ์ œ

์„ธ์ค€์‹œ์—๋Š” ๊ณ ์ธต ๋นŒ๋”ฉ์ด ๋งŽ๋‹ค. ์„ธ์ค€์‹œ์˜ ์„œ๋ฏผ ๊น€์ง€๋ฏผ์€ ๊ฐ€์žฅ ๋งŽ์€ ๊ณ ์ธต ๋นŒ๋”ฉ์ด ๋ณด์ด๋Š” ๊ณ ์ธต ๋นŒ๋”ฉ์„ ์ฐพ์œผ๋ ค๊ณ  ํ•œ๋‹ค. ๋นŒ๋”ฉ์€ ์ด N๊ฐœ๊ฐ€ ์žˆ๋Š”๋ฐ, ๋นŒ๋”ฉ์€ ์„ ๋ถ„์œผ๋กœ ๋‚˜ํƒ€๋‚ธ๋‹ค. i๋ฒˆ์งธ ๋นŒ๋”ฉ (1๋ถ€ํ„ฐ ์‹œ์ž‘)์€ (i,0)๋ถ€ํ„ฐ (i,๋†’์ด)์˜ ์„ ๋ถ„์œผ๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋‹ค.ย ๊ณ ์ธต ๋นŒ๋”ฉ A์—์„œ ๋‹ค๋ฅธ ๊ณ ์ธต ๋นŒ๋”ฉ B๊ฐ€ ๋ณผ ์ˆ˜ ์žˆ๋Š” ๋นŒ๋”ฉ์ด ๋˜๋ ค๋ฉด, ๋‘ ์ง€๋ถ•์„ ์ž‡๋Š” ์„ ๋ถ„์ด A์™€ B๋ฅผ ์ œ์™ธํ•œ ๋‹ค๋ฅธ ๊ณ ์ธต ๋นŒ๋”ฉ์„ ์ง€๋‚˜๊ฑฐ๋‚˜ ์ ‘ํ•˜์ง€ ์•Š์•„์•ผ ํ•œ๋‹ค.ย ๊ฐ€์žฅ ๋งŽ์€ ๊ณ ์ธต ๋นŒ๋”ฉ์ด ๋ณด์ด๋Š” ๋นŒ๋”ฉ์„ ๊ตฌํ•˜๊ณ , ๊ฑฐ๊ธฐ์„œ ๋ณด์ด๋Š” ๋นŒ๋”ฉ์˜ ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.


์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ๋นŒ๋”ฉ์˜ ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ ์ค„์— 1๋ฒˆ ๋นŒ๋”ฉ๋ถ€ํ„ฐ ๊ทธ ๋†’์ด๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋†’์ด๋Š” 1,000,000,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค.


์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— ๋ฌธ์ œ์˜ ์ •๋‹ต์„ ์ถœ๋ ฅํ•œ๋‹ค.


์˜ˆ์ œ

์˜ˆ์ œ 1

์ž…๋ ฅ

15
1 5 3 2 6 3 2 6 4 2 5 7 3 1 5


์ถœ๋ ฅ

7


์˜ˆ์ œ 2

์ž…๋ ฅ

1
10


์ถœ๋ ฅ

0


์˜ˆ์ œ 3

์ž…๋ ฅ

4
5 5 5 5


์ถœ๋ ฅ

2


์˜ˆ์ œ 4

์ž…๋ ฅ

5
1 2 7 3 2


์ถœ๋ ฅ

4


์˜ˆ์ œ 5

์ž…๋ ฅ

10
1000000000 999999999 999999998 999999997 999999996 1 2 3 4 5


์ถœ๋ ฅ

6


My Sol

def main(std_i):
    ret = 0
    for k in range(1, std_i):
        ret += check(std_i, k)

    for k in range(std_i+1, N+1):
        ret += check(std_i, k)

    return ret

def check(std_i, k):
    dx = std_i - k
    dy = arr[std_i] - arr[k]
    s = dy/dx
    [b, e] = [k+1, std_i] if std_i > k else [std_i+1, k]

    for j in range(b, e):
        std_h = s*j + (arr[k] - s*k)
        if arr[j] >= std_h:
            return 0
    return 1


N = int(input())
arr = [0] + list(map(int, input().split()))
ret = 0
for std_i in range(1, N+1):
    ret = max(ret, main(std_i))

print(ret)

๋ชจ๋“  ๋นŒ๋”ฉ๋“ค์— ๋Œ€ํ•˜์—ฌ ๊ฐ ๋นŒ๋”ฉ์„ ๊ธฐ์ค€์ ์œผ๋กœ ์ขŒ์šฐ์˜ ๋ชจ๋“  ๋นŒ๋”ฉ๋“ค์— ๋Œ€ํ•ด ์˜ฅ์ƒ์„ ์ž‡๋Š” ์ง์„ ์˜ ์‹์„ ๊ตฌํ•˜๊ณ , ๊ทธ ์‚ฌ์ด์— ์ด ์ง์„ ์„ ํ†ต๊ณผํ•˜๊ฑฐ๋‚˜ ์ ‘ํ•˜๋Š” ์ง์„ ์ด ์—†๋‹ค๋ฉด ๋นŒ๋”ฉ์„ ๋ณผ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด๋ฏ€๋กœ ๋งค ๊ฑด๋ฌผ์„ ๊ธฐ์ค€์ ์œผ๋กœ ์žก์„ ๋•Œ๋งˆ๋‹ค ์ตœ๊ณ ์ ์„ ๊ฐฑ์‹ ํ•˜์˜€๋‹ค. ์ดํ›„ ์ตœ๊ณ ์ ์„ ์ถœ๋ ฅํ•ด์ฃผ์—ˆ๋‹ค.


๊ฒฐ๊ณผ

๋งž์•˜์Šต๋‹ˆ๋‹ค!!


๋ชจ๋ฒ”๋‹ต์•ˆ

์ถœ์ฒ˜

from sys import stdin

n = int(stdin.readline())
h = list(map(int, stdin.readline().split()))

able_to_see = [0] * n

for i in range(n):
    inc = -1000000000
    for j in range(i+1, n):
        slope = (h[j] - h[i]) / (j - i)
        if slope > inc:
            inc = slope
            able_to_see[i] +=1
            able_to_see[j] +=1
    
print(max(able_to_see))

์—ฐ์‚ฐ์‹œ๊ฐ„๋„ ์กฐ๊ธˆ ์งง๊ณ  ๊ธธ์ด๊ฐ€ ํš๊ธฐ์ ์œผ๋กœ ์งง์€ ํ’€์ด๊ฐ€ ์žˆ์–ด ๊ฐ€์ ธ์™”๋‹ค. ๊ฐ ๋นŒ๋”ฉ ์ง€์ ์„ ๊ธฐ์ค€์ ์œผ๋กœ ํ•˜์˜€๋Š”๋ฐ, ์ตœ์ดˆ -inf๋กœ ๋‘” inc๊ฐ€ slope๋ณด๋‹ค ์ž‘์œผ๋ฉด slope๋กœ inc๋ฅผ ๊ฐฑ์‹ ํ•˜๊ณ  ๋ฐฐ์—ด์˜ i์™€ j๋ฅผ 1์”ฉ ์ถ”๊ฐ€ํ•ด์ฃผ์—ˆ๋‹ค. ์ด๋Ÿฐ ๋ฐœ์ƒ์„ ์–ด๋–ป๊ฒŒ ํ–ˆ๋Š”๊ฐ€ ์‹ถ๋‹ค.

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ