forked from ming-ki/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
33 lines (28 loc) · 952 Bytes
/
main.cpp
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
// Authored by : tony9402
// Co-authored by : -
// Link : http://boj.kr/2b018771f61549749df9e0a5a023ba28
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll prefix[4004][4004], V[2002][2002], ans[2002][2002];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int N, M; cin >> N >> M;
int dx = M / 2;
for(int i=1;i<=N;i++) {
for(int j=1;j<=N;j++) {
cin >> V[i][j];
prefix[i + M - 1][j + M - 1] = prefix[i + M - 2][j + M - 1] + prefix[i + M - 1][j + M - 2] - prefix[i + M - 2][j + M - 2];
ans[i + dx][j + dx] = -(V[i][j] + prefix[i + M - 1][j + M - 1] - prefix[i - 1][j + M - 1] - prefix[i + M - 1][j - 1] + prefix[i - 1][j - 1]);
prefix[i + M - 1][j + M - 1] += ans[i + dx][j + dx];
}
}
for(int i=1;i<=N;i++) {
for(int j=1;j<=N;j++) {
cout << ans[i][j] << " ";
}
cout << '\n';
}
return 0;
}