Submission #67012

# Submission time Handle Problem Language Result Execution time Memory
67012 2018-08-13T08:12:26 Z ekrem Maxcomp (info1cup18_maxcomp) C++
60 / 100
500 ms 36328 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define inf 2000000007
#define N 1005
using namespace std;

int n, m, ans = -inf, a[N][N], dp[N][N][4][2];
int o[] = {-1, 0, 1, 0};
int p[] = {0, 1, 0, -1};

int f(int i, int j, int yon, int dur){
	int &r = dp[i][j][yon][dur];
	if(r != -inf)
		return r;
	if(i < 1 or j < 1 or i > n or j > m)
		return -inf + 1;
	if(dur == 0){
		if(a[i][j] > f(i + o[yon], j + p[yon], yon, dur) - 1)
			r = a[i][j];
		else
			r = f(i + o[yon], j + p[yon], yon, dur) - 1;
	}
	if(dur == 1){
		if(-a[i][j] > f(i + o[yon], j + p[yon], yon, dur) - 1)
			r = -a[i][j];
		else
			r = f(i + o[yon], j + p[yon], yon, dur) - 1;
	}
	return r;
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d",&n ,&m);

	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			scanf("%d",&a[i][j]);
	for(int i = 0; i <= n + 1; i++)
		for(int j = 0; j <= m + 1; j++)
			for(int yon = 0; yon <= 3; yon++)
				for(int dur = 0; dur <= 1; dur++)
					dp[i][j][yon][dur] = -inf;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			for(int yon = 0; yon <= 3; yon++)
				for(int dur = 0; dur <= 1; dur++)
					f(i, j, yon, dur);

	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			for(int l = 0; l <= 3; l++)
				for(int k = 0; k <= 3; k++)
					if(l != k)
						ans = max(ans, dp[i][j][l][0] + dp[i][j][k][1] - 1 );

	printf("%d\n",ans);
	return 0;
}

Compilation message

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n ,&m);
  ~~~~~^~~~~~~~~~~~~~~~
maxcomp.cpp:42:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&a[i][j]);
    ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 3 ms 524 KB Output is correct
7 Correct 3 ms 524 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 668 KB Output is correct
2 Correct 2 ms 744 KB Output is correct
3 Correct 2 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 3 ms 524 KB Output is correct
7 Correct 3 ms 524 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 4 ms 1000 KB Output is correct
10 Correct 4 ms 1000 KB Output is correct
11 Correct 4 ms 1012 KB Output is correct
12 Correct 4 ms 1012 KB Output is correct
13 Correct 3 ms 1012 KB Output is correct
14 Correct 5 ms 1012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 3 ms 524 KB Output is correct
7 Correct 3 ms 524 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 4 ms 668 KB Output is correct
10 Correct 2 ms 744 KB Output is correct
11 Correct 2 ms 744 KB Output is correct
12 Correct 4 ms 1000 KB Output is correct
13 Correct 4 ms 1000 KB Output is correct
14 Correct 4 ms 1012 KB Output is correct
15 Correct 4 ms 1012 KB Output is correct
16 Correct 3 ms 1012 KB Output is correct
17 Correct 5 ms 1012 KB Output is correct
18 Correct 452 ms 36328 KB Output is correct
19 Execution timed out 544 ms 36328 KB Time limit exceeded
20 Halted 0 ms 0 KB -