QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#430865#6610. Forged in the BarrenszltWA 4ms59432kbC++142.7kb2024-06-04 16:07:542024-06-04 16:07:54

Judging History

你现在查看的是最新测评结果

  • [2024-06-04 16:07:54]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:59432kb
  • [2024-06-04 16:07:54]
  • 提交

answer

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;

const int maxn = 100100;
const ll inf = 0x3f3f3f3f3f3f3f3fLL;

ll n, m, type, a[maxn];

typedef vector<ll> poly;

inline poly operator + (poly a, poly b) {
	int n = (int)a.size() - 1, m = (int)b.size() - 1;
	// if (1) {
		// poly res(n + m + 1, -inf);
		// for (int i = 0; i <= n; ++i) {
			// for (int j = 0; j <= m; ++j) {
				// res[i + j] = max(res[i + j], a[i] + b[j]);
			// }
		// }
		// return res;
	// }
	poly res;
	res.pb(a[0] + b[0]);
	int i = 0, j = 0;
	ll s = a[0] + b[0];
	while (i < n && j < m) {
		if (a[i + 1] - a[i] > b[j + 1] - b[j]) {
			s += a[i + 1] - a[i];
			++i;
			res.pb(s);
		} else {
			s += b[j + 1] - b[j];
			++j;
			res.pb(s);
		}
	}
	while (i < n) {
		s += a[i + 1] - a[i];
		++i;
		res.pb(s);
	}
	while (j < m) {
		s += b[j + 1] - b[j];
		++j;
		res.pb(s);
	}
	assert((int)res.size() == n + m + 1);
	return res;
}

inline poly get(poly a, poly b) {
	int n = (int)a.size(), m = (int)b.size();
	poly res(max(n, m), -inf);
	for (int i = 0; i < max(n, m); ++i) {
		if (i < n) {
			res[i] = max(res[i], a[i]);
		}
		if (i < m) {
			res[i] = max(res[i], b[i]);
		}
	}
	return res;
}

poly F[262199][3][3];

void dfs(int rt, int l, int r) {
	if (l == r) {
		F[rt][0][0] = {-inf};
		F[rt][0][1] = {-a[l]};
		F[rt][0][2] = {-inf};
		F[rt][1][0] = {-a[l]};
		F[rt][1][1] = {0, 0};
		F[rt][1][2] = {a[l]};
		F[rt][2][0] = {-inf};
		F[rt][2][1] = {a[l]};
		F[rt][2][2] = {-inf};
		return;
	}
	int mid = (l + r) >> 1;
	dfs(rt << 1, l, mid);
	dfs(rt << 1 | 1, mid + 1, r);
	for (int i = 0; i <= 2; ++i) {
		for (int j = 0; j <= 2; ++j) {
			F[rt][i][j] = get(F[rt << 1][i][j], F[rt << 1 | 1][i][j]);
			poly res = F[rt << 1][i][1] + F[rt << 1 | 1][1][j];
			F[rt][i][j] = get(F[rt][i][j], res);
			res = F[rt << 1][i][0] + F[rt << 1 | 1][2][j];
			res.insert(res.begin(), -inf);
			F[rt][i][j] = get(F[rt][i][j], res);
			res = F[rt << 1][i][2] + F[rt << 1 | 1][0][j];
			res.insert(res.begin(), -inf);
			F[rt][i][j] = get(F[rt][i][j], res);
		}
	}
}

void solve() {
	scanf("%lld%lld%lld", &n, &m, &type);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
	}
	dfs(1, 1, n);
	if (type == 1) {
		printf("%lld\n", F[1][1][1][m]);
	} else {
		for (int i = 1; i <= m; ++i) {
			printf("%lld\n", F[1][1][1][i]);
		}
	}
}

int main() {
	int T = 1;
	// scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 59432kb

input:

5
1 2 3 4 5

output:

5

result:

wrong answer 1st numbers differ - expected: '4', found: '5'