#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) (int)(x).size()
#define len(x) (int)(x).length()
#define cntbit(x) builtin_popcnt(x)
#define f first
#define s second
#define pb push_back
const int N = 30;
int dp[N][N][N][N][30];
void minimize(int &a, int b) {
if (a > b)
a = b;
}
ll solve() {
memset(dp, 0x3f, sizeof(dp));
int n, m;
cin >> n >> m;
for (int a = 1; a <= n; a++) {
for (int b = 1; b <= n; b++) {
for (int c = 1; c <= n; c++) {
for (int d = 1; d <= n; d++) {
cin >> dp[a][b][c][d][0];
}
}
}
}
vector < vector <int>> all;
for (int mask = 0; mask < (1 << 4); mask++) {
vector <int> v;
for (int j = 0; j < 4; j++) {
if (mask & (1 << j)) {
v.pb(1);
} else {
v.pb(0);
}
}
all.pb(v);
}
for (int a = n; a >= 1; a--) {
for (int b = n; b >= 1; b--) {
for (int c = n; c >= 1; c--) {
for (int d = n; d >= 1; d--) {
for (int k = 1; k <= m; k++) {
for (auto x : all) {
minimize(dp[a][b][c][d][k], dp[a + x[0]][b + x[1]][c + x[2]][d + x[3]][k - 1]);
}
}
}
}
}
}
for (int a = 1; a + m - 1 <= n; a++) {
for (int b = 1; b + m - 1 <= n; b++) {
for (int c = 1; c + m - 1 <= n; c++) {
for (int d = 1; d + m - 1 <= n; d++) {
cout << dp[a][b][c][d][m - 1] << " ";
}
}
}
}
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
//cout << solve() << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
95320 KB |
Output is correct |
2 |
Correct |
12 ms |
95324 KB |
Output is correct |
3 |
Correct |
39 ms |
95324 KB |
Output is correct |
4 |
Correct |
26 ms |
95320 KB |
Output is correct |
5 |
Correct |
21 ms |
95532 KB |
Output is correct |
6 |
Correct |
89 ms |
95544 KB |
Output is correct |
7 |
Correct |
153 ms |
95324 KB |
Output is correct |
8 |
Correct |
811 ms |
95544 KB |
Output is correct |
9 |
Correct |
103 ms |
97108 KB |
Output is correct |
10 |
Correct |
588 ms |
95572 KB |
Output is correct |
11 |
Correct |
1142 ms |
96080 KB |
Output is correct |
12 |
Runtime error |
190 ms |
201540 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |