Submission #689920

# Submission time Handle Problem Language Result Execution time Memory
689920 2023-01-29T18:45:49 Z divad Norela (info1cup18_norela) C++14
0 / 100
17 ms 212 KB
#include <bits/stdc++.h>
#define int long long
#define NMAX 62
#define MMAX 26
using namespace std;
int n,m,q,x,ans,b[MMAX];
vector<int> sol;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    ans = -1;
    for(int i = 1; i <= m; i++){
        cin >> q;
        for(int j = 1; j <= q; j++){
            cin >> x;
            b[i] |= (1<<x);
        }
    }
    for(int i = 0; i < (1<<m); i++){
        int all = 0;
        for(int j = 0; j < m; j++){
            if(i&(1<<j)){
                all ^= b[j+1];
            }
        }
        if(__builtin_popcount(all) == n){
            if(ans == -1){
                ans = i;
                for(int j = 0; j < m; j++){
                    if(i&(1<<j)){
                        sol.push_back(j+1);
                    }
                }
            }else{
                if(__builtin_popcount(ans) > __builtin_popcount(i)){
                    sol.clear();
                    for(int j = 0; j < m; j++){
                        if(i&(1<<j)){
                            sol.push_back(j+1);
                        }
                    }
                    ans = i;
                }else if(__builtin_popcount(ans) == __builtin_popcount(i)){
                    vector<int> aux;
                    int ok = -1;
                    for(int j = 0; j < m; j++){
                        if(i&(1<<j)){
                            aux.push_back(j+1);
                            int pos = aux.size()-1;
                            if(ok == -1){
                                if(aux[pos] > sol[pos]){
                                    ok = 0;
                                }else if(aux[pos] < sol[pos]){
                                    ok = 1;
                                }
                            }
                        }
                    }
                    if(ok){
                        sol.clear();
                        for(auto it: aux){
                            sol.push_back(it);
                        }
                        ans = i;
                    }
                }
            }
        }
    }
    cout << __builtin_popcount(ans) << "\n";
    for(auto it: sol){
        cout << it << " ";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 212 KB Output is correct
2 Incorrect 15 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 212 KB Output is correct
2 Incorrect 15 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 212 KB Output is correct
2 Incorrect 15 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 212 KB Output is correct
2 Incorrect 15 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -