#include <bits/stdc++.h>
#define fi first
#define se second
#define lo long long
#define inf 1000000000
#define md 1000000007
#define li 1004
#define mp make_pair
#define pb push_back
#define pii pair<int , pair<int , int> >
using namespace std;
int n, m, A[li][li], mn = inf + 5, cev = - 1;
queue< pair<int , pair<int , int> > > q;
int vis[li][li], deg[li][li];
int yon1[6] = {1, - 1, 0, 0};
int yon2[6] = {0, 0, 1, - 1};
pii temp;
int main(){
scanf("%d %d", &n, &m);
for(int i = 1; i <= n ; i ++){
for(int j = 1; j <= m; j ++){
scanf("%d", &A[i][j]);
mn = min(mn, A[i][j]);
}
}
for(int i = 1; i <= n ; i ++){
for(int j = 1; j <= m; j ++){
if(A[i][j] == mn){
q.push(mp(1, mp(i, j)));
}
}
}
while(! q.empty()){
temp = q.front();
q.pop();
int val = temp.fi;
int x = temp.se.fi;
int y = temp.se.se;
if(vis[x][y] == 1) continue;
vis[x][y] = 1;
deg[x][y] = val;
for(int i = 0; i <= 3; i ++){
int dx = x + yon1[i];
int dy = y + yon2[i];
if(dx < 1 || dx > n || dy < 1 || dy > m) continue;
q.push(mp(val + 1, mp(dx, dy)));
}
}
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
cev = max(cev, A[i][j] - mn - deg[i][j]);
}
}
printf("%d\n", cev);
return 0;
}
Compilation message
maxcomp.cpp: In function 'int main()':
maxcomp.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:22:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &A[i][j]);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |