// #pragma comment(linker, "\stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcount,abm,mmx,avx,avx2,tune=native")
//#pragma GCC target("avx,avx2")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("O3")
// #pragma GCC optimization("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
using namespace __gnu_pbds;
typedef
tree<
ll,
null_type,
less_equal<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
const ll INF = 1e16;
const int lim = 450;
int n, m, a[N][N], more1[N][N], less1[N][N];
int main() {
// ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("input.in", "r", stdin);
// freopen("input.out", "w", stdout);
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
scanf("%d", &a[i][j]);
int ans = -1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
more1[i][j] = a[i][j] + i + j;
if (i != 1)
more1[i][j] = max(more1[i][j], more1[i - 1][j]);
if (j != 1)
more1[i][j] = max(more1[i][j], more1[i][j - 1]);
less1[i][j] = -a[i][j] + i + j;
if (i != 1)
less1[i][j] = max(less1[i][j], less1[i - 1][j]);
if (j != 1)
less1[i][j] = max(less1[i][j], less1[i][j - 1]);
ans = max(ans, a[i][j] + less1[i][j] - i - j - 1);
// cout << i << " " << j << " " << ans << endl;
ans = max(ans, -a[i][j] + more1[i][j] - i - j - 1);
// cout << i << " " << j << " " << ans << endl;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m / 2; j++)
swap(a[i][j], a[i][m - j + 1]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
more1[i][j] = a[i][j] + i + j;
if (i != 1)
more1[i][j] = max(more1[i][j], more1[i - 1][j]);
if (j != 1)
more1[i][j] = max(more1[i][j], more1[i][j - 1]);
less1[i][j] = -a[i][j] + i + j;
if (i != 1)
less1[i][j] = max(less1[i][j], less1[i - 1][j]);
if (j != 1)
less1[i][j] = max(less1[i][j], less1[i][j - 1]);
ans = max(ans, a[i][j] + less1[i][j] - i - j - 1);
// cout << i << " " << j << " " << ans << endl;
ans = max(ans, -a[i][j] + more1[i][j] - i - j - 1);
// cout << i << " " << j << " " << ans << endl;
}
printf("%d", ans);
}
Compilation message
maxcomp.cpp: In function 'int main()':
maxcomp.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:51:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i][j]);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
5 ms |
948 KB |
Output is correct |
11 |
Correct |
5 ms |
896 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
6 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
948 KB |
Output is correct |
14 |
Correct |
5 ms |
896 KB |
Output is correct |
15 |
Correct |
5 ms |
896 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
6 ms |
896 KB |
Output is correct |
18 |
Correct |
223 ms |
12280 KB |
Output is correct |
19 |
Correct |
210 ms |
20728 KB |
Output is correct |
20 |
Correct |
195 ms |
20476 KB |
Output is correct |
21 |
Correct |
210 ms |
20768 KB |
Output is correct |
22 |
Correct |
199 ms |
20728 KB |
Output is correct |
23 |
Correct |
211 ms |
20728 KB |
Output is correct |
24 |
Correct |
172 ms |
20988 KB |
Output is correct |