답안 #429881

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
429881 2021-06-16T10:14:06 Z Kevin_Zhang_TW 별자리 3 (JOI20_constellation3) C++17
0 / 100
6 ms 6972 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// My bug list :
// integer overflow
// 0based, 1based forgotten
// index out of bound
// n, m, i, j typo
// some cases are missing

const int MAX_N = 200010, MAX_M = 2005;

int n, h[MAX_N], m;
//           y, c
vector<pair<int,int>> star[MAX_N];

ll dp[MAX_M][MAX_M];

ll solve() {
	for (int i = 1;i <= n;++i) {
		if (h[i] <= h[i-1]) {
			int mxv = 0;
			for (auto [y, c] : star[i]) 
				if (y <= h[i-1]) chmax(mxv, c);

			for (int j = h[i-1] + 1;j <= n;++j) {
				dp[i][j] = dp[i-1][j] + mxv;
			}

			for (auto [y, c] : star[i])
				chmax(dp[i][y], dp[i-1][0] + c);

			dp[i][0] = dp[i-1][0];
		}
		else {
			ll mxv = 0;
			for (int j = 0;j <= h[i];++j)
				chmax(mxv, dp[i-1][j]);

			for (int j = h[i]+1;j <= n;++j)
				dp[i][j] = dp[i-1][j];

			for (auto [y, c] : star[i])
				chmax(dp[i][y], mxv + c);

			dp[i][0] = mxv;
		}
	}

	ll res = 0;
	for (int i = 1;i <= n;++i)
		for (auto [y, c] : star[i])
			res += c;
	res -= *max_element(dp[n], dp[n] + n + 1);

	return res;
}
int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int i = 1;i <= n;++i)
		cin >> h[i];
	cin >> m;
	for (int x, y, c, i = 0;i < m;++i) {
		cin >> x >> y >> c;
		star[x].pb(y, c);
	}

	cout << solve() << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 6972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 6972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 6972 KB Output isn't correct
2 Halted 0 ms 0 KB -