์ƒˆ์†Œ์‹

๐Ÿงฎ PS

๋ฐฑ์ค€ (boj) ํŒŒ์ด์ฌ - 2167 ์ด์ฐจ์› ๋ฐฐ์—ด ํ•ฉ

  • -

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

 

2167๋ฒˆ: 2์ฐจ์› ๋ฐฐ์—ด์˜ ํ•ฉ

์ฒซ์งธ ์ค„์— ๋ฐฐ์—ด์˜ ํฌ๊ธฐ N, M(1 ≤ N, M ≤ 300)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ N๊ฐœ์˜ ์ค„์—๋Š” M๊ฐœ์˜ ์ •์ˆ˜๋กœ ๋ฐฐ์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ๋ฐฐ์—ด์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์ˆ˜๋Š” ์ ˆ๋Œ“๊ฐ’์ด 10,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜์ด๋‹ค. ๊ทธ ๋‹ค์Œ ์ค„์—๋Š” ํ•ฉ์„ ๊ตฌํ•  ๋ถ€๋ถ„์˜ ๊ฐœ์ˆ˜ K(1 ≤ K ≤ 10,000)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ K๊ฐœ์˜ ์ค„์—๋Š” ๋„ค ๊ฐœ์˜ ์ •์ˆ˜๋กœ i, j, x, y๊ฐ€ ์ฃผ์–ด์ง„๋‹ค(i ≤ x, j ≤ y).

www.acmicpc.net

 

2์ฐจ์› ๋ฐฐ์—ด์ด๊ธฐ์— 2์ค‘ for๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ, ๋ฌธ์ œ๋‚ด์šฉ ๊ทธ๋Œ€๋กœ ๊ตฌํ˜„ํ–ˆ๋‹ค. ํ•˜์ง€๋งŒ ๊ทธ๋ƒฅ python3์œผ๋กœ ์ œ์ถœํ•˜๊ฒŒ๋˜๋ฉด

 

์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋‚ฌ๊ธฐ ๋•Œ๋ฌธ์—, ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ด์šฉํ•˜๋ผ๋Š” ์ถœ์ œ์˜๋„๊ฐ™๋‹ค. ์ผ๋‹จ์€ pypy3๋กœ ์ œ์ถœํ–ˆ์ง€๋งŒ, ๋‹ค์Œ์— ๊ณ ์ณ๋ด์•ผ๊ฒ ๋‹ค.

 

 

ํŒŒ์ด์ฌ ์ฝ”๋“œ (pypy3๋กœ ์ œ์ถœ)
import sys
input = sys.stdin.readline
N,M = map(int,input().split())

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

K = int(input())
for _ in range(K):
    i,j,x,y = map(int,input().split())
    sum = 0
    for a in range(i-1,x):
        for k in range(j-1,y):
            sum+=arr[a][k]
    answer.append(sum)


for prt in answer :
    print(prt)

 

Contents

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

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