#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 = -1e9;
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]);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
620 KB |
Output is correct |
2 |
Correct |
3 ms |
620 KB |
Output is correct |
3 |
Correct |
3 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
4 ms |
876 KB |
Output is correct |
10 |
Correct |
4 ms |
876 KB |
Output is correct |
11 |
Correct |
5 ms |
876 KB |
Output is correct |
12 |
Correct |
5 ms |
1004 KB |
Output is correct |
13 |
Correct |
4 ms |
1004 KB |
Output is correct |
14 |
Correct |
5 ms |
1004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
11 |
Correct |
3 ms |
620 KB |
Output is correct |
12 |
Correct |
4 ms |
876 KB |
Output is correct |
13 |
Correct |
4 ms |
876 KB |
Output is correct |
14 |
Correct |
5 ms |
876 KB |
Output is correct |
15 |
Correct |
5 ms |
1004 KB |
Output is correct |
16 |
Correct |
4 ms |
1004 KB |
Output is correct |
17 |
Correct |
5 ms |
1004 KB |
Output is correct |
18 |
Execution timed out |
966 ms |
17516 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |