답안 #360110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
360110 2021-01-27T13:08:56 Z Poimidorka Maxcomp (info1cup18_maxcomp) C++17
100 / 100
158 ms 16748 KB
#include <random>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <queue>
#include <string>
#include <algorithm>
#include <tuple>
#include <cassert>


using namespace std;


#define x first
#define y second
//#define int long long


#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,sse4,tune=native")
#pragma GCC optimize("unroll-loops")


const int maxn = 1e3 + 10;


int mat[maxn][maxn];
int d1[maxn][maxn];
int n, m;


signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	int ans = -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
			cin >> mat[i][j];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			d1[i][j] = mat[i][j] + i + j;
			if (i)
				d1[i][j] = max(d1[i][j], d1[i - 1][j]);
			if (j)
				d1[i][j] = max(d1[i][j], d1[i][j - 1]);			
			ans = max(ans, d1[i][j] - mat[i][j] - i - j - 1);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = m - 1; j >= 0; j--) {
			d1[i][j] = mat[i][j] + i - j;
			if (i)
				d1[i][j] = max(d1[i][j], d1[i - 1][j]);
			if (j != m - 1)
				d1[i][j] = max(d1[i][j], d1[i][j + 1]);			
			ans = max(ans, d1[i][j] - mat[i][j] - i + j - 1);
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j < m; j++) {
			d1[i][j] = mat[i][j] - i + j;
			if (i != n - 1)
				d1[i][j] = max(d1[i][j], d1[i + 1][j]);
			if (j)
				d1[i][j] = max(d1[i][j], d1[i][j - 1]);
			ans = max(ans, d1[i][j] - mat[i][j] + i - j - 1);
		}
	}
	// for (int i = 0; i < n; i++) {
	// 	for (int j = 0; j < m; j++)
	// 		cout << d1[i][j] << ' ';
	// 	cout << '\n';
	// }
	for (int i = n - 1; i >= 0; i--) {
		for (int j = m - 1; j >= 0; j--) {
			d1[i][j] = mat[i][j] - i - j;
			if (i != n - 1)
				d1[i][j] = max(d1[i][j], d1[i + 1][j]);
			if (j != m - 1)
				d1[i][j] = max(d1[i][j], d1[i][j + 1]);			
			ans = max(ans, d1[i][j] - mat[i][j] + i + j - 1);
			// cout << d1[i][j] << ' ';
		}
		// cout << endl;
	}
	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 748 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 748 KB Output is correct
17 Correct 1 ms 748 KB Output is correct
18 Correct 131 ms 8300 KB Output is correct
19 Correct 155 ms 8300 KB Output is correct
20 Correct 119 ms 8428 KB Output is correct
21 Correct 129 ms 16748 KB Output is correct
22 Correct 158 ms 16748 KB Output is correct
23 Correct 132 ms 16748 KB Output is correct
24 Correct 125 ms 16364 KB Output is correct