제출 #1141850

#제출 시각아이디문제언어결과실행 시간메모리
1141850AgageldiMaxcomp (info1cup18_maxcomp)C++17
0 / 100
21 ms580 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define N 600005 #define pb push_back #define ff first #define ss second #define all(x) x.begin(),x.end() #define sz(s) (int)s.size() #define pii pair<int,int> //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll T, n, a[2000][2000], t, m, answer = -1, vis[2000][2000], dp[2000][2000]; vector <pair<int,int>> path, ans; void solve(int x,int y,ll mn,ll mx,int cnt) { vis[x][y] = 1; if(answer < mx - mn - cnt) { ans = path; } answer = max(answer,mx - mn - cnt); if(x+1 <= n && vis[x+1][y]==0){ path.pb({x+1,y}); solve(x + 1, y,min(mn,a[x + 1][y]),max(mx,a[x+1][y]),cnt+1); path.pop_back(); } if(x-1 >= 1 && vis[x-1][y]==0){ path.pb({x-1,y}); solve(x - 1, y,min(mn,a[x-1][y]),max(mx,a[x-1][y]),cnt+1); path.pop_back(); } if(y+1 <= m && vis[x][y+1]==0){ path.pb({x,y+1}); solve(x, y + 1,min(mn,a[x][y + 1]),max(mx,a[x][y + 1]),cnt+1); path.pop_back(); } if(y-1 >= 1 && vis[x][y-1]==0){ path.pb({x,y-1}); solve(x, y - 1,min(mn,a[x][y - 1]),max(mx,a[x][y - 1]),cnt+1); path.pop_back(); } vis[x][y] = 0; } int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> n >> m; for(int i = 1;i <= n;i++) { for(int j = 1;j <=m;j++) { cin >> a[i][j]; } } for(int i=1;i<=n;i++){ for(int j= 1;j<=m;j++) { if(dp[i][j]) continue; ans.clear(); solve(i,j,a[i][j],a[i][j],1); for(auto k:ans) { dp[k.ff][k.ss] = 1; } } } cout << answer << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...