#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define pip pair<int,pii>
#define ff first
#define ss second
using namespace std;
const int MAXN = 1000;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
vector <vector<int>> arr(n);
for (int i = 0; i < n; i++) {
arr[i].resize(m);
for (int j = 0; j < m; j++) {
cin >> arr[i][j];
}
}
int ans = -1;
vector <vector<int>> vis(n);
priority_queue <pip> nxt;
for (int j = 0; j < n; j++) {
vis[j].resize(m);
for (int k = 0; k < m; k++) {
vis[j][k] = arr[j][k] - 1;
nxt.push(pip(vis[j][k], pii(j, k)));
}
}
vector <int> dx = {0, 1, -1, 0}, dy = {1, 0, 0, -1};
while (nxt.size()) {
pip now = nxt.top();
if (now.ff != vis[now.ss.ff][now.ss.ss]) continue;
nxt.pop();
now.ff--;
for (int i = 0; i < 4; i++) {
int x = now.ss.ff + dx[i], y = now.ss.ss + dy[i];
if (x < 0 || y < 0 || x >= n || y >= m) continue;
ans = max(ans, now.ff - arr[x][y]);
if (now.ff > vis[x][y]) {
vis[x][y] = now.ff;
nxt.push(pip(now.ff, pii(x, y)));
}
}
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1040 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1051 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1040 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1040 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |