์ƒˆ์†Œ์‹

๐Ÿงฎ PS

๋ฐฑ์ค€ (boj) ํŒŒ์ด์ฌ - 14500 : ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ

  • -

๋ฌธ์ œ ๋งํฌ : https://www.acmicpc.net/problem/14500

 

14500๋ฒˆ: ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ

ํด๋ฆฌ์˜ค๋ฏธ๋…ธ๋ž€ ํฌ๊ธฐ๊ฐ€ 1×1์ธ ์ •์‚ฌ๊ฐํ˜•์„ ์—ฌ๋Ÿฌ ๊ฐœ ์ด์–ด์„œ ๋ถ™์ธ ๋„ํ˜•์ด๋ฉฐ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•ด์•ผ ํ•œ๋‹ค. ์ •์‚ฌ๊ฐํ˜•์€ ์„œ๋กœ ๊ฒน์น˜๋ฉด ์•ˆ ๋œ๋‹ค. ๋„ํ˜•์€ ๋ชจ๋‘ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค. ์ •์‚ฌ๊ฐํ˜•์˜ ๋ณ€๋ผ๋ฆฌ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค. ์ฆ‰, ๊ผญ์ง“์ ๊ณผ ๊ผญ์ง“์ ๋งŒ ๋งž๋‹ฟ์•„ ์žˆ์œผ๋ฉด ์•ˆ ๋œ๋‹ค. ์ •์‚ฌ๊ฐํ˜• 4๊ฐœ๋ฅผ ์ด์–ด ๋ถ™์ธ ํด๋ฆฌ์˜ค๋ฏธ๋…ธ๋Š” ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ๋ผ๊ณ  ํ•˜๋ฉฐ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ 5๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค. ์•„๋ฆ„์ด๋Š” ํฌ๊ธฐ๊ฐ€ N×M์ธ ์ข…์ด ์œ„์— ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ ํ•˜๋‚˜๋ฅผ ๋†“์œผ๋ ค๊ณ  ํ•œ๋‹ค. ์ข…์ด๋Š” 1×1 ํฌ๊ธฐ์˜ ์นธ์œผ๋กœ ๋‚˜๋ˆ„

www.acmicpc.net

 

 

 

 

๋ฌธ์ œ ๋ถ„๋ฅ˜ : ๋ธŒ๋ฃจํŠธ ํฌ์Šค

https://infinitt.tistory.com/241

 

๋ฐฑ์ค€ (boj) ํŒŒ์ด์ฌ , C++ - 2309 : ์ผ๊ณฑ ๋‚œ์Ÿ์ด

๋ฌธ์ œ ๋งํฌ : https://www.acmicpc.net/problem/2309 2309๋ฒˆ: ์ผ๊ณฑ ๋‚œ์Ÿ์ด ์•„ํ™‰ ๊ฐœ์˜ ์ค„์— ๊ฑธ์ณ ๋‚œ์Ÿ์ด๋“ค์˜ ํ‚ค๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ํ‚ค๋Š” 100์„ ๋„˜์ง€ ์•Š๋Š” ์ž์—ฐ์ˆ˜์ด๋ฉฐ, ์•„ํ™‰ ๋‚œ์Ÿ์ด์˜ ํ‚ค๋Š” ๋ชจ๋‘ ๋‹ค๋ฅด๋ฉฐ, ๊ฐ€๋Šฅํ•œ ์ •..

infinitt.tistory.com

 


์–ด๋ ค์šด ๊ฐœ๋…์€ ์—†์ง€๋งŒ ์—„์ฒญ๋‚œ ๋…ธ๊ฐ€๋‹ค ์ž‘์—…์ด ์žˆ์—ˆ๋‹ค..... 

ํ•œ๋‘์ค„๋งŒ ์ž…๋ ฅํ•˜๋‹ค๋ณด๋ฉด ์š”๋ น์ด ์ƒ๊ธธ์ •๋„์˜ ๋ฐ˜๋ณต์ž‘์—…์ด์—ˆ๋‹ค. 

 

 

์ •๋‹ต์ฝ”๋“œ - ํŒŒ์ด์ฌ(python)

 

N , M  = map(int,input().split())
arr = []; x = []
for _ in range(N):
    arr.append(list(map(int,input().split())))

