CodeForces 1415D XOR-gun

洛谷传送门

CF 传送门

纯纯的诈骗。

下文令 \(f(x)\)\(x\) 最高位使得这一位为 \(1\)。考虑若存在 \(i \in [1,n-2]\) 使得 \(f(a_i) = f(a_{i+1}) = f(a_{i+2})\),那么可以合并 \(a_{i+1}\)\(a_{i+2}\),这样最高位被消了,因此一定 \(< a_i\)。因此答案为 \(1\)

若不存在,则 \(n \le 60\)。爱怎么搞怎么搞。

code
/*

p_b_p_b txdy
AThousandSuns txdy
Wu_Ren txdy
Appleblue17 txdy

*/

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

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

const int maxn = 100100;

ll n, a[maxn];

void solve() {
	scanf("%lld", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
	}
	for (int i = 1; i <= n - 2; ++i) {
		if (__lg(a[i]) == __lg(a[i + 1]) && __lg(a[i + 1]) == __lg(a[i + 2])) {
			puts("1");
			return;
		}
	}
	for (int i = 1; i <= n; ++i) {
		a[i] ^= a[i - 1];
	}
	int ans = 2e9;
	for (int i = 1; i <= n; ++i) {
		for (int j = i; j <= n; ++j) {
			for (int k = j + 1; k <= n; ++k) {
				if ((a[j] ^ a[i - 1]) > (a[k] ^ a[j])) {
					ans = min(ans, k - i - 1);
				}
			}
		}
	}
	printf("%d\n", ans > 1e9 ? -1 : ans);
}

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

posted @ 2023-01-27 16:05  zltzlt  阅读(27)  评论(0)    收藏  举报