답안 #496851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496851 2021-12-22T05:27:08 Z abc864197532 Maxcomp (info1cup18_maxcomp) C++17
100 / 100
135 ms 28448 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define X first
#define Y second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
	cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
	for (; l != r; ++l) 
		cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x);
#else
#define test(x...) void(0);
#endif
const int N = 1001;

int a[N][N], ul[N][N], ur[N][N], dl[N][N], dr[N][N];

int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
		cin >> a[i][j];
		ul[i][j] = -a[i][j] + i + j;
		ur[i][j] = -a[i][j] + i - j;
		dl[i][j] = -a[i][j] - i + j;
		dr[i][j] = -a[i][j] - i - j;
	}
	for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
		if (i)
			ul[i][j] = max(ul[i][j], ul[i - 1][j]);
		if (j)
			ul[i][j] = max(ul[i][j], ul[i][j - 1]);
	}
	for (int i = 0; i < n; ++i) for (int j = m - 1; ~j; --j) {
		if (i)
			ur[i][j] = max(ur[i][j], ur[i - 1][j]);
		if (j + 1 < m)
			ur[i][j] = max(ur[i][j], ur[i][j + 1]);	
	}
	for (int i = n - 1; ~i; --i) for (int j = 0; j < m; ++j) {
		if (i + 1 < n)
			dl[i][j] = max(dl[i][j], dl[i + 1][j]);
		if (j)
			dl[i][j] = max(dl[i][j], dl[i][j - 1]);	
	}
	for (int i = n - 1; ~i; --i) for (int j = m - 1; ~j; --j) {
		if (i + 1 < n)
			dr[i][j] = max(dr[i][j], dr[i + 1][j]);
		if (j + 1 < m)
			dr[i][j] = max(dr[i][j], dr[i][j + 1]);
	}
	int ans = -1;
	for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
		ans = max(ans, a[i][j] - i - j + ul[i][j] - 1);
		ans = max(ans, a[i][j] - i + j + ur[i][j] - 1);
		ans = max(ans, a[i][j] + i - j + dl[i][j] - 1);
		ans = max(ans, a[i][j] + i + j + dr[i][j] - 1);
	}
	cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 1228 KB Output is correct
10 Correct 1 ms 1324 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 1 ms 1228 KB Output is correct
14 Correct 1 ms 1232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 1228 KB Output is correct
13 Correct 1 ms 1324 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 1 ms 1228 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
17 Correct 1 ms 1232 KB Output is correct
18 Correct 126 ms 28344 KB Output is correct
19 Correct 129 ms 28448 KB Output is correct
20 Correct 117 ms 28000 KB Output is correct
21 Correct 135 ms 28348 KB Output is correct
22 Correct 122 ms 28416 KB Output is correct
23 Correct 127 ms 28440 KB Output is correct
24 Correct 118 ms 28224 KB Output is correct