# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
228996 |
2020-05-03T08:48:00 Z |
VEGAnn |
Maja (COCI18_maja) |
C++14 |
|
1864 ms |
34404 KB |
#include <bits/stdc++.h>
#define PB push_back
using namespace std;
typedef long long ll;
const int CNST = 2;
const ll N = 110;
const ll PW = 22;
int c[N][N], a, b, n, m, k;
ll ans[4 * N][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 (ll i = 0; i < n; i++)
for (ll j = 0; j < m; j++)
cin >> c[i][j];
ans[0][a][b] = 1;
int cnst = 2 * (n + m);
for (ll ite = 1; ite <= cnst; ite++){
// for (ll ite = 1; ite <= CNST; ite++){
for (ll i = 0; i < n; i++)
for (ll j = 0; j < m; j++){
if (ans[ite - 1][i][j] == 0) continue;
if (i > 0) MAX(ans[ite][i - 1][j], ans[ite - 1][i][j] + c[i - 1][j]);
if (j > 0) MAX(ans[ite][i][j - 1], ans[ite - 1][i][j] + c[i][j - 1]);
if (j + 1 < m) MAX(ans[ite][i][j + 1], ans[ite - 1][i][j] + c[i][j + 1]);
if (i + 1 < n) MAX(ans[ite][i + 1][j], ans[ite - 1][i][j] + c[i + 1][j]);
}
}
if (k <= cnst)
cout << ans[k][a][b] - 1 << '\n';
else {
ll res = 0;
for (ll i = 0; i < n; i++)
for (ll j = 0; j < m; j++) {
ll mx = 0;
if (i > 0) MAX(mx, c[i - 1][j]);
if (j > 0) MAX(mx, c[i][j - 1]);
if (j + 1 < m) MAX(mx, c[i][j + 1]);
if (i + 1 < n) MAX(mx, c[i + 1][j]);
mx += c[i][j];
for (ll st = 0; st <= cnst; st++)
for (ll ed = (st & 1); ed <= cnst; ed++){
// for (ll st = 0; st <= CNST; st++){
if (ans[st][i][j] == 0) continue;
if (ans[ed][i][j] == 0) continue;
if (st + ed > k) break;
ll cur = ans[st][i][j] - 1;
ll scr = ans[ed][i][j] - 1;
res = max(res, cur + scr + mx * (k - st - ed) / 2 - c[i][j]);
}
}
cout << res;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
768 KB |
Output is correct |
2 |
Correct |
6 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1024 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
5888 KB |
Output is correct |
2 |
Correct |
6 ms |
1280 KB |
Output is correct |
3 |
Incorrect |
1864 ms |
34404 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1792 KB |
Output is correct |
2 |
Correct |
543 ms |
18916 KB |
Output is correct |
3 |
Incorrect |
1826 ms |
32252 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
459 ms |
22400 KB |
Output is correct |
2 |
Correct |
719 ms |
24440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
5504 KB |
Output is correct |
2 |
Correct |
84 ms |
12544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2432 KB |
Output is correct |
2 |
Correct |
13 ms |
4096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
11904 KB |
Output is correct |
2 |
Correct |
7 ms |
1280 KB |
Output is correct |