Submission #1060396

# Submission time Handle Problem Language Result Execution time Memory
1060396 2024-08-15T13:43:52 Z pera Maxcomp (info1cup18_maxcomp) C++17
100 / 100
254 ms 24664 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
main(){
   int n , m , ans = -1;
   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] = -1e16;
         }
      }
   };
   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] - 1});
         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] - 1});
         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] - 1});
         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] - 1});
         ans = max(ans , a[i][j] + i + j + mx[i][j]);
      }
   }
   cout << ans << endl;
}

Compilation message

maxcomp.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 254 ms 24504 KB Output is correct
19 Correct 222 ms 24664 KB Output is correct
20 Correct 218 ms 23380 KB Output is correct
21 Correct 215 ms 24660 KB Output is correct
22 Correct 219 ms 24660 KB Output is correct
23 Correct 249 ms 24500 KB Output is correct
24 Correct 227 ms 24620 KB Output is correct