제출 #1222934

#제출 시각아이디문제언어결과실행 시간메모리
1222934VMaksimoski008Maxcomp (info1cup18_maxcomp)C++20
100 / 100
327 ms16132 KiB
#include <bits/stdc++.h> #define ar array //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const ll inf = 1e18; const int N = 1e3 + 5; int n, m, a[N][N], dp1[N][N], dp2[N][N]; void rotate() { int b[m+1][n+1]; for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) b[j][n-i+1] = a[i][j]; for(int i=1; i<=m; i++) for(int j=1; j<=n; j++) a[i][j] = b[i][j]; swap(n, m); } int solve() { int ans = -1; for(int i=0; i<=n; i++) for(int j=0; j<=m; j++) dp1[i][j] = dp2[i][j] = -2e9; for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) { dp1[i][j] = max(dp1[i-1][j], dp1[i][j-1]); dp2[i][j] = max(dp2[i-1][j], dp2[i][j-1]); dp1[i][j] = max(dp1[i][j], -a[i][j] + i + j); dp2[i][j] = max(dp2[i][j], a[i][j] + i + j); ans = max(ans, dp1[i][j] + a[i][j] - i - j - 1); ans = max(ans, dp2[i][j] - a[i][j] - i - j - 1); } } return ans; } signed main() { cin >> n >> m; for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) cin >> a[i][j]; int ans = -1; for(int i=0; i<4; i++) { ans = max(ans, solve()); rotate(); } cout << ans << '\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...