Submission #388530

# Submission time Handle Problem Language Result Execution time Memory
388530 2021-04-12T01:42:50 Z warner1129 Maxcomp (info1cup18_maxcomp) C++17
100 / 100
497 ms 8276 KB
#include <bits/stdc++.h>

using namespace std;

const int INF = 0x3f3f3f3f;

struct bibit {
	static const int maxn = 1e3 + 5;
	int a[maxn][maxn] = {};
	int n, m;
	inline int lowbit(int x) { return x & (-x); }
	void init(int _n, int _m) {
		n = _n, m = _m;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				a[i][j] = INF;
	}
	void add(int x, int y, int v) {
		for (int i = x; i <= n; i += lowbit(i))
			for (int j = y; j <= m; j += lowbit(j))
				a[i][j] = min(a[i][j], v);
	}
	int que(int x, int y) {
		int ret = INF;
		for (int i = x; i > 0; i -= lowbit(i))
			for (int j = y; j > 0; j -= lowbit(j))
				ret = min(ret, a[i][j]);
		return ret;
	}
} bit;

const int maxn = 1e3 + 5;

int G[maxn][maxn];

void solve() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> G[i][j];
	int ans = 0;
	bit.init(n, m);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			ans = max(ans, G[i][j] - i - j - bit.que(i, j));
			bit.add(i, j, G[i][j] - i - j);
		}
	bit.init(n, m);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			ans = max(ans, G[i][m-j+1] - i - j - bit.que(i, j));
			bit.add(i, j, G[i][m-j+1] - i - j);
		}	
	bit.init(n, m);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			ans = max(ans, G[n-i+1][j] - i - j - bit.que(i, j));
			bit.add(i, j, G[n-i+1][j] - i - j);
		}
	bit.init(n, m);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			ans = max(ans, G[n-i+1][m-j+1] - i - j - bit.que(i, j));
			bit.add(i, j, G[n-i+1][m-j+1] - i - j);
		}
	cout << ans - 1 << '\n';
}

signed main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4172 KB Output is correct
3 Correct 2 ms 4172 KB Output is correct
4 Correct 2 ms 4172 KB Output is correct
5 Correct 2 ms 4172 KB Output is correct
6 Correct 2 ms 4172 KB Output is correct
7 Correct 2 ms 4172 KB Output is correct
8 Correct 2 ms 4300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 3 ms 4172 KB Output is correct
3 Correct 2 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4172 KB Output is correct
3 Correct 2 ms 4172 KB Output is correct
4 Correct 2 ms 4172 KB Output is correct
5 Correct 2 ms 4172 KB Output is correct
6 Correct 2 ms 4172 KB Output is correct
7 Correct 2 ms 4172 KB Output is correct
8 Correct 2 ms 4300 KB Output is correct
9 Correct 3 ms 4428 KB Output is correct
10 Correct 3 ms 4428 KB Output is correct
11 Correct 3 ms 4432 KB Output is correct
12 Correct 3 ms 4432 KB Output is correct
13 Correct 3 ms 4428 KB Output is correct
14 Correct 3 ms 4428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4172 KB Output is correct
3 Correct 2 ms 4172 KB Output is correct
4 Correct 2 ms 4172 KB Output is correct
5 Correct 2 ms 4172 KB Output is correct
6 Correct 2 ms 4172 KB Output is correct
7 Correct 2 ms 4172 KB Output is correct
8 Correct 2 ms 4300 KB Output is correct
9 Correct 2 ms 4172 KB Output is correct
10 Correct 3 ms 4172 KB Output is correct
11 Correct 2 ms 4172 KB Output is correct
12 Correct 3 ms 4428 KB Output is correct
13 Correct 3 ms 4428 KB Output is correct
14 Correct 3 ms 4432 KB Output is correct
15 Correct 3 ms 4432 KB Output is correct
16 Correct 3 ms 4428 KB Output is correct
17 Correct 3 ms 4428 KB Output is correct
18 Correct 466 ms 8276 KB Output is correct
19 Correct 462 ms 8168 KB Output is correct
20 Correct 497 ms 8224 KB Output is correct
21 Correct 456 ms 8132 KB Output is correct
22 Correct 457 ms 8192 KB Output is correct
23 Correct 467 ms 8212 KB Output is correct
24 Correct 445 ms 8004 KB Output is correct