답안 #461298

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
461298 2021-08-09T17:02:40 Z grt Maja (COCI18_maja) C++17
0 / 110
676 ms 580 KB
#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(k <= 10000) {
		cout << dp[a][b][0];
	} else {
		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;
	}
	
}
 
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 292 ms 388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 676 ms 556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 241 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 210 ms 580 KB Output isn't correct
2 Halted 0 ms 0 KB -