# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
127570 |
2019-07-09T15:15:30 Z |
Vlatko |
Maja (COCI18_maja) |
C++14 |
|
1367 ms |
760 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll inf = 1e9;
const int maxn = 100;
int di[4] = {-1, 0, 1, 0};
int dj[4] = {0, 1, 0, -1};
int N, M, A, B;
ll K, T;
ll C[maxn][maxn];
// dp[k][i][j] = max sum for path to here after k steps
ll cur[maxn][maxn];
ll nxt[maxn][maxn];
void dp_step() {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
nxt[i][j] = -inf;
for (int d = 0; d < 4; ++d) {
int i1 = i + di[d], j1 = j + dj[d];
if (i1 >= 0 && i1 < N && j1 >= 0 && j1 < M) {
nxt[i][j] = max(nxt[i][j], cur[i1][j1] + C[i][j]);
}
}
}
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
cur[i][j] = nxt[i][j];
}
}
}
void simulate() {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
ll gains = -inf;
for (int d = 0; d < 4; ++d) {
int i1 = i + di[d], j1 = j + dj[d];
if (i1 >= 0 && i1 < N && j1 >= 0 && j1 < M) {
gains = max(gains, C[i1][j1] + C[i][j]);
}
}
cur[i][j] += gains * (K - 2*T) / 2;
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> M >> A >> B >> K;
--A, --B;
T = N * M * 2;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
cin >> C[i][j];
cur[i][j] = -inf;
}
}
cur[A][B] = 0;
if (2*T >= K) {
for (int i = 0; i < K; ++i) {
dp_step();
}
} else {
// T steps, simulate going back and forth, T steps again
for (int i = 0; i < T; ++i) {
dp_step();
}
simulate();
for (int i = 0; i < T; ++i) {
dp_step();
}
}
cout << cur[A][B] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
249 ms |
480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1367 ms |
760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
183 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
130 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |