Submission #317110

# Submission time Handle Problem Language Result Execution time Memory
317110 2020-10-29T03:34:32 Z Seanliu Maxcomp (info1cup18_maxcomp) C++14
60 / 100
500 ms 21240 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 = -1, narr[maxN][maxN]; 
 
int solve(){
	for(int i = 0; i < M; i++) dp[i] = nxt[i] = mx[i] = nxtmx[i] = -INF;
	int ans = -INF;
	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 < 5; 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8448 KB Output is correct
2 Correct 5 ms 8448 KB Output is correct
3 Correct 6 ms 8448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 5 ms 8448 KB Output is correct
10 Correct 5 ms 8448 KB Output is correct
11 Correct 6 ms 8448 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 3 ms 768 KB Output is correct
16 Correct 3 ms 768 KB Output is correct
17 Correct 2 ms 768 KB Output is correct
18 Execution timed out 790 ms 21240 KB Time limit exceeded
19 Halted 0 ms 0 KB -