답안 #244008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244008 2020-07-02T12:55:22 Z islingr 구슬과 끈 (APIO14_beads) C++14
0 / 100
5 ms 384 KB
#include <iostream>
using namespace std;
 
const int N = 1e5 + 5, K = 205;
int64_t f[2][N], a[N];
int opt[K][N], s[N];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, k; cin >> n >> k;
	for (int i = 1; i <= n; ++i) cin >> a[i], a[i] += a[i - 1];
	for (int l = 1; l <= k; ++l) {
		auto c = [&](int j) { return f[(l & 1) ^ 1][j] - a[j] * a[j]; };
		auto val = [&](int j, int x) { return a[j] * x + c(j); };
		auto cross = [&](int i, int j, int k) {
			return (c(k) - c(i)) * (a[j] - a[i]) - (c(j) - c(i)) * (a[k] - a[i]);
		};
		for (int i = l, j = 1, t = 0; i <= n; ++i) {
			while (i > l && j > t) --j;
			while (j < t && val(s[j], a[i]) < val(s[j + 1], a[i])) ++j;
			opt[l][i] = s[j];
			f[l & 1][i] = val(s[j], a[i]);
			while (t > 1 && 0 <= cross(s[t - 1], s[t], i)) --t;
			s[++t] = i;
		}
	}
	cout << f[k & 1][n] << '\n';
	for (int v = n, l = k; v = opt[l--][v]; ) s[l] = v;
	for (int l = 0; l < k; ++l) cout << s[l] << ' ';
}

Compilation message

beads.cpp: In function 'int main()':
beads.cpp:30:27: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  for (int v = n, l = k; v = opt[l--][v]; ) s[l] = v;
                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -