This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int, int>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 11;
const int B = 800;
int a[1001][1001];
int mx[1001][1001];
bool vis[1001][1001];
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
int n, m;
bool in(int i, int j){
return 0 <= i && i < n && 0 <= j && j < m;
}
int32_t main(){
cin >> n >> m;
priority_queue<pair<int, int>> pq;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> a[i][j];
mx[i][j] = a[i][j];
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
pq.push({mx[i][j], i * m + j});
}
}
while(pq.size()){
pair<int, int> t = pq.top(); pq.pop();
int i = t.se / m, j = t.se % m, val = t.fi;
if(mx[i][j] != val || vis[i][j]) continue; vis[i][j] = true;
for(int dir = 0; dir < 4; dir++){
if(in(i + dx[dir], j + dy[dir]) && mx[i + dx[dir]][j + dy[dir]] < mx[i][j] - 1){
mx[i + dx[dir]][j + dy[dir]] = mx[i][j] - 1;
int ni = i + dx[dir], nj = j + dy[dir];
pq.push({mx[i + dx[dir]][j + dy[dir]], ni * m + nj});
}
}
}
int ans = -1;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
ans = max(ans, mx[i][j] - a[i][j] - 1);
}
}
cout << ans << endl;
}
Compilation message (stderr)
maxcomp.cpp: In function 'int32_t main()':
maxcomp.cpp:41:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
41 | if(mx[i][j] != val || vis[i][j]) continue; vis[i][j] = true;
| ^~
maxcomp.cpp:41:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
41 | if(mx[i][j] != val || vis[i][j]) continue; vis[i][j] = true;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |