# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
229133 |
2020-05-03T12:48:56 Z |
Vimmer |
Maja (COCI18_maja) |
C++14 |
|
6 ms |
640 KB |
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) ll(x.size())
#define pb push_back
#define N 100005
#define MOD ll(998244353)
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef short int si;
//typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll dp[105][105], ar[105][105], ans;
int main()
{
// freopen("input.txt", "r", stdin);// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m, a, b, k;
cin >> n >> m >> a >> b >> k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cin >> ar[i][j];
dp[a][b] = 0;
for (int i = a; i <= n; i++)
for (int j = b; j <= m; j++)
{
if (i == a && j == b) continue;
dp[i][j] = max(dp[i][j], ar[i][j] + max((i - 1 >= a ? dp[i - 1][j] : 0), (j - 1 >= b ? dp[i][j - 1] : 0)));
}
for (int i = a; i >= 1; i--)
for (int j = b; j >= 1; j--)
{
if (i == a && j == b) continue;
dp[i][j] = max(dp[i][j], ar[i][j] + max((i + 1 <= a ? dp[i + 1][j] : 0), (j + 1 <= b ? dp[i][j + 1] : 0)));
}
for (int i = a; i >= 1; i--)
for (int j = b; j <= m; j++)
{
if (i == a && j == b) continue;
dp[i][j] = max(dp[i][j], ar[i][j] + max((i + 1 <= a ? dp[i + 1][j] : 0), (j - 1 >= b ? dp[i][j - 1] : 0)));
}
for (int i = a; i <= n; i++)
for (int j = b; j >= 1; j--)
{
if (i == a && j == b) continue;
dp[i][j] = max(dp[i][j], ar[i][j] + max((i - 1 >= a ? dp[i - 1][j] : 0), (j + 1 <= b ? dp[i][j + 1] : 0)));
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
if (i == a && j == b) continue;
int rst = abs(a - i) + abs(b - j);
if (rst * 2 > k) continue;
ll sum = 2 * dp[i][j];
ll kol = k - (rst * 2);
ll mx = 0;
if (i - 1 != 0) mx = max(mx, ar[i - 1][j]);
if (j - 1 != 0) mx = max(mx, ar[i][j - 1]);
if (i + 1 != n) mx = max(mx, ar[i + 1][j]);
if (j + 1 != m) mx = max(mx, ar[i][j + 1]);
kol /= 2;
sum += mx * kol;
sum += ar[i][j] * (kol - 1);
ans = max(ans, sum);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Incorrect |
6 ms |
640 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |