結果

提出番号 1441
提出者 square1001
言語 C++
提出日時 2018-08-04 08:47:25
問題名 (54)Split the sequence
結果 MLE
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 WA 0% 2ms 8416KB
2 WA 0% 2ms 7792KB
3 AC 100% 2ms 8096KB
4 WA 0% 2ms 7776KB
5 WA 0% 2ms 7920KB
6 AC 100% 2ms 8112KB
7 AC 100% 1ms 8304KB
8 AC 100% 2ms 8720KB
9 WA 0% 2ms 8048KB
10 WA 0% 2ms 8704KB
11 WA 0% 2ms 7616KB
12 WA 0% 2ms 8128KB
13 WA 0% 2ms 8704KB
14 WA 0% 2ms 7792KB
15 WA 0% 2ms 7232KB
16 WA 0% 2ms 8432KB
17 WA 0% 1ms 8688KB
テストケース 結果 得点 実行時間 メモリ使用量
18 WA 0% 2ms 7648KB
19 WA 0% 2ms 8128KB
20 WA 0% 2ms 7920KB
21 WA 0% 2ms 8720KB
22 WA 0% 2ms 8400KB
23 WA 0% 2ms 8416KB
24 WA 0% 2ms 7776KB
25 WA 0% 2ms 7920KB
26 WA 0% 1ms 8096KB
27 WA 0% 2ms 8432KB
テストケース 結果 得点 実行時間 メモリ使用量
28 WA 0% 2ms 7632KB
29 WA 0% 2ms 8416KB
30 WA 0% 3ms 8928KB
31 WA 0% 2ms 8416KB
32 WA 0% 2ms 7840KB
33 WA 0% 3ms 8096KB
34 WA 0% 3ms 8928KB
35 WA 0% 2ms 8400KB
36 WA 0% 2ms 8432KB
37 WA 0% 2ms 7984KB
テストケース 結果 得点 実行時間 メモリ使用量
38 WA 0% 2ms 7776KB
39 WA 0% 2ms 7808KB
40 WA 0% 7ms 11504KB
41 WA 0% 2ms 8016KB
42 WA 0% 6ms 10848KB
43 WA 0% 5ms 10128KB
44 WA 0% 8ms 11520KB
45 WA 0% 6ms 11536KB
46 WA 0% 2ms 7904KB
47 WA 0% 4ms 8480KB
テストケース 結果 得点 実行時間 メモリ使用量
48 WA 0% 3ms 8432KB
49 WA 0% 3ms 8416KB
50 WA 0% 46ms 40944KB
51 WA 0% 3ms 8720KB
52 WA 0% 29ms 23168KB
53 WA 0% 34ms 26112KB
54 WA 0% 38ms 32384KB
55 WA 0% 33ms 27584KB
56 WA 0% 37ms 28416KB
57 WA 0% 49ms 34656KB
テストケース 結果 得点 実行時間 メモリ使用量
58 WA 0% 17ms 21024KB
59 WA 0% 17ms 21008KB
60 MLE 0% 349ms 331568KB
61 WA 0% 19ms 23696KB
62 MLE 0% 383ms 271312KB
63 WA 0% 327ms 194912KB
64 WA 0% 438ms 253456KB
65 WA 0% 329ms 209680KB
66 WA 0% 353ms 217552KB
67 MLE 0% 443ms 274400KB

ソースコード

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const long long inf = 1LL << 60;
int n, m, c, s[100009], sp[100009], ss[100009], d[100009], p[209][100009]; long long dp[100009], ndp[100009];
bool comp(long long xa, long long xb, long long ya, long long yb) {
	// judge if xa * xb >= ya * yb
	int xa1 = xa >> 31, xa0 = xa & ((1 << 31) - 1);
	int xb1 = xb >> 31, xb0 = xb & ((1 << 31) - 1);
	int ya1 = ya >> 31, ya0 = ya & ((1 << 31) - 1);
	int yb1 = yb >> 31, yb0 = yb & ((1 << 31) - 1);
	long long xc3 = 0;
	long long xc2 = 1LL * xa1 * xb1;
	long long xc1 = 1LL * xa1 * xb0 + 1LL * xa0 * xb1;
	long long xc0 = 1LL * xa0 * xb0;
	long long yc3 = 0;
	long long yc2 = 1LL * ya1 * yb1;
	long long yc1 = 1LL * ya1 * yb0 + 1LL * ya0 * yb1;
	long long yc0 = 1LL * ya0 * yb0;
	xc1 += xc0 >> 31; xc0 &= ((1 << 31) - 1);
	xc2 += xc1 >> 31; xc1 &= ((1 << 31) - 1);
	xc3 += xc2 >> 31; xc2 &= ((1 << 31) - 1);
	yc1 += yc0 >> 31; yc0 &= ((1 << 31) - 1);
	yc2 += yc1 >> 31; yc1 &= ((1 << 31) - 1);
	yc3 += yc2 >> 31; yc2 &= ((1 << 31) - 1);
	if (xc3 != yc3) return xc3 > yc3;
	if (xc2 != yc2) return xc2 > yc2;
	if (xc1 != yc1) return xc1 > yc1;
	return xc0 >= yc0;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> ss[i + 1];
		ss[i + 1] += ss[i];
	}
	int rn = 0;
	for (int i = 0; i < n; i++) {
		if (ss[i + 1] != ss[i]) {
			s[++rn] = ss[i + 1];
			sp[rn] = i + 1;
		}
	}
	fill(dp + 1, dp + n + 1, inf);
	for (int i = 0; i <= m && i < rn; ++i) {
		c = 0;
		for (int j = 0; j <= rn; ++j) {
			while (c >= 2 && comp(s[j] - s[d[c - 1]], dp[d[c - 1]] - dp[d[c - 2]], s[d[c - 1]] - s[d[c - 2]], dp[j] - dp[d[c - 1]])) {
				c--;
			}
			d[c++] = j;
		}
		int ptr = 0;
		for (int j = 0; j <= rn; ++j) {
			while (ptr + 1 != c && d[ptr + 1] < j && dp[d[ptr]] - 2LL * s[j] * s[d[ptr]] > dp[d[ptr + 1]] - 2LL * s[j] * s[d[ptr + 1]]) ptr++;
			ndp[j] = dp[d[ptr]] + 2LL * (s[j] - s[d[ptr]]) * s[j];
			p[i][j] = d[ptr];
		}
		copy(ndp, ndp + rn + 1, dp);
	}
	cout << 1LL * s[rn] * s[rn] - dp[rn] / 2 << '\n';
	int pos = rn;
	vector<int> ret;
	for (int i = min(m, rn - 1); i >= 1; --i) {
		pos = p[i][pos];
		ret.push_back(sp[pos]);
	}
	for (int i = 1; i <= n; i++) {
		if (ss[i] == ss[i - 1] && ret.size() != m) {
			ret.push_back(i);
		}
	}
	for (int i = 0; i < ret.size(); i++) {
		cout << ret[i];
		if (i + 1 == ret.size()) cout << '\n';
		else cout << ' ';
	}
	return 0;
}