Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define fi first
- #define se second
- using namespace std;
- using i64 = long long;
- const int TARGET = (1 << 10) - 1;
- const int INF = 0x3f3f3f3f;
- int a[10] = {
- (1 << 1) | (1 << 4), // 1
- (1 << 0) | (1 << 4) | (1 << 5) | (1 << 2), // 2
- (1 << 1) | (1 << 5) | (1 << 6) | (1 << 3), // 3
- (1 << 2) | (1 << 6), // 4
- (1 << 0) | (1 << 1) | (1 << 5) | (1 << 7), // 5
- (1 << 1) | (1 << 2) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 8), // 6
- (1 << 2) | (1 << 3) | (1 << 5) | (1 << 8), // 7
- (1 << 4) | (1 << 5) | (1 << 8) | (1 << 9), // 8
- (1 << 5) | (1 << 6) | (1 << 7) | (1 << 9), // 9
- (1 << 7) | (1 << 8) // 10
- };
- string get(int mask) {
- string s;
- for (int i = 0; i < 10; ++i) {
- s += ((mask & (1 << i)) ? "1" : "0");
- }
- return s;
- }
- bool cmp(string a, string b) {
- int sz = a.size();
- vector<int> aa, bb;
- for (int i = 0; i < sz; ++i) {
- if (a[i] == '1') {
- aa.push_back(i + 1);
- }
- if (b[i] == '1') {
- bb.push_back(i + 1);
- }
- }
- for (int i = 0; i < aa.size(); ++i) {
- if (aa[i] < bb[i]) return true;
- if (aa[i] > bb[i]) return false;
- }
- return false;
- }
- int main() {
- cin.tie(0)->sync_with_stdio(0);
- int initialMask = 0;
- for (int i = 0; i < 10; ++i) {
- int x; cin >> x;
- if (x)
- initialMask |= (1 << i);
- }
- int answer = INF;
- string strAns;
- for (int mask = 0; mask < (1 << 10); ++mask) {
- int allMasks = initialMask;
- for (int i = 0; i < 10; ++i) {
- if (mask & (1 << i)) {
- allMasks ^= a[i];
- }
- }
- if (allMasks == TARGET) {
- int qtd = __builtin_popcount(mask);
- if (qtd < answer or (qtd == answer and cmp(get(mask), strAns))) {
- answer = qtd;
- strAns = get(mask);
- }
- }
- }
- if (answer != INF) {
- cout << answer << '\n';
- bool first = true;
- vector<int> a;
- for (int i = 0; i < 10; ++i) {
- if (strAns[i] == '1') {
- a.push_back(i + 1);
- }
- }
- for (int i = 0; i < answer; ++i) {
- cout << a[i] << " \n"[i==answer-1];
- }
- } else {
- cout << "-1\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment