#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 + 5;
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() {
rep(i, 0, N) rep(j, 0, N) dp[i][j] = INF;
cin >> n >> m;
rep(i, 1, n + 1) {
rep(j, 1, m + 1) {
cin >> a[i][j];
dp[i][j] = a[i][j] + 1;
}
}
rep(i, 1, n + 1) {
rep(j, 1, m + 1) {
mini(dp[i][j], min(dp[i - 1][j] + 1, dp[i][j - 1] + 1));
}
per(j, m, 1) {
mini(dp[i][j], min(dp[i - 1][j] + 1, dp[i][j + 1] + 1));
}
}
per(i, n, 1) {
rep(j, 1, m + 1) {
mini(dp[i][j], min(dp[i + 1][j] + 1, dp[i][j - 1] + 1));
}
per(j, m, 1) {
mini(dp[i][j], min(dp[i + 1][j] + 1, dp[i][j + 1] + 1));
}
}
int ans = -INF;
rep(i, 1, n + 1) rep(j, 1, m + 1) maxi(ans, a[i][j] - dp[i][j]);
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4216 KB |
Output is correct |
2 |
Correct |
5 ms |
4324 KB |
Output is correct |
3 |
Correct |
5 ms |
4376 KB |
Output is correct |
4 |
Correct |
5 ms |
4484 KB |
Output is correct |
5 |
Correct |
5 ms |
4512 KB |
Output is correct |
6 |
Correct |
6 ms |
4528 KB |
Output is correct |
7 |
Correct |
5 ms |
4588 KB |
Output is correct |
8 |
Correct |
5 ms |
4604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4604 KB |
Output is correct |
2 |
Correct |
5 ms |
4604 KB |
Output is correct |
3 |
Correct |
5 ms |
4604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4216 KB |
Output is correct |
2 |
Correct |
5 ms |
4324 KB |
Output is correct |
3 |
Correct |
5 ms |
4376 KB |
Output is correct |
4 |
Correct |
5 ms |
4484 KB |
Output is correct |
5 |
Correct |
5 ms |
4512 KB |
Output is correct |
6 |
Correct |
6 ms |
4528 KB |
Output is correct |
7 |
Correct |
5 ms |
4588 KB |
Output is correct |
8 |
Correct |
5 ms |
4604 KB |
Output is correct |
9 |
Correct |
5 ms |
4732 KB |
Output is correct |
10 |
Correct |
5 ms |
4732 KB |
Output is correct |
11 |
Correct |
5 ms |
4732 KB |
Output is correct |
12 |
Correct |
5 ms |
4732 KB |
Output is correct |
13 |
Correct |
5 ms |
4732 KB |
Output is correct |
14 |
Correct |
6 ms |
4732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4216 KB |
Output is correct |
2 |
Correct |
5 ms |
4324 KB |
Output is correct |
3 |
Correct |
5 ms |
4376 KB |
Output is correct |
4 |
Correct |
5 ms |
4484 KB |
Output is correct |
5 |
Correct |
5 ms |
4512 KB |
Output is correct |
6 |
Correct |
6 ms |
4528 KB |
Output is correct |
7 |
Correct |
5 ms |
4588 KB |
Output is correct |
8 |
Correct |
5 ms |
4604 KB |
Output is correct |
9 |
Correct |
5 ms |
4604 KB |
Output is correct |
10 |
Correct |
5 ms |
4604 KB |
Output is correct |
11 |
Correct |
5 ms |
4604 KB |
Output is correct |
12 |
Correct |
5 ms |
4732 KB |
Output is correct |
13 |
Correct |
5 ms |
4732 KB |
Output is correct |
14 |
Correct |
5 ms |
4732 KB |
Output is correct |
15 |
Correct |
5 ms |
4732 KB |
Output is correct |
16 |
Correct |
5 ms |
4732 KB |
Output is correct |
17 |
Correct |
6 ms |
4732 KB |
Output is correct |
18 |
Correct |
142 ms |
8576 KB |
Output is correct |
19 |
Correct |
143 ms |
8576 KB |
Output is correct |
20 |
Correct |
142 ms |
8576 KB |
Output is correct |
21 |
Correct |
147 ms |
8576 KB |
Output is correct |
22 |
Correct |
154 ms |
8576 KB |
Output is correct |
23 |
Correct |
177 ms |
8576 KB |
Output is correct |
24 |
Correct |
143 ms |
8576 KB |
Output is correct |