Submission #1091161

# Submission time Handle Problem Language Result Execution time Memory
1091161 2024-09-20T01:21:40 Z TrinhKhanhDung Maja (COCI18_maja) C++14
11 / 110
63 ms 612 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)
#define double long double

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

const int MAX = 1e2 + 10;

int N, M, A, B, K;
int mat[MAX][MAX], sum[MAX][MAX];
ll dp[2][MAX][MAX];

void solve(){
    cin >> N >> M >> A >> B >> K;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= M; j++){
            cin >> mat[i][j];
        }
    }
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= M; j++){
            sum[i][j] = max({mat[i - 1][j], mat[i + 1][j], mat[i][j - 1], mat[i][j + 1]}) + mat[i][j];
        }
    }
    memset(dp[0], -0x3f, sizeof dp[0]);
    dp[0][A][B] = 0;
    ll ans = 0;
    for(int p = 1; p <= min(K / 2, N * M); p++){
        int id = p & 1;
        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= M; j++){
                dp[id][i][j] = max({dp[!id][i - 1][j], dp[!id][i][j - 1], dp[!id][i + 1][j], dp[!id][i][j + 1]}) + mat[i][j];
                maximize(ans, dp[id][i][j] * 2 - mat[i][j] + 1LL * sum[i][j] * ((K - 2 * p) / 2));
            }
        }
    }

    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
//     freopen("mst.inp","r",stdin);
//     freopen("mst.out","w",stdout);

    int t = 1;
//    cin >> t;
    while(t--){
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 600 KB Output is correct
2 Incorrect 7 ms 600 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -