답안 #390626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
390626 2021-04-16T12:18:49 Z keta_tsimakuridze Collecting Stamps 3 (JOI20_ho_t3) C++14
0 / 100
1 ms 460 KB
#include<bits/stdc++.h>
#define f first
#define int long long
#define s second
using namespace std;
const int N=205,Inf=1e10;
int t,dp[N][N][N][2],n,l,ans;
pair<int,int>p[N];
string s;
int add(int x ,int y){
	if(x<y) swap(x,y);
	return min(x-y,l-x+y);
}
 main(){
	// t=1;
	cin >> n >> l;
	for(int i=1;i<=n;i++){
		cin>>p[i].f;
	}
	for(int i=1;i<=n;i++){
		cin>>p[i].s;
	}
	sort(p+1,p+n+1);
	for(int i=0;i<=n+1;i++){
		for(int j=0;j<=n+1;j++){
			for(int k=0;k<=n;k++)
				dp[i][j][k][0]=dp[i][j][k][1]=Inf;
		}
	}
	dp[n+1][0][0][0]=dp[n+1][0][0][1]=0;
	p[n+1].f=l;
	// 1 1 
	for(int i=n;i>=0;i--){
		for(int j=0;j<i;j++){
			for(int k=0;k<=n;k++){
				if(i==0 && j==0) continue;
			
				dp[i][j][k][0] = min(dp[i+1][j][k][0] + add(p[i+1].f,p[i].f), dp[i+1][j][k][1] + add(p[j].f,p[i].f) );
				if(j)	dp[i][j][k][1] = min(dp[i][j-1][k][1] + add(p[j-1].f,p[j].f), dp[i][j-1][k][0] + add(p[j].f,p[i].f)); 
				if(k) {
					if(j && dp[i][j-1][k-1][0]+add(p[j].f,p[i].f)<=p[j].s){
						dp[i][j][k][1]=min(dp[i][j][k][1], dp[i][j-1][k-1][0]+add(p[j].f,p[i].f));
					}
					if(j && dp[i][j-1][k-1][1]+add(p[j].f,p[j-1].f)<=p[j].s){
						dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][j-1][k-1][1]+add(p[j].f,p[j-1].f));
					}
					if(dp[i+1][j][k-1][0]+add(p[i+1].f,p[i].f)<=p[i].s){
						dp[i][j][k][0]=min(dp[i][j][k][0],dp[i+1][j][k-1][0]+add(p[i+1].f,p[i].f));
					}
					if(dp[i+1][j][k-1][1]+add(p[i].f,p[j].f)<=p[i].s){
						dp[i][j][k][0]=min(dp[i][j][k][0],dp[i+1][j][k-1][1]+add(p[j].f,p[i].f));
					}
					
				}
		if(dp[i][j][k][0]<Inf || dp[i][j][k][1]<Inf) ans=max(ans,k);//cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k][0]<<endl; 
			}
		}
	}
	cout<<ans;
	
}

Compilation message

ho_t3.cpp:14:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 |  main(){
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Incorrect 1 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Incorrect 1 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Incorrect 1 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Incorrect 1 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -