Submission #46245

# Submission time Handle Problem Language Result Execution time Memory
46245 2018-04-18T09:23:40 Z qoo2p5 Maxcomp (info1cup18_maxcomp) C++17
60 / 100
500 ms 21300 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = (int) 1e9 + 1e6 + 123;
const ll LINF = (ll) 1e18 + 1e9 + 123;

#define rep(i, s, t) for (auto i = (s); i < (t); ++(i))
#define per(i, s, t) for (auto i = (s); i >= (t); --(i))
#define sz(x) ((int)(x).size())
#define mp make_pair
#define pb push_back

bool mini(auto &x, const auto &y) {
	if (y < x) {
		x = y;
		return 1;
	}
	return 0;
}

bool maxi(auto &x, const auto &y) {
	if (y > x) {
		x = y;
		return 1;
	}
	return 0;
}

void run();

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	run();
	return 0;
}

const int N = (int) 1000 + 1;

int n, m;
int a[N][N], dp[N][N];
bool vis[N][N];
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};

bool check(int i, int j) {
	return 0 <= min(i, j) && i < n && j < m;
}

void run() {
	cin >> n >> m;
	rep(i, 0, n) {
		rep(j, 0, m) {
			cin >> a[i][j];
		}
	}
	
	priority_queue<pair<int, pair<int, int>>> q;
	rep(i, 0, n) {
		rep(j, 0, m) {
			dp[i][j] = a[i][j] + 1;
			q.push({-dp[i][j], {i, j}});
		}
	}
	
	while (sz(q)) {
		auto it = q.top();
		int i = it.second.first;
		int j = it.second.second;
		q.pop();
		if (vis[i][j]) continue;
		vis[i][j] = 1;
		rep(dir, 0, 4) {
			int ni = i + dx[dir];
			int nj = j + dy[dir];
			if (check(ni, nj) && mini(dp[ni][nj], dp[i][j] + 1)) {
				q.push({-dp[ni][nj], {ni, nj}});
			}
		}
	}
	
	int ans = -INF;
	rep(i, 0, n) rep(j, 0, m) maxi(ans, a[i][j] - dp[i][j]);
	cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 2 ms 496 KB Output is correct
6 Correct 2 ms 496 KB Output is correct
7 Correct 2 ms 496 KB Output is correct
8 Correct 2 ms 496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 496 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 2 ms 496 KB Output is correct
6 Correct 2 ms 496 KB Output is correct
7 Correct 2 ms 496 KB Output is correct
8 Correct 2 ms 496 KB Output is correct
9 Correct 4 ms 1072 KB Output is correct
10 Correct 3 ms 1200 KB Output is correct
11 Correct 4 ms 1208 KB Output is correct
12 Correct 3 ms 1208 KB Output is correct
13 Correct 3 ms 1208 KB Output is correct
14 Correct 4 ms 1208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 2 ms 496 KB Output is correct
6 Correct 2 ms 496 KB Output is correct
7 Correct 2 ms 496 KB Output is correct
8 Correct 2 ms 496 KB Output is correct
9 Correct 2 ms 496 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 4 ms 1072 KB Output is correct
13 Correct 3 ms 1200 KB Output is correct
14 Correct 4 ms 1208 KB Output is correct
15 Correct 3 ms 1208 KB Output is correct
16 Correct 3 ms 1208 KB Output is correct
17 Correct 4 ms 1208 KB Output is correct
18 Execution timed out 670 ms 21300 KB Time limit exceeded
19 Halted 0 ms 0 KB -