답안 #165556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
165556 2019-11-27T12:42:01 Z ArKCa Cipele (COCI18_cipele) C++14
9 / 90
1000 ms 198748 KB
#include<bits/stdc++.h>
 
using namespace std;
int n,k,m;
int dizi1[5000],dizi2[5000],dp[5000][5000];
 
int dpf(int crr,int r){
	if(crr==(n-1)){
		int mn=INT_MAX;
		for(int i=r;i<m;i++){
			mn=min(mn,abs(dizi1[crr]-dizi2[i]) );
		}
		dp[crr][r]=mn;
		return dp[crr][r];	
	}
	if( (n-crr) > (m-r) ){
		return INT_MAX;
	}
	if(dp[crr][r]!=-1){
		return dp[crr][r];
	}
	int mn=INT_MAX;
	// printf("a\n");
	for(int i=r;i<m && ( (n-(crr+1)) <= (m-(i+1)) );i++){
		mn=min(mn,max( abs(dizi1[crr]-dizi2[i] ),dpf(crr+1,i+1) ) );
	}
	dp[crr][r]=mn;
	return dp[crr][r];
}
 
int main(){
	// freopen("a.gir","r",stdin);
	// freopen("a.cik","w",stdout);
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	if(n==m){	
		int mx=0;
		for(int i=0;i<n;i++){
			cin>>dizi1[i];
		}
		for(int i=0;i<m;i++){
			cin>>dizi2[i];
		}
		sort(dizi1,dizi1+n);
		sort(dizi2,dizi2+m);
		for(int i=0;i<n;i++){
			mx=max(abs(dizi2[i]-dizi1[i]),mx);
		}
		printf("%d\n",mx );
		return 0;
	}
	else if(n<m){
		for(int i=0;i<n;i++){
			cin>>dizi1[i];
		}
		for(int i=0;i<m;i++){
			cin>>dizi2[i];
		}
		sort(dizi1,dizi1+n);
		sort(dizi2,dizi2+m);
		printf("%d\n",dpf(0,0) );
		return 0;
	}
	
	else{
		int a;
		for(int i=0;i<n;i++){
			cin>>dizi2[i];
		}
		for(int i=0;i<m;i++){
			cin>>dizi1[i];
		}
		a=n;
		n=m;
		m=a;
		sort(dizi1,dizi1+n);
		sort(dizi2,dizi2+m);
		printf("%d\n",dpf(0,0) );
		return 0;	
	}
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 238 ms 198732 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 237 ms 198748 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 98396 KB Output is correct
2 Correct 99 ms 98552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1037 ms 98296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 98424 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 98424 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1058 ms 98552 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 232 ms 198648 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 253 ms 198684 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 227 ms 198680 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -