#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
typedef long long ll;
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;
#define LLINF INF //((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (1006)
int n,m,dist[MAXN][MAXN],grid[MAXN][MAXN];
int main(){
FAST
cin>>n>>m;
FOR(i,1,n)FOR(j,1,m)cin>>grid[i][j];
priority_queue<spi>pq;
FOR(i,1,n)FOR(j,1,m)dist[i][j]=grid[i][j]-1,pq.emplace(dist[i][j],pi(i,j));
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
while(pq.size()){
ll x=pq.top().s.f,y=pq.top().s.s,d=pq.top().f;
pq.pop();
if(dist[x][y]^d)continue;
FOR(i,0,3){
ll nx=x+dx[i];
ll ny=y+dy[i];
if(nx<=0||nx>n||ny<=0||ny>m)continue;
if(dist[nx][ny]<d-1){
dist[nx][ny]=d-1;
pq.emplace(dist[nx][ny],pi(nx,ny));
}
}
}
int ans=-LLINF;
FOR(i,1,n)FOR(j,1,m)ans=max(ans,dist[i][j]-grid[i][j]);
cout<<ans<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
6 ms |
896 KB |
Output is correct |
10 |
Correct |
6 ms |
896 KB |
Output is correct |
11 |
Correct |
6 ms |
896 KB |
Output is correct |
12 |
Correct |
6 ms |
944 KB |
Output is correct |
13 |
Correct |
6 ms |
896 KB |
Output is correct |
14 |
Correct |
6 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
896 KB |
Output is correct |
13 |
Correct |
6 ms |
896 KB |
Output is correct |
14 |
Correct |
6 ms |
896 KB |
Output is correct |
15 |
Correct |
6 ms |
944 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
6 ms |
896 KB |
Output is correct |
18 |
Execution timed out |
779 ms |
32044 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |