답안 #334531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334531 2020-12-09T10:32:31 Z nandonathaniel Maxcomp (info1cup18_maxcomp) C++14
100 / 100
182 ms 28780 KB
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;
int a[1005][1005],dp[4][1005][1005];

int kecil(int a,int b,int c,int d){
	return min(a,min(b,min(c,d)));
}

int main(){
	int n,m;
	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=1;i<=m;i++){
		for(int j=0;j<4;j++){
			dp[j][0][i]=INF;
			dp[j][n+1][i]=INF;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<4;j++){
			dp[j][i][0]=INF;
			dp[j][i][m+1]=INF;
		}
	}
	//kuadran 2
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[0][i][j]=min(a[i][j]+1,min(dp[0][i-1][j],dp[0][i][j-1])+1);
		}
	}
	//kuadran 1
	for(int i=1;i<=n;i++){
		for(int j=m;j>=1;j--){
			dp[1][i][j]=min(a[i][j]+1,min(dp[1][i-1][j],dp[1][i][j+1])+1);
		}
	}
	//kuadran 3
	for(int i=n;i>=1;i--){
		for(int j=1;j<=m;j++){
			dp[2][i][j]=min(a[i][j]+1,min(dp[2][i+1][j],dp[2][i][j-1])+1);
		}
	}
	//kuadran 4
	for(int i=n;i>=1;i--){
		for(int j=m;j>=1;j--){
			dp[3][i][j]=min(a[i][j]+1,min(dp[3][i+1][j],dp[3][i][j+1])+1);
		}
	}
	//pasti max pathnya diawali dengan bil minimum di path tsb dan diakhari dengan bil maksimum di path tsb
	int ans=-1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			//maksimum di (i,j)
			ans=max(ans,a[i][j]-kecil(dp[0][i][j],dp[1][i][j],dp[2][i][j],dp[3][i][j]));
		}
	}
	printf("%d\n",ans);
	return 0;
}

Compilation message

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
maxcomp.cpp:14:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |   for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);
      |                        ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 2 ms 1388 KB Output is correct
10 Correct 2 ms 1388 KB Output is correct
11 Correct 2 ms 1388 KB Output is correct
12 Correct 2 ms 1388 KB Output is correct
13 Correct 2 ms 1388 KB Output is correct
14 Correct 1 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 1388 KB Output is correct
13 Correct 2 ms 1388 KB Output is correct
14 Correct 2 ms 1388 KB Output is correct
15 Correct 2 ms 1388 KB Output is correct
16 Correct 2 ms 1388 KB Output is correct
17 Correct 1 ms 1388 KB Output is correct
18 Correct 182 ms 28780 KB Output is correct
19 Correct 175 ms 28652 KB Output is correct
20 Correct 162 ms 28268 KB Output is correct
21 Correct 172 ms 28524 KB Output is correct
22 Correct 170 ms 28532 KB Output is correct
23 Correct 173 ms 28524 KB Output is correct
24 Correct 164 ms 28416 KB Output is correct