#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();
nxt.pop();
if (now.ff != vis[now.ss.ff][now.ss.ss]) continue;
if (now.ff <= ans) continue;
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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
416 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
416 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
416 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Execution timed out |
677 ms |
19964 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |