求 hack
查看原帖
求 hack
526711
Sliarae楼主2025/1/5 19:52

赛时写假贪心 WA 了一发,拒绝思考,换成 (3!)2(3!)^2 枚举优先级过了。

看题解的 dp 很有道理,并且能和数据范围对上,我怀疑这个是不是假的。求 hack 或能证明正确性的贪心。

#include <iostream>
#include <algorithm>

using namespace std;
using LL = long long;

const LL Inf = 1e18;

int p[3];

void Do (LL &x, int o) {
	if (!o) x = (x + 1) >> 1;
	else if (o == 1) x >>= 1;
	else if (o == 2) x = (x - 1) >> 1; 
}

int main () {
	LL n;
	cin >> n >> p[1] >> p[0] >> p[2];
	int ord[2][3];
	for (int i = 0; i < 2; ++i)
		for (int j = 0; j < 3; ++j)
			ord[i][j] = j;
	LL ans = Inf;
	do {
		do {
			int c[3];
			copy(p, p + 3, c);
			LL x = n; 
			while (x && (c[0] || c[1] || c[2])) {
				int r = x & 1;
				for (int j = 0; j < 3; ++j) {
					int o = ord[r][j];
					if (c[o]) {
						--c[o], Do(x, o);
						break;
					}
				}
			}
			ans = min(ans, x);
		} while (next_permutation(ord[1], ord[1] + 3)); 
	} while (next_permutation(ord[0], ord[0] + 3)); 
	cout << ans << '\n';
	return 0; 
}
2025/1/5 19:52
加载中...