1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<cstdbool>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 987654321
#define LINF 321321321321
#define MAX 1100
int n, m;
int board[1025][1025];
int dp[1025][1025];
 
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
 
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cin >> board[i][j];
 
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1- dp[i - 1][j - 1+ board[i][j];
        }
    }
    for (int k = 0; k < m; k++) {
        int y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;
 
        cout << dp[y2][x2] - dp[y1 - 1][x2] - dp[y2][x1 - 1+ dp[y1 - 1][x1 - 1<< "\n";
    }
    
 
    
    return 0;
}
cs

출처:https://www.acmicpc.net/problem/11660

 

11660번: 구간 합 구하기 5

첫째 줄에 표의 크기 N과 합을 구해야 하는 횟수 M이 주어진다. (1 ≤ N ≤ 1024, 1 ≤ M ≤ 100,000) 둘째 줄부터 N개의 줄에는 표에 채워져 있는 수가 1행부터 차례대로 주어진다. 다음 M개의 줄에는 네

www.acmicpc.net

로직엔 문제없었는데 시간초과가 뜨는걸 보니 입력이 너무많아서 

ios_base::sync_with_stdio(false);
    cin.tie(0);
을 추가해주고 정답처리 되었습니다.

+ Recent posts