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 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 (stderr)
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 |
---|
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... |