Submission #66994

# Submission time Handle Problem Language Result Execution time Memory
66994 2018-08-13T07:43:35 Z hamzqq9 Maxcomp (info1cup18_maxcomp) C++14
15 / 100
4 ms 652 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 1000000000
#define MOD 1000000007
#define N 1005
#define MAX 10000006
#define LOG 22
using namespace std;

int n,m,a[N][N],p1[N][N];
int ans=-inf;
int add[4][2]={-1,-1,-1,1,1,-1,1,1};

void check(int cur) {

	for(int i=1;i<=n;i++) {

		for(int j=1;j<=m;j++) {

			umax(ans,a[i][j]+p1[i][j]+add[cur][0]*i+add[cur][1]*j-1);

		}

	}

}

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

	for(int i=0;i<=n+1;i++) for(int j=0;j<=m+1;j++) p1[i][j]=-inf;

	for(int i=1;i<=n;i++) {

		for(int j=1;j<=m;j++) {

			scanf("%d",&a[i][j]);

		}

	}

	for(int i=1;i<=n;i++) {

		for(int j=1;j<=m;j++) {

			p1[i][j]=-inf;

			umax(p1[i][j],max(p1[i-1][j],p1[i][j-1]));
			umax(p1[i][j],-a[i][j]+i+j);

		}

	}

	check(0);

	//printf("Cur ans-->%d\n",ans);

	for(int i=1;i<=n;i++) {

		for(int j=m;j>=1;j--) {

			p1[i][j]=-inf;

			umax(p1[i][j],max(p1[i-1][j],p1[i][j+1]));
			umax(p1[i][j],-a[i][j]+i-j);

		}

	} 

	check(1);

//	printf("Cur ans-->%d\n",ans);
	for(int i=n;i>=1;i--) {

		for(int j=1;j<=m;j++) {

			p1[i][j]=-inf;

			umax(p1[i][j],max(p1[i+1][j],p1[i][j-1]));
			umax(p1[i][j],-a[i][j]-i+j);

		}

	}

	check(2);

//	printf("Cur ans-->%d\n",ans);
	for(int i=n;i>=1;i--) {

		for(int j=m;j>=1;j--) {

			p1[i][j]=-inf;

			umax(p1[i][j],max(p1[i+1][j],p1[i][j+1]));
			umax(p1[i][j],-a[i][j]-i-j);

		}

	}

	check(3);
//	printf("Cur ans-->%d\n",ans);

	printf("%d",ans);

} 	

Compilation message

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:46: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:54: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 4 ms 448 KB Output is correct
3 Incorrect 3 ms 448 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 476 KB Output is correct
2 Correct 3 ms 524 KB Output is correct
3 Correct 3 ms 652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 448 KB Output is correct
3 Incorrect 3 ms 448 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 448 KB Output is correct
3 Incorrect 3 ms 448 KB Output isn't correct
4 Halted 0 ms 0 KB -