Submission #461302

#TimeUsernameProblemLanguageResultExecution timeMemory
461302grtMaja (COCI18_maja)C++17
0 / 110
665 ms900 KiB
#include <bits/stdc++.h> #define PB push_back #define ST first #define ND second #define _ ios_base::sync_with_stdio(0); cin.tie(0); //mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); using namespace std; using ll = long long; using pi = pair<int,int>; using vi = vector<int>; const int nax = 110; const ll INF = 1e18; int n, m, k, a, b; int c[nax][nax]; ll dp[nax][nax][2]; int dx[4] = {0,0,-1,1}; int dy[4] = {1,-1,0,0}; int main() {_ cin >> n >> m >> a >> b >> k; for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { cin >> c[i][j]; if(i == a && j == b) { dp[a][b][0] = 0; } else { dp[a][b][0] = -INF; } } } for(int s = 1; s <= min(10000, k); ++s) { for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { dp[i][j][s&1] = -INF; for(int d = 0; d < 4; ++d) { if(i + dx[d] > 0 && i + dx[d] <= n && j + dy[d] > 0 && j + dy[d] <= m) { dp[i][j][s&1] = max(dp[i][j][s&1],dp[i + dx[d]][j + dy[d]][1 - (s&1)] + c[i][j]); } } if(dp[i][j][s&1] < 0) dp[i][j][s&1] = -INF; } } } if(k <= 10000) { cout << dp[a][b][0]; } else { assert(false); ll ans = -INF; for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { for(int d = 0; d < 4; ++d) { if(i + dx[d] > 0 && i + dx[d] <= n && j + dy[d] > 0 && j + dy[d] <= m) { if((a + b) % 2 == (i + j) % 2) { ans = max(ans, dp[i][j][0] + dp[i + dx[d]][j + dy[d]][1]) + 1LL * ((k - 20000) / 2) * (c[i][j] + c[i + dx[d]][j + dy[d]]); } } } } } cout << ans; } }
#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...