Submission #197117

# Submission time Handle Problem Language Result Execution time Memory
197117 2020-01-18T21:04:09 Z Redhood Maxcomp (info1cup18_maxcomp) C++14
100 / 100
173 ms 14604 KB
#include<bits/stdc++.h>
#define rep(i,x) for(int i = 0; i < x; ++i)
using namespace std;

const int inf = 2e9;
signed main(){
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n , m;
    cin >> n >> m;
    vector <vector<int>> a(n,vector<int>(m));
    rep(i , n)
        rep(j , m)
            cin >> a[i][j];
    int answer = 0;
    vector<vector<int>>best;
    /// 1 zone

    best = vector<vector<int>>(n,vector<int>(m,inf));
    for(int i = 0; i < n; ++i){
        for(int j = m - 1; j >= 0; --j){
            if(i>0)best[i][j]=min(best[i][j],best[i-1][j]);
            if(j<m-1)best[i][j]=min(best[i][j],best[i][j+1]);
            best[i][j]=min(best[i][j],a[i][j]-i+j);
        }
    }

    rep(i,n)
        rep(j , m)
            answer = max(answer , a[i][j]-i+j-best[i][j]);
    /// 2 zone
    best = vector<vector<int>>(n,vector<int>(m,inf));
    for(int i = n-1; i >=0; --i){
        for(int j = m - 1; j >= 0; --j){
            if(i<n-1)best[i][j]=min(best[i][j],best[i+1][j]);
            if(j<m-1)best[i][j]=min(best[i][j],best[i][j+1]);
            best[i][j]=min(best[i][j],a[i][j]+i+j);
        }
    }
    rep(i,n)
        rep(j , m)
            answer = max(answer , a[i][j]+i+j-best[i][j]);
    /// 3 zone
    best = vector<vector<int>>(n,vector<int>(m,inf));
    for(int i = n-1; i >=0; --i){
        for(int j = 0; j < m; ++j){
            if(i<n-1)best[i][j]=min(best[i][j],best[i+1][j]);
            if(j>0)best[i][j]=min(best[i][j],best[i][j-1]);
            best[i][j]=min(best[i][j],a[i][j]+i-j);
        }
    }
    rep(i,n)
        rep(j , m)
            answer = max(answer , a[i][j]+i-j-best[i][j]);
    /// 4 zone
    best = vector<vector<int>>(n,vector<int>(m,inf));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            if(i>0)best[i][j]=min(best[i][j],best[i-1][j]);
            if(j>0)best[i][j]=min(best[i][j],best[i][j-1]);
            best[i][j]=min(best[i][j],a[i][j]-i-j);
        }
    }
    rep(i,n)
        rep(j , m)
            answer = max(answer , a[i][j]-i-j-best[i][j]);
    cout << answer - 1;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 168 ms 12140 KB Output is correct
19 Correct 171 ms 12552 KB Output is correct
20 Correct 161 ms 13952 KB Output is correct
21 Correct 172 ms 14400 KB Output is correct
22 Correct 172 ms 14224 KB Output is correct
23 Correct 172 ms 14604 KB Output is correct
24 Correct 173 ms 13952 KB Output is correct