답안 #362808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362808 2021-02-04T12:20:31 Z keta_tsimakuridze Maxcomp (info1cup18_maxcomp) C++14
100 / 100
424 ms 20892 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define pii pair< pair<int,pair<int,int > > ,pair<int,int> > 
using namespace std;
const int N=1e3+5,INF=2e9;
int n,m,dp[N][N][2],k,i,ans,a[N][N];
int a1[]={0,0,-1,1},a2[]={-1,1,0,0};
priority_queue<pii,vector<pii>,greater<pii> > q;
bool ok(int x,int y){
	if(min(x,y)<1 || x>n || y>m ) return 0;
	return 1;
}
 main(){
	cin>>n>>m;
	for(k=1;k<=n;k++){
		for(int i=1;i<=m;i++){
			cin>>a[k][i];
			dp[k][i][0]=0;
		}
	}
	ans=INF;
	for(k=1;k<=2;k++){
		
		for(i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				int cur=dp[i][j][k-1];
				if(k==1) dp[i][j][k]=dp[i][j][k-1]+a[i][j];
				else dp[i][j][k]=dp[i][j][k-1]-a[i][j];
				if(i>1)dp[i][j][k] = min (dp[i][j][k],dp[i-1][j][k]+1);
				if(j>1)dp[i][j][k] = min (dp[i][j][k],dp[i][j-1][k]+1);
			}
		}
		for(i=n;i>=1;i--){
			for(int j=m;j>=1;j--){
				if(i<n)dp[i][j][k] = min (dp[i][j][k],dp[i+1][j][k]+1);
				if(j<m)dp[i][j][k] = min (dp[i][j][k],dp[i][j+1][k]+1);
				if(k==2) ans=min(ans,dp[i][j][k]);
				
			}
		}
	}
	cout<<-ans-1;
}

Compilation message

maxcomp.cpp:14:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 |  main(){
      |       ^
maxcomp.cpp: In function 'int main()':
maxcomp.cpp:27:9: warning: unused variable 'cur' [-Wunused-variable]
   27 |     int cur=dp[i][j][k-1];
      |         ^~~
maxcomp.cpp:38:36: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   38 |     if(k==2) ans=min(ans,dp[i][j][k]);
      |                          ~~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 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 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 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 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 409 ms 12084 KB Output is correct
19 Correct 407 ms 20844 KB Output is correct
20 Correct 392 ms 20332 KB Output is correct
21 Correct 407 ms 20716 KB Output is correct
22 Correct 407 ms 20892 KB Output is correct
23 Correct 410 ms 20844 KB Output is correct
24 Correct 424 ms 20844 KB Output is correct