답안 #1100206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100206 2024-10-13T09:45:48 Z vjudge1 Maxcomp (info1cup18_maxcomp) C++17
15 / 100
391 ms 524288 KB
//UNSTOPPABLE
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int,int>
#define tpii pair <pair <int,int> , int>
#define bruh cout << "NO\n"
using namespace std;
using namespace __gnu_pbds;
const int N = 1e3 + 5 , M = 1e6 + 5;
int mod = 1e9 + 7;
const int INF = 1e18;
int n,m,a[51][51],num[51][51],val[2501],used[2501];
vector <int> g[2501],dist[2501][2501];
void Goldik(){
	cin >> n >> m;
	int cur = 0;
	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= m ; j++){
			cin >> a[i][j];
			num[i][j] = ++cur;
			val[cur] = a[i][j];
		}
	}
	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= m ; j++){
			int x = num[i][j];
			if(i != 1){
				g[x].pb(num[i - 1][j]);
			}
			if(j != 1){
				g[x].pb(num[i][j - 1]);
			}
			if(i != n){
				g[x].pb(num[i + 1][j]);
			}
			if(j != m){
				g[x].pb(num[i][j + 1]);
			}
		}
	}
	for(int i = 1 ; i <= cur ; i++){
		for(int j = 1 ; j <= cur ; j++){
			dist[i][j].pb(INF);
		}
	}
	int ans = -INF;
	for(int i = 1 ; i <= cur ; i++){
		for(int j = 1 ; j <= cur ; j++) used[j] = 0;
		deque <int> q = {};
		q.pb(i);
		dist[i][i].clear();
		dist[i][i].pb(i);
		used[i] = 1;
		while(q.size()){
			int v = q.front();
			q.ppf();
			used[v] = 1;
			for(auto to : g[v]){
				if(!used[to]){
					if(dist[i][to].back() == INF || dist[i][to].size() > dist[i][v].size() + 1){
						dist[i][to] = dist[i][v];
						dist[i][to].pb(to);
						q.pb(to);
					}
				}
			}
		}
		for(int j = 1 ; j <= cur ; j++){
			if(i == j) continue;
			int mx = -INF , mn = INF;
			for(auto it : dist[i][j]){
				mx = max(mx , val[it]);
				mn = min(mn , val[it]);
			}
			ans = max(ans , mx - mn - (int)dist[i][j].size());
		}
	}
	cout << ans;
}
//rewai mnogo zadach vozmozhno odna iz nih gde to popadetsya
//returning winter prime?
//chem prowe tem luchshe
signed main(/*AZ AZDAN UZDIKSIZ*/){
	//freopen("txt.in","r",stdin);
	//freopen("txt.out","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	srand(time(0));
	int TT = 1;
	// cin >> TT;
	for(int i = 1 ; i <= TT ; i++){
		//cout << "Case " << i << ": ";
		Goldik();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 147280 KB Output is correct
2 Correct 23 ms 147280 KB Output is correct
3 Correct 23 ms 147376 KB Output is correct
4 Correct 23 ms 147428 KB Output is correct
5 Correct 24 ms 147280 KB Output is correct
6 Correct 23 ms 147280 KB Output is correct
7 Correct 23 ms 147452 KB Output is correct
8 Correct 24 ms 147288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 279 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 147280 KB Output is correct
2 Correct 23 ms 147280 KB Output is correct
3 Correct 23 ms 147376 KB Output is correct
4 Correct 23 ms 147428 KB Output is correct
5 Correct 24 ms 147280 KB Output is correct
6 Correct 23 ms 147280 KB Output is correct
7 Correct 23 ms 147452 KB Output is correct
8 Correct 24 ms 147288 KB Output is correct
9 Runtime error 391 ms 524288 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 147280 KB Output is correct
2 Correct 23 ms 147280 KB Output is correct
3 Correct 23 ms 147376 KB Output is correct
4 Correct 23 ms 147428 KB Output is correct
5 Correct 24 ms 147280 KB Output is correct
6 Correct 23 ms 147280 KB Output is correct
7 Correct 23 ms 147452 KB Output is correct
8 Correct 24 ms 147288 KB Output is correct
9 Runtime error 279 ms 524288 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -