답안 #364332

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
364332 2021-02-09T01:54:21 Z amunduzbaev Maxcomp (info1cup18_maxcomp) C++14
15 / 100
19 ms 364 KB
/** amunduzbaev **/

#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define x.fff get<0>(x)
//#define x.sss get<1>(x)
//#define x.ttt get<2>(x)
typedef long long ll;
#define int ll
typedef long double ld;
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<ll> vll;
typedef vector<int> vii;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}
 
const int N = 55; 
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);

#define MULTI 0

int n, m, k, ans, res, a[N][N], dis[N][N], mx[N][N], mn[N][N];

pii ch[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

void solve(int t_case){
	cin>>n>>m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++) cin>>a[i][j];
	
	//int res = 0;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			for(int i=0;i<n;i++) for(int j=0;j<m;j++) dis[i][j] = mod;
			queue<pii> qq;
			qq.push({i, j});
			dis[i][j] = 1, mx[i][j] = a[i][j], mn[i][j] = a[i][j];
			
			
			while(!qq.empty()){
				pii cur = qq.front();  qq.pop();
				for(int i=0;i<4;i++){
					pii tt = cur; tt.ff += ch[i].ff, tt.ss += ch[i].ss;
					if(tt.ff < 0 || tt.ss < 0 || tt.ff >= n || tt.ss >= m) continue;
					if(umin(dis[tt.ff][tt.ss], dis[cur.ff][cur.ss] + 1)){
						mx[tt.ff][tt.ss] = max(a[tt.ff][tt.ss], mx[cur.ff][cur.ss]);
						mn[tt.ff][tt.ss] = min(a[tt.ff][tt.ss], mn[cur.ff][cur.ss]);
						qq.push(tt);
					}else if((a[tt.ff][tt.ss] < mn[cur.ff][cur.ss] || a[tt.ff][tt.ss] > mx[cur.ff][cur.ss]) && dis[tt.ff][tt.ss] == dis[cur.ff][cur.ss] + 1){
						mx[tt.ff][tt.ss] = max(a[tt.ff][tt.ss], mx[cur.ff][cur.ss]);
						mn[tt.ff][tt.ss] = min(a[tt.ff][tt.ss], mn[cur.ff][cur.ss]);
						qq.push(tt);
					}
				}
			}
			
			for(int i=0;i<n;i++){
				for(int j=0;j<m;j++){
					umax(res, mx[i][j] - mn[i][j] - dis[i][j]);
				}
			}
			
			
			//for(int i=0;i<n;i++){
				//for(int j=0;j<m;j++){
					//cout<<dis[i][j]<<" ";
				//}
				//cout<<"\n";
			//}
			//cout<<"\n";
			
			//for(int i=0;i<n;i++){
				//for(int j=0;j<m;j++){
					//cout<<mn[i][j]<<" ";
				//}
				//cout<<"\n";
			//}
			//cout<<"\n";
			
			//for(int i=0;i<n;i++){
				//for(int j=0;j<n;j++){
					//cout<<mx[i][j]<<" ";
				//}
				//cout<<"\n";
			//}
			//cout<<"\n";
		}
	}
	cout<<res<<"\n";
}

signed main(){
	NeedForSpeed
	
	if(!MULTI) {
		solve(1);
	} else {
		int t; cin>>t;
		for(int t_case = 1; t_case <= t; t_case++) solve(t_case);
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 364 KB Output is correct
2 Correct 18 ms 364 KB Output is correct
3 Correct 19 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -