#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define For( i , a ) for(int i=1;i<=a;i++)
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf
#define set multiset
using namespace std;
typedef long long Lint;
typedef double db;
typedef pair<int,int> ii;
typedef pair<int,char> ic;
typedef pair<db,db> dd;
typedef pair<int,ii> iii;
typedef pair<ii,ii> i4;
const int maxn = 1020;
const int maxm = 1000020;
const int MOd = 998244353;
int ar[maxn][maxn];
bool used[maxn][maxn];
priority_queue<iii> q;
int yol[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
int main() {
//freopen("asd.in","r",stdin);
//freopen("output17.txt","w",stdout);
int a, b;
scanf("%d %d",&a,&b);
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++) {
scanf("%d",&ar[i][j]);
q.push( iii( ar[i][j], ii( i, j ) ) );
}
int ans = 0;
while( !q.empty() ) {
int mal = q.top().fi;
int x = q.top().se.fi;
int y = q.top().se.se;
q.pop();
if( used[x][y] ) continue;
used[x][y]=1;
umax( ans, mal-ar[x][y]-1 );
for(int i=0;i<4;i++) {
int gox = x + yol[i][0];
int goy = y + yol[i][1];
if( 0 < gox && gox <= a && 0 < goy && goy <= b && !used[gox][goy] )
q.push( iii( mal-1, ii( gox, goy ) ) );
}
}
cout << ans << endl;
return 0;
}
Compilation message
maxcomp.cpp: In function 'int main()':
maxcomp.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&a,&b);
~~~~~^~~~~~~~~~~~~~~
maxcomp.cpp:55:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&ar[i][j]);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Incorrect |
2 ms |
488 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
496 KB |
Output is correct |
2 |
Correct |
2 ms |
496 KB |
Output is correct |
3 |
Correct |
3 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Incorrect |
2 ms |
488 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Incorrect |
2 ms |
488 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |