This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimization("g", on)
#pragma GCC optimize ("inline")
#pragma GCC optimization("03")
#pragma GCC optimization("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 1e2 + 5;
const int inf = 1e9+7;
int n, m, dist, a[N][N], cur, mx, ans = -inf;
bool used[N][N];
void rec(int i, int j, int mn){
dist++;
used[i][j] = 1;
if(cur <= dist) {used[i][j] = 0;dist--;return;}
if(cur >= mn + dist){
cur = mn + dist;
}
if(a[i][j + 1] <= mx && !used[i][j + 1]){
rec(i, j + 1, min(mn, a[i][j + 1]));
}
if(a[i][j - 1] <= mx && !used[i][j - 1]){
rec(i, j - 1, min(mn, a[i][j - 1]));
}
if(a[i + 1][j] <= mx && !used[i + 1][j]){
rec(i + 1, j, min(mn, a[i + 1][j]));
}
if(a[i - 1][j] <= mx && !used[i - 1][j]){
rec(i - 1, j, min(mn, a[i - 1][j]));
}
used[i][j] = 0;
dist--;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i){
a[i][0] = inf;
a[i][m + 1] = inf;
for(int j = 1; j <= m; ++j){
cin >> a[i][j];
}
}
for(int j = 1; j <= m; ++j){
a[0][j] = inf;
a[n + 1][j] = inf;
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= m; ++j){
// memset(used, 0, sizeof(used));
if(ans >= a[i][j]) continue;
mx = a[i][j];
cur = inf;
rec(i, j, a[i][j]);
// cout << cur << ' ' << a[i][j] << '\n';
ans = max(a[i][j] - cur, ans);
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
maxcomp.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization("g", on)
|
maxcomp.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
5 | #pragma GCC optimization("03")
|
maxcomp.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
6 | #pragma GCC optimization("unroll-loops")
|
maxcomp.cpp:7: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
7 | #pragma comment(linker, "/stack:200000000")
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |