답안 #479837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
479837 2021-10-13T10:44:30 Z MilosMilutinovic Maxcomp (info1cup18_maxcomp) C++14
100 / 100
193 ms 28508 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int N = 1005;

int n, m;
int a[N][N];
int pref1[N][N];
int pref2[N][N];
int pref3[N][N];
int pref4[N][N];

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			pref1[i][j] = a[i][j] - i - j;
			if (i > 0) pref1[i][j] = min(pref1[i][j], pref1[i - 1][j]);
			if (j > 0) pref1[i][j] = min(pref1[i][j], pref1[i][j - 1]);
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j < m; j++) {
			pref2[i][j] = a[i][j] + i - j;
			if (i + 1 < n) pref2[i][j] = min(pref2[i][j], pref2[i + 1][j]);
			if (j > 0) pref2[i][j] = min(pref2[i][j], pref2[i][j - 1]);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = m - 1; j >= 0; j--) {
			pref3[i][j] = a[i][j] - i + j;
			if (i > 0) pref3[i][j] = min(pref3[i][j], pref3[i - 1][j]);
			if (j + 1 < m) pref3[i][j] = min(pref3[i][j], pref3[i][j + 1]);
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = m - 1; j >= 0; j--) {
			pref4[i][j] = a[i][j] + i + j;
			if (i + 1 < n) pref4[i][j] = min(pref4[i][j], pref4[i + 1][j]);
			if (j + 1 < m) pref4[i][j] = min(pref4[i][j], pref4[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 - pref1[i][j] - 1);
			ans = max(ans, a[i][j] + i - j - pref2[i][j] - 1);
			ans = max(ans, a[i][j] - i + j - pref3[i][j] - 1);
			ans = max(ans, a[i][j] + i + j - pref4[i][j] - 1);
		}
	}
	cout << ans << '\n';
	return 0;
}

Compilation message

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
maxcomp.cpp:36:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |    scanf("%d", &a[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 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 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 2 ms 1228 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 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 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 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 2 ms 1228 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 1228 KB Output is correct
18 Correct 138 ms 28416 KB Output is correct
19 Correct 193 ms 28508 KB Output is correct
20 Correct 134 ms 28112 KB Output is correct
21 Correct 148 ms 28484 KB Output is correct
22 Correct 137 ms 28484 KB Output is correct
23 Correct 145 ms 28412 KB Output is correct
24 Correct 132 ms 28240 KB Output is correct