답안 #48551

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48551 2018-05-15T22:56:36 Z Pajaraja Maxcomp (info1cup18_maxcomp) C++17
100 / 100
256 ms 79944 KB
#include <bits/stdc++.h>
using namespace std;
int a[1007][1007],ul[1007][1007],ud[1007][1007],ll[1007][1007],ld[1007][1007];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&a[i][j]);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++)
	{
		ul[i][j]=-2000000000;
		if(i>0) ul[i][j]=fmax(ul[i][j],ul[i-1][j]);
		if(j>0) ul[i][j]=fmax(ul[i][j],ul[i][j-1]);
		ul[i][j]=fmax(ul[i][j],-a[i][j]+i+j);
	}
	for(int i=0;i<n;i++) for(int j=m-1;j>=0;j--)
	{
		ud[i][j]=-2000000000;
		if(i>0) ud[i][j]=fmax(ud[i][j],ud[i-1][j]);
		if(j<m-1) ud[i][j]=fmax(ud[i][j],ud[i][j+1]);
		ud[i][j]=fmax(ud[i][j],-a[i][j]+i-j);
	}
	for(int i=n-1;i>=0;i--) for(int j=0;j<m;j++)
	{
		ll[i][j]=-2000000000;
		if(i<n-1) ll[i][j]=fmax(ll[i][j],ll[i+1][j]);
		if(j>0) ll[i][j]=fmax(ll[i][j],ll[i][j-1]);
		ll[i][j]=fmax(ll[i][j],-a[i][j]-i+j);
	}
	for(int i=n-1;i>=0;i--) for(int j=m-1;j>=0;j--)
	{
		ld[i][j]=-2000000000;
		if(i<n-1) ld[i][j]=fmax(ld[i][j],ld[i+1][j]);
		if(j<m-1) ld[i][j]=fmax(ld[i][j],ld[i][j+1]);
		ld[i][j]=fmax(ld[i][j],-a[i][j]-i-j);
	}
	int sol=-2000000000;
	for(int i=0;i<n;i++) for(int j=0;j<m;j++)
	{
		sol=fmax(sol,a[i][j]-i-j+ul[i][j]);
		sol=fmax(sol,a[i][j]-i+j+ud[i][j]);
		sol=fmax(sol,a[i][j]+i-j+ll[i][j]);
		sol=fmax(sol,a[i][j]+i+j+ld[i][j]);
	}
	printf("%d",sol-1);
}

Compilation message

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:7: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:8:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&a[i][j]);
                                            ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
8 Correct 2 ms 792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 792 KB Output is correct
2 Correct 2 ms 792 KB Output is correct
3 Correct 2 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
8 Correct 2 ms 792 KB Output is correct
9 Correct 3 ms 1824 KB Output is correct
10 Correct 4 ms 1824 KB Output is correct
11 Correct 3 ms 1824 KB Output is correct
12 Correct 3 ms 1824 KB Output is correct
13 Correct 3 ms 2064 KB Output is correct
14 Correct 4 ms 2064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
8 Correct 2 ms 792 KB Output is correct
9 Correct 2 ms 792 KB Output is correct
10 Correct 2 ms 792 KB Output is correct
11 Correct 2 ms 848 KB Output is correct
12 Correct 3 ms 1824 KB Output is correct
13 Correct 4 ms 1824 KB Output is correct
14 Correct 3 ms 1824 KB Output is correct
15 Correct 3 ms 1824 KB Output is correct
16 Correct 3 ms 2064 KB Output is correct
17 Correct 4 ms 2064 KB Output is correct
18 Correct 253 ms 29124 KB Output is correct
19 Correct 256 ms 37712 KB Output is correct
20 Correct 240 ms 45900 KB Output is correct
21 Correct 256 ms 54392 KB Output is correct
22 Correct 255 ms 63060 KB Output is correct
23 Correct 255 ms 71532 KB Output is correct
24 Correct 216 ms 79944 KB Output is correct