# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
229077 |
2020-05-03T10:47:24 Z |
Vimmer |
Maja (COCI18_maja) |
C++14 |
|
112 ms |
65540 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[101][101][101][101], mx[101][101][205], ans;
int ar[101][101];
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);
ll 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];
for (int x = 1; x <= n; x++)
for (int y = 1; y <= m; y++)
{
dp[x][y][x][y] = ar[x][y];
for (int i = x; i <= n; i++)
for (int j = y; j <= m; j++)
{
if (i == x && j == y) continue;
dp[x][y][i][j] = max(dp[x][y][i][j], ll(ar[i][j]) + max((i - 1 >= x ? dp[x][y][i - 1][j] : 0), (j - 1 >= y ? dp[x][y][i][j - 1] : 0)));
}
for (int i = x; i >= 1; i--)
for (int j = y; j >= 1; j--)
{
if (i == x && j == y) continue;
dp[x][y][i][j] = max(dp[x][y][i][j], ll(ar[i][j]) + max((i + 1 <= x ? dp[x][y][i + 1][j] : 0), (j + 1 <= y ? dp[x][y][i][j + 1] : 0)));
}
for (int i = x; i >= 1; i--)
for (int j = y; j <= m; j++)
{
if (i == x && j == y) continue;
dp[x][y][i][j] = max(dp[x][y][i][j], ll(ar[i][j]) + max((i + 1 <= x ? dp[x][y][i + 1][j] : 0), (j - 1 >= y ? dp[x][y][i][j - 1] : 0)));
}
for (int i = x; i <= n; i++)
for (int j = y; j >= 1; j--)
{
if (i == x && j == y) continue;
dp[x][y][i][j] = max(dp[x][y][i][j], ll(ar[i][j]) + max((i - 1 >= x ? dp[x][y][i - 1][j] : 0), (j + 1 <= y ? dp[x][y][i][j + 1] : 0)));
}
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
for (int x = 1; x <= n; x++)
for (int y = 1; y <= m; y++)
{
int rst = abs(x - i) + abs(y - j);
if (i == x && j == y) continue;
mx[i][j][rst] = max(mx[i][j][rst], dp[i][j][x][y]);
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
for (int x = 1; x <= n; x++)
for (int y = 1; y <= m; y++)
{
if (x == i && y == j) continue;
ll rst = abs(a - i) + abs(b - j);
if (rst * 2 > k) continue;
ll sum = 2 * dp[a][b][i][j];
ll kol = k - (rst * 2);
ll rs = abs(i - x) + abs(j - y);
if (rs * 2 > kol) continue;
ll kl = kol / rs;
if (kl % 2) kl--;
sum += kl * dp[i][j][x][y];
sum -= kl * ll(ar[i][j] + ar[x][y]);
sum += (kl / 2) * ll(ar[x][y]);
sum += ((kl / 2) - 1) * ll(ar[i][j]);
kol -= kl * rs;
sum += mx[i][j][kol / 2];
ans = max(ans, sum);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1792 KB |
Output is correct |
2 |
Correct |
6 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1536 KB |
Output is correct |
2 |
Correct |
9 ms |
4352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2560 KB |
Output is correct |
2 |
Correct |
5 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
58232 KB |
Output is correct |
2 |
Correct |
7 ms |
3328 KB |
Output is correct |
3 |
Runtime error |
99 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
4480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
68 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
53572 KB |
Output is correct |
2 |
Runtime error |
64 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
13952 KB |
Output is correct |
2 |
Correct |
18 ms |
13952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
58 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |