Submission #127290

#TimeUsernameProblemLanguageResultExecution timeMemory
127290E869120Maxcomp (info1cup18_maxcomp)C++14
60 / 100
588 ms16804 KiB
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <cassert>
using namespace std;
#pragma warning (disable: 4996)

int N, M, A[1009][1009], dist[1009][1009];

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]); dist[i][j] = A[i][j] - 1; }
	}
	priority_queue<long long, vector<long long>, less<long long>>Q;
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) Q.push(((1LL * A[i][j]) << 32) + 1LL * (i << 16) + 1LL * j); }

	while (!Q.empty()) {
		long long pos = Q.top(); Q.pop();
		int px = ((pos >> 16) & 65535LL), py = (pos & 65535LL);
		int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
		for (int i = 0; i < 4; i++) {
			int ex = px + dx[i], ey = py + dy[i];
			if (ex <= 0 || ey <= 0 || ex > N || ey > M) continue;
			if (dist[ex][ey] < dist[px][py] - 1) {
				dist[ex][ey] = dist[px][py] - 1;
				Q.push(((1LL * dist[ex][ey]) << 32) + 1LL * (ex << 16) + 1LL * ey);
			}
		}
	}

	int maxn = -1;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) maxn = max(maxn, dist[i][j] - A[i][j]);
	}
	cout << maxn << endl;
	return 0;
}

Compilation message (stderr)

maxcomp.cpp:7:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
maxcomp.cpp: In function 'int main()':
maxcomp.cpp:12: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:14:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (int j = 1; j <= M; j++) { scanf("%d", &A[i][j]); dist[i][j] = A[i][j] - 1; }
                                  ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...