Submission #890300

# Submission time Handle Problem Language Result Execution time Memory
890300 2023-12-21T02:31:51 Z pcc Maja (COCI18_maja) C++14
44 / 110
2000 ms 628 KB
#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 time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 604 KB Output is correct
2 Correct 51 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 604 KB Output is correct
2 Correct 33 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 604 KB Output is correct
2 Correct 38 ms 628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2032 ms 604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2027 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2055 ms 604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2088 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2020 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2041 ms 604 KB Time limit exceeded
2 Halted 0 ms 0 KB -