Submission #890300

#TimeUsernameProblemLanguageResultExecution timeMemory
890300pccMaja (COCI18_maja)C++14
44 / 110
2088 ms628 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const ll inf = 4e18; const int mxn = 110; int n,m,step; ll arr[mxn][mxn]; ll dp[2][mxn][mxn]; bool roll = false; pii s; pii dir[] = {{-1,0},{1,0},{0,1},{0,-1}}; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n>>m>>s.fs>>s.sc>>step; for(int i = 1;i<=n;i++)for(int j = 1;j<=m;j++)cin>>arr[i][j]; for(auto &i:dp)for(auto &j:i)for(auto &k:j)k = -inf; dp[roll][s.fs][s.sc] = 0; for(int i = 1;i<=step;i++){ roll ^= 1; for(auto &i:dp[roll])for(auto &k:i)k = -inf; for(int j = 1;j<=n;j++){ for(int k = 1;k<=m;k++){ for(auto &d:dir){ int nr = j+d.fs,nc = k+d.sc; if(nr<=0||nc<=0||nr>n||nc>m)continue; dp[roll][nr][nc] = max(dp[roll][nr][nc],dp[roll^1][j][k]+arr[nr][nc]); } } } } cout<<dp[roll][s.fs][s.sc]; }
#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...