답안 #86101

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
86101 2018-11-25T01:02:55 Z Shtef Maja (COCI18_maja) C++14
66 / 110
2000 ms 1356 KB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long ll;

int n, m, x1, y1, k, odkud[5][105][105];
ll dp[5][105][105], c[105][105], sol;
const ll inf = 1e18;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};

int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> x1 >> y1 >> k;
for(int i = 1 ; i <= n ; ++i){
	for(int j = 1 ; j <= m ; ++j){
		cin >> c[i][j];
	}
}
for(int i = 1 ; i <= n ; ++i){
	for(int j = 1 ; j <= m ; ++j){
		for(int v = 0 ; v < 5 ; ++v){
			dp[v][i][j] = -inf;
		}
	}
}
for(int i = 0 ; i < 5 ; ++i){
	dp[i][x1][y1] = 0;
}
memset(odkud, -1, sizeof(odkud));
for(int i = 1 ; i <= min(k, 3 * n * m) ; ++i){
	for(int j = 1 ; j <= n ; ++j){
		for(int v = 1 ; v <= m ; ++v){
			for(int w = 0 ; w < 4 ; ++w){
				int nx = j + dx[w];
				int ny = v + dy[w];
				if(nx <= 0 || nx > n || ny <= 0 || ny > m)
					continue;
				if(dp[i % 5][nx][ny] < dp[(i - 1 + 5) % 5][j][v] + c[nx][ny]){
					odkud[i % 5][nx][ny] = w;
					dp[i % 5][nx][ny] = dp[(i - 1 + 5) % 5][j][v] + c[nx][ny];
				}
			}
		}
	}
	for(int j = 1 ; j <= n ; ++j){
		for(int v = 1 ; v <= m ; ++v){
			if(odkud[i % 5][j][v] == odkud[(i - 2 + 5) % 5][j][v]){
				int j1 = j - dx[odkud[i % 5][j][v]], v1 = v - dy[odkud[i % 5][j][v]];
				sol = max(sol, 2 * dp[(i - 2 + 5) % 5][j][v] + ((c[j][v] + c[j1][v1]) * ((k - (i - 2) * 2) / 2)) - c[j][v]);
			}
		}
	}
}
cout << (k <= 3 * n * m ? dp[k & 5][x1][y1] : sol) << endl;

return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Incorrect 3 ms 636 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 680 KB Output is correct
2 Correct 3 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 772 KB Output is correct
2 Correct 5 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 848 KB Output is correct
2 Correct 2 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 976 KB Output is correct
2 Correct 3 ms 976 KB Output is correct
3 Incorrect 1950 ms 1256 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1256 KB Output is correct
2 Execution timed out 2041 ms 1256 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1685 ms 1356 KB Output is correct
2 Execution timed out 2056 ms 1356 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 1356 KB Output is correct
2 Correct 196 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1356 KB Output is correct
2 Correct 9 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 1356 KB Output is correct
2 Correct 7 ms 1356 KB Output is correct