#include "bits/stdc++.h"
using namespace std;
using ld = long double;
#define int long long
#define ss second
#define ff first
#define pii pair <int, int>
#define undef -1
#define inf INT_MAX
#define PI acos((ld)-1);
#define NoTime ios::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void setIO(string str){
if(str == "") return;
freopen((str+".in").c_str(), "r", stdin);
freopen((str+".out").c_str(), "w", stdout);
}
vector <vector <int>> g;
vector <vector <int>> used;
int mn = -inf;
int it[] = {0, 0, 1, -1};
int jt[] = {1, -1, 0, 0};
void dfs(int i, int j, int dep, int xv, int nv){
used[i][j] = 1;
mn = max(mn, xv - nv - dep);
for(int to = 0; to < 4; to++){
int ni = i + it[to],
nj = j + jt[to];
if(!used[ni][nj] && g[ni][nj] != undef) dfs(ni, nj, dep + 1, max(xv, g[ni][nj]), min(nv, g[ni][nj]));
}
}
int32_t main(void){
NoTime
setIO("");
int n, m;
cin >> n >> m;
g.resize(n + 2, vector <int> (m + 2, undef));
used.resize(n + 2, vector <int> (m + 2));
//int a[n][m];
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++) cin >> g[i][j];
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
dfs(i, j, 0, g[i][j], g[i][j]);
used.assign(n + 2, vector <int> (m + 2, 0));
}
}
cout << mn;
return 'm' - 109;
}
Compilation message
maxcomp.cpp: In function 'void setIO(std::string)':
maxcomp.cpp:21:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen((str+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
maxcomp.cpp:22:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen((str+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |