Submission #228954

#TimeUsernameProblemLanguageResultExecution timeMemory
228954VEGAnnMaja (COCI18_maja)C++14
44 / 110
2087 ms512 KiB
#include <bits/stdc++.h> #define PB push_back using namespace std; typedef long long ll; const int N = 110; const int PW = 22; int c[N][N], a, b, n, m, k; ll ans[2][N][N]; void MAX(ll &x, ll y){ x = max(x, y); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> a >> b >> k; a--; b--; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> c[i][j]; ans[0][a][b] = 1; int it = 0; for (int ite = 1; ite <= k; ite++){ for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ans[it ^ 1][i][j] = 0; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++){ if (ans[it][i][j] == 0) continue; if (i > 0) MAX(ans[it ^ 1][i - 1][j], ans[it][i][j] + c[i - 1][j]); if (j > 0) MAX(ans[it ^ 1][i][j - 1], ans[it][i][j] + c[i][j - 1]); if (j + 1 < m) MAX(ans[it ^ 1][i][j + 1], ans[it][i][j] + c[i][j + 1]); if (i + 1 < n) MAX(ans[it ^ 1][i + 1][j], ans[it][i][j] + c[i + 1][j]); } it ^= 1; } cout << ans[it][a][b] - 1; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...