answer= []
for i in range(N):
    
    for k in range(M):
        # k = 0 1 2 3 4 / M = 5
        #์ผ์ž - ๊ฐ€๋กœ
        if k+3 < M :
            x.append(arr[i][k] + arr[i][k+1] + arr[i][k+2] + arr[i][k+3])
        #์ผ์ž - ์„ธ๋กœ
        if i+3 < N :
            x.append(arr[i][k] + arr[i+1][k] + arr[i+2][k] + arr[i+3][k])
        

        #์ •์‚ฌ๊ฐํ˜•
        if k+1<M and i+1<N :
            x.append(arr[i][k] + arr[i][k+1]+arr[i+1][k] + arr[i+1][k+1])

        #ใ…—๋ชจ์–‘
        if k+2 < M and i+1 < N :
            x.append(arr[i][k+1] + arr[i+1][k] + arr[i+1][k+1] + arr[i+1][k+2])
        #ใ…œ๋ชจ์–‘
        if k+2< M and i+1<N :
            x.append(arr[i+1][k+1] + arr[i][k] + arr[i][k+1] + arr[i][k+2])    
        #ใ…“๋ชจ์–‘
        if k+1 < M and i+2<N :
            x.append(arr[i+1][k] + arr[i][k+1] + arr[i+1][k+1] + arr[i+2][k+1])    
        #ใ… ๋ชจ์–‘    
        if k+1 < M and i+2<N :
            x.append(arr[i+1][k+1] + arr[i][k] + arr[i+1][k] + arr[i+2][k])    
        
        ##
         #
         # ๋ชจ์–‘
        if k+1 <M and i+2<N:
            x.append(arr[i][k]+arr[i][k+1]+arr[i+1][k+1]+arr[i+2][k+1])
        ##
        # 
        #  ๋ชจ์–‘
        if k+1 < M and i+2<N:
            x.append(arr[i][k]+arr[i][k+1]+arr[i+1][k]+arr[i+2][k])

        #
        #
        ## ๋ชจ์–‘
        if k+1 < M and i+2<N:
            x.append(arr[i][k]+arr[i+1][k]+arr[i+2][k]+ arr[i+2][k+1])
         #
         #
        ## ๋ชจ์–‘
        if k+1 <M and i+2<N:
            x.append(arr[i+2][k]+arr[i][k+1]+arr[i+1][k+1]+arr[i+2][k+1])
        ###
        #   ๋ชจ์–‘
        if k+2<M and i+1<N:
            x.append(arr[i][k]+arr[i][k+1]+arr[i][k+2]+arr[i+1][k])
          #
        ### ๋ชจ์–‘
        if k+2<M and i+1<N:
            x.append(arr[i][k+2]+arr[i+1][k]+arr[i+1][k+1]+arr[i+1][k+2])

        #
        ### ๋ชจ์–‘
        if k+2<M and i+1<N:
            x.append(arr[i][k]+arr[i+1][k]+arr[i+1][k+1]+arr[i+1][k+2])

        ###
          # ๋ชจ์–‘
        if k+2<M and i+1<N:
            x.append(arr[i][k]+arr[i][k+1]+arr[i][k+2]+arr[i+1][k+2])
        ###
        #    ๋ชจ์–‘    
        if k+2<M and i+1<N:
            x.append(arr[i][k]+arr[i][k+1]+arr[i][k+2]+arr[i+1][k])

        
        #
        ##
         # ๋ชจ์–‘
        if k+1<M and i+2 <N:
            x.append(arr[i][k]+arr[i+1][k] + arr[i+1][k+1] + arr[i+2][k+1])
         #
        ##
        #
        if k+1<M and i+2 <N:
            x.append(arr[i][k+1]+arr[i+1][k] + arr[i+1][k+1] + arr[i+2][k])

        ##
         ## 
        if k+2<M and i+1<N:
            x.append(arr[i][k]+arr[i][k+1]+arr[i+1][k+1]+arr[i+1][k+2])
         ##
        ##
        if k+2<M and i+1<N:
            x.append(arr[i][k+1]+arr[i][k+2]+arr[i+1][k]+arr[i+1][k+1])
print(max(x))

 

 

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.