답안 #207757

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
207757 2020-03-08T20:32:32 Z super_j6 Collecting Stamps 3 (JOI20_ho_t3) C++14
0 / 100
5 ms 504 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define f first
#define s second

const long long inf = 1000000000000000007;
const int maxn = 202;
int n, m;
pi a[maxn];
long long dp[maxn][maxn][maxn][2];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++) cin >> a[i].f;
	for(int i = 1; i <= n; i++) cin >> a[i].s;
	a[n + 1].f = m;
	sort(a + 1, a + n + 1);
	
	for(int i = 0; i <= n; i++)
	for(int j = 0; j <= n; j++)
	for(int k = n + 1; k > j; k--) dp[i][j][k][0] = dp[i][j][k][1] = inf;
	
	int ret = 0;
	dp[0][0][n + 1][0] = dp[0][0][n + 1][1] = 0;
	for(int i = 0; i <= n; i++)
	for(int j = 0; j <= n; j++)
	for(int k = n + 1; k > j; k--){
		long long x;
		bool t0 = 0, t1 = 0;
		if(dp[i][j][k][0] != inf){
			ret = i;
			x = dp[i][j][k][0] + a[j + 1].f - a[j].f;
			if(x <= dp[i][j + 1][k][0]){
				dp[i][j + 1][k][0] = x;
				t0 = 1;
			}
			x = dp[i][j][k][0] + a[j].f + m - a[k - 1].f;
			if(x <= dp[i][j][k - 1][1]){
				dp[i][j][k - 1][1] = x;
				t1 = 1;
			}
		}
		if(dp[i][j][k][1] != inf){
			ret = i;
			x = dp[i][j][k][1] + a[k].f - a[k - 1].f;
			if(x <= dp[i][j][k - 1][1]){
				dp[i][j][k - 1][1] = x;
				t1 = 1;
			}
			x = dp[i][j][k][1] + a[j + 1].f + m - a[k].f;
			if(x <= dp[i][j + 1][k][0]){
				dp[i][j + 1][k][0] = x;
				t0 = 1;
			}
		}
		if(t0 && dp[i][j + 1][k][0] <= a[j + 1].s) dp[i + 1][j + 1][k][0] = dp[i][j + 1][k][0];
		if(t1 && dp[i][j][k - 1][1] <= a[k - 1].s) dp[i + 1][j][k - 1][1] = dp[i][j][k - 1][1];
	}
	
	cout << ret << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Incorrect 5 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Incorrect 5 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Incorrect 5 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Incorrect 5 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -