답안 #317106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317106 2020-10-29T03:28:48 Z Seanliu Maxcomp (info1cup18_maxcomp) C++14
15 / 100
5 ms 8448 KB
#include <iostream>
#define int long long int
using namespace std;

const int maxN = 1e3 + 326, INF = 2e15;

int N, M, arr[maxN][maxN], dp[maxN], nxt[maxN], mx[maxN], nxtmx[maxN], r, narr[maxN][maxN]; 

int solve(){
	for(int i = 0; i < M; i++) dp[i] = nxt[i] = mx[i] = nxtmx[i] = -INF;
	int ans = 0;
	for(int i = 0; i < M; i++){
		dp[i] = -arr[0][i] + i - 1;
		mx[i] = dp[i];
		if(i){
			mx[i] = max(mx[i], mx[i - 1]);
			ans = max(ans, arr[0][i] - i + mx[i - 1]);
		}
	}
	for(int i = 1; i < N; i++){
		for(int j = 0; j < M; j++){
			dp[j] = -arr[i][j] + i + j - 1;	
			nxtmx[j] = max(mx[j], dp[j]);
			ans = max(ans, arr[i][j] - i - j + mx[j]);
			if(j){
				nxtmx[j] = max(nxtmx[j], nxtmx[j - 1]);
				ans = max(ans, arr[i][j] - i - j + nxtmx[j - 1]);
			}
			//cout << "Pre for " << i << ", " << j << " = " << nxtmx[j] << endl;
		}
		for(int j = 0; j < M; j++) mx[j] = nxtmx[j];
	}
	return ans;
}

void rot(){
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			narr[j][N - i - 1] = arr[i][j];	
			//cout << "narr[" << j << "][" << N - i - 1 << "] = " << arr[i][j] << endl;
		}
	}
	swap(N, M);
	for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) arr[i][j] = narr[i][j];
}

signed main(){
	cin >> N >> M;
	for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) cin >> arr[i][j];
	for(int i = 0; i < 4; i++){
		r = max(r, solve());
		/*
		for(int j = 0; j < N; j++){
			for(int k = 0; k < M; k++){
				cout << arr[j][k] << " ";
			}
			cout << endl;
		}
		*/
		rot();
	}
	cout << r << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8448 KB Output is correct
2 Correct 5 ms 8448 KB Output is correct
3 Correct 5 ms 8448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -