답안 #698187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698187 2023-02-12T19:11:42 Z BidoTeima Go (COCI18_go) C++17
10 / 100
231 ms 78472 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std; 
int dp[105][105][2005][2];
int a[105], b[105], t[105];
int n, k, m;
int cost(int i, int j, bool onWho, bool toWho) {
	//to i - 1
	if (!toWho) { 
		if (i == 0)return -1;
		if (!onWho) {
			return a[i] - a[i - 1];
		}
		return a[j] - a[i - 1];
	}
	// to j + 1
	if (j == m - 1)return -1;
	if (!onWho) {
		return a[j + 1] - a[i];
	}
	return a[j + 1] - a[j];
}
int main()
{ 
	cin >> n >> k >> m; 
	for (int i = 0; i < m; i++)
		cin >> a[i] >> b[i] >> t[i];
	int nearest_left = -1, nearest_right = -1;
	for (int i = 0; i < m && a[i] <= k; i++) {
		nearest_left = i;
	}
	for (int i = m - 1; i >= 0 && a[i] >= k; i--) {
		nearest_right = i;
	}
	int dist, ans=0;
	if (nearest_left != -1) {
		dist = k - a[nearest_left];
		dp[nearest_left][nearest_left][dist][1] =
		dp[nearest_left][nearest_left][dist][0] = (dist < t[nearest_left] ? b[nearest_left] : 0);
		ans = max(ans, dp[nearest_left][nearest_left][dist][1]);
	}
	if (nearest_right != -1) {
		dist = a[nearest_right] - k;
		dp[nearest_right][nearest_right][dist][1] =
		dp[nearest_right][nearest_right][dist][0] = (dist < t[nearest_right] ? b[nearest_right] : 0);
		ans = max(ans, dp[nearest_right][nearest_right][dist][1]);
	}
	for (int i = 0; i < m; i++) {
		for (int x = 0; i + x < m; x++) {
			int j = i + x;
			for (int curTime = 0; curTime < 2003; curTime++) {
				for (int on = 0; on < 2; on++) {
					ans = max(ans, dp[i][j][curTime][on]);
					// 0 means on i, 1 means on j
					// option 1: transition to [i - 1][j] 
					int v = cost(i, j, on, 0);
					if (i > 0 && curTime + v <= 2003) {
						int tot = curTime + v;
						dp[i - 1][j][tot][0] = max(dp[i - 1][j][tot][0],
							dp[i][j][curTime][on] + (tot < t[i - 1] ? b[i - 1] : 0));
						ans = max(ans, dp[i - 1][j][tot][0]);
					}
					// option 2: transition to [i][j + 1]
					v = cost(i, j, on, 1);
					if (j < m - 1 && curTime + v <= 2003) {
						int tot = curTime + v;
						dp[i][j + 1][tot][1] = max(dp[i][j + 1][tot][1],
							dp[i][j][curTime][on] + (tot < t[j + 1] ? b[j + 1] : 0)); 
						ans = max(ans, dp[i][j + 1][tot][1]);
					}
				}
			}
		}
	}
	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 3 ms 980 KB Output isn't correct
3 Incorrect 5 ms 1748 KB Output isn't correct
4 Incorrect 9 ms 3412 KB Output isn't correct
5 Incorrect 59 ms 19812 KB Output isn't correct
6 Incorrect 85 ms 28368 KB Output isn't correct
7 Incorrect 112 ms 38524 KB Output isn't correct
8 Incorrect 150 ms 50288 KB Output isn't correct
9 Incorrect 194 ms 63648 KB Output isn't correct
10 Incorrect 231 ms 78472 KB Output isn't correct