답안 #234780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234780 2020-05-25T14:28:44 Z super_j6 Maja (COCI18_maja) C++14
0 / 110
6 ms 1024 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int maxn = 100;
int n, m, sx, sy, k, nm;
ll a[maxn][maxn];
ll dp[2][maxn][maxn];

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool works(int x, int y){
    return x >= 0 && y >= 0 && x < n && y < m;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> sx >> sy >> k;
	sx--, sy--;
    nm = min(n * m, k / 2);
	
	for(int i = 0; i < n; i++)
	for(int j = 0; j < m; j++){
	    cin >> a[i][j];
	}
	
	memset(dp[0], -1, sizeof(dp[0]));
	dp[0][sx][sy] = 0;
	for(int l = 0; l < nm; l++){
	    memset(dp[(l & 1) ^ 1], -1, sizeof(dp[(l & 1) ^ 1]));
    	for(int i = 0; i < n; i++)
    	for(int j = 0; j < m; j++){
    	    if(dp[i][j][l & 1] == -1) continue;
        	for(int f = 0; f < 4; f++){
        	    int x = i + dx[f], y = j + dy[f];
        	    if(works(x, y)){
        	        dp[(l & 1) ^ 1][x][y] = max(dp[(l & 1) ^ 1][x][y],
        	            dp[l & 1][i][j] + a[x][y]);
        	    }
        	}
    	}
	}
	
	ll ret = 0;
	for(int i  = 0; i < n; i++)
	for(int j = 0; j < m; j++){
	    if(dp[nm & 1][i][j] == -1) continue;
	    for(int f = 0; f < 4; f++){
	        int x = i + dx[f], y = j + dy[f];
	        if(works(x, y)){
	            ret = max(ret, 2 * dp[nm & 1][i][j] + 
	                (k - 2 * nm) / 2 * (a[i][j] + a[x][y]) - a[i][j]);
	        }
	    }
	}
	
	cout << ret << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -