Submission #1060373

#TimeUsernameProblemLanguageResultExecution timeMemory
1060373peraMaxcomp (info1cup18_maxcomp)C++17
15 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int n , m , ans = 0; cin >> n >> m; vector<vector<int>> a(n + 1 , vector<int>(m + 1)) , mx(n + 2 , vector<int>(m + 2)); for(int i = 1;i <= n;i ++){ for(int j = 1;j <= m;j ++){ cin >> a[i][j]; } } auto Reset = [&](){ for(int i = 0;i <= n + 1;i ++){ for(int j = 0;j <= m + 1;j ++){ mx[i][j] = -1e9; } } }; Reset(); for(int i = 1;i <= n;i ++){ for(int j = 1;j <= m;j ++){ mx[i][j] = max({mx[i - 1][j] , mx[i][j - 1] , i + j - a[i][j]}); ans = max(ans , a[i][j] - i - j + mx[i][j]); } } Reset(); for(int i = 1;i <= n;i ++){ for(int j = m;j >= 1;j --){ mx[i][j] = max({mx[i - 1][j] , mx[i][j + 1] , i - j - a[i][j]}); ans = max(ans , a[i][j] - i + j + mx[i][j]); } } Reset(); for(int i = n;i >= 1;i --){ for(int j = 1;j <= m;j ++){ mx[i][j] = max({mx[i + 1][j] , mx[i][j - 1] , -i + j - a[i][j]}); ans = max(ans , a[i][j] + i - j + mx[i][j]); } } Reset(); for(int i = n;i >= 1;i --){ for(int j = m;j >= 1;j --){ mx[i][j] = max({mx[i + 1][j] , mx[i][j + 1] , -i - j - a[i][j]}); ans = max(ans , a[i][j] + i + j + mx[i][j]); } } cout << ans - 1 << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...