Submission #765303

# Submission time Handle Problem Language Result Execution time Memory
765303 2023-06-24T10:34:52 Z Ahmed57 Maxcomp (info1cup18_maxcomp) C++17
100 / 100
112 ms 68092 KB
#include<bits/stdc++.h>
using namespace std;
long long mx1[3001][3001],mx2[3001][3001],mx3[3001][3001],mx4[3001][3001];
long long arr[3001][3001];
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;cin>>n>>m;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            cin>>arr[i][j];
        }
    }
    long long inf = 1e18;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            mx1[i][j] = min(arr[i][j],(j?mx1[i][j-1]+1:inf));
        }
    }
    for(int j = 0;j<m;j++){
        for(int i = 0;i<n;i++){
            mx1[i][j] = min(mx1[i][j],(i?mx1[i-1][j]+1:inf));
        }
    }
    for(int i = 0;i<n;i++){
        for(int j = m-1;j>=0;j--){
            mx2[i][j] = min(arr[i][j],(j<(m-1)?mx2[i][j+1]+1:inf));
        }
    }
    for(int j = m-1;j>=0;j--){
        for(int i = 0;i<n;i++){
            mx2[i][j] = min(mx2[i][j],(i?mx2[i-1][j]+1:inf));
        }
    }
    for(int i = n-1;i>=0;i--){
        for(int j = 0;j<m;j++){
            mx3[i][j] = min(arr[i][j],(j?mx3[i][j-1]+1:inf));
        }
    }
    for(int j = 0;j<m;j++){
        for(int i = n-1;i>=0;i--){
            mx3[i][j] = min(mx3[i][j],(i<(n-1)?mx3[i+1][j]+1:inf));
        }
    }
    for(int i = n-1;i>=0;i--){
        for(int j = m-1;j>=0;j--){
            mx4[i][j] = min(arr[i][j],(j<(m-1)?mx4[i][j+1]+1:inf));
        }
    }
    for(int j = m-1;j>=0;j--){
        for(int i = n-1;i>=0;i--){
            mx4[i][j] = min(mx4[i][j],(i<(n-1)?mx4[i+1][j]+1:inf));
        }
    }
    long long ans = 0;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            ans = max(ans,arr[i][j]-min({mx1[i][j],mx2[i][j],mx3[i][j],mx4[i][j]}));
        }
    }
    cout<<ans-1<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 1364 KB Output is correct
10 Correct 1 ms 1488 KB Output is correct
11 Correct 1 ms 1360 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 1 ms 1488 KB Output is correct
14 Correct 1 ms 1360 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
16 Correct 1 ms 1364 KB Output is correct
17 Correct 1 ms 1364 KB Output is correct
18 Correct 112 ms 68092 KB Output is correct
19 Correct 110 ms 68088 KB Output is correct
20 Correct 107 ms 65916 KB Output is correct
21 Correct 108 ms 68036 KB Output is correct
22 Correct 105 ms 67996 KB Output is correct
23 Correct 105 ms 68088 KB Output is correct
24 Correct 102 ms 65808 KB Output is correct