답안 #210921

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210921 2020-03-19T02:33:44 Z ryansee Maxcomp (info1cup18_maxcomp) C++14
15 / 100
5 ms 512 KB
#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 ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (1006)
ll 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));
			}
		}
	}
	ll ans=0;
	FOR(i,1,n)FOR(j,1,m)ans=max(ans,dist[i][j]-grid[i][j]);
	cout<<ans<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -