《补题》( Codeforces Round #851 (Div. 2), problem: (A) One and Two)

44 阅读1分钟

思维:只有2才对题意有贡献

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
	int n;
	std::cin >> n;

	std::vector<int> a(n + 1);
	int cnt = 0;

	for (int i = 1; i <= n; i ++) {
		std::cin >> a[i];

		if (a[i] == 2) {
			cnt ++;
		}
	}

	if (cnt & 1) {
		std::cout << -1 << "\n";
		return;
	} else if (cnt == 0) {
		std::cout << 1 << "\n";
		return;
	}

	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		if (a[i] == 2) {
			ans ++;
		}
		if (ans == cnt / 2) {
			std::cout << i << "\n";
			return;
		}
	}
}

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

	int t;
	std::cin >> t;

	while (t --) {
		solve();
	}

	return 0;
}