제출 #229757

#제출 시각아이디문제언어결과실행 시간메모리
229757NONAMEMaja (COCI18_maja)C++17
11 / 110
89 ms640 KiB
#include <bits/stdc++.h> #define sz(x) int(x.size()) #define in(x) freopen(x, "r", stdin) #define out(x) freopen(x, "w", stdout) #define N 100500 #define oo ll(1e16) #define ft first #define sd second #define pb push_back #define ppb pop_back #define el '\n' #define elf endl #define base ll(1e9 + 7) using namespace std; typedef long long ll; typedef long double ld; int n, m, mx, k, a, b; ll f[2][101][101], c[101][101], res; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // in("input.txt"); cin >> n >> m >> a >> b >> k; a--; b--; k >>= 1; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> c[i][j]; mx = min(k, n * m); for (int t = 0; t <= 1; t++) for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) f[t][i][j] = -1; f[1][a][b] = 0; for (int t = 0; t < mx; t++) { int cur = t & 1; int lst = cur ^ 1; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) f[cur][i][j] = -1; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { if (f[lst][i][j] == -1) continue; if (i - 1 >= 0) f[cur][i - 1][j] = max(f[cur][i - 1][j], f[lst][i][j] + c[i][j]); if (j - 1 >= 0) f[cur][i][j - 1] = max(f[cur][i][j - 1], f[lst][i][j] + c[i][j]); if (i + 1 < n) f[cur][i + 1][j] = max(f[cur][i + 1][j], f[lst][i][j] + c[i][j]); if (j + 1 < m) f[cur][i][j + 1] = max(f[cur][i][j + 1], f[lst][i][j] + c[i][j]); } } int cur = (mx - 1) & 1; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (f[cur][i][j] != -1) res = max(res, 2 * f[cur][i][j] + c[i][j]); // for (int i = 0; i < n; i++) // for (int j = 0; j < m; j++) { // int t = k - mx; // // if (t <= 0) // continue; // // // } cout << res; }
#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...