Submission #923458

#TimeUsernameProblemLanguageResultExecution timeMemory
923458NValchanovNorela (info1cup18_norela)C++17
0 / 100
16 ms348 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; const ll MAXN=64; const ll MAXM=25; ll a[MAXN],n,m,q,c; ll ans; vector<ll>order; void read() { cin>>n>>m; for(ll i=0;i<m;i++) { cin>>q; for(ll j=0;j<q;j++) { cin>>c; a[i]|=(ll)(1LL<<(c-1)); } } } ll count_bits(ll mask) { ll cnt=0; for(ll i=0;i<n;i++) { if(mask&(1LL<<i)) cnt++; } return cnt; } void fill_order(ll mask) { order.clear(); ans=mask; for(ll i=0;i<m;i++) { if(mask&(1LL<<(i))) { order.push_back(i+1); } } } void check_current(ll mask, ll x) { if(__builtin_popcount(x) == n) { if(!ans) fill_order(mask); else { if(__builtin_popcount(ans)>__builtin_popcount(mask)) fill_order(mask); else if(__builtin_popcount(ans)==__builtin_popcount(mask)) { ll lampa=-1; vector<ll>tmp; for(ll i=0;i<m;i++) { if(mask&(1LL<<i)) { tmp.push_back(i+1); ll sz=tmp.size(); if(lampa==-1) { if(tmp[sz-1]>order[sz-1]) lampa=0; else if(tmp[sz-1]<order[sz-1]) lampa=1; } } } if(lampa==1) { ans=mask; order.clear(); order=tmp; } } } } } void solve() { ans=0; for(ll mask=0;mask<(1LL<<m);mask++) { ll cur=0; for(ll i=0;i<m;i++) { if(mask&(1LL<<i)) { cur^=a[i]; } } check_current(mask, cur); } } void print() { ll sz=__builtin_popcount(ans); cout<<sz<<endl; for(ll i=0;i<sz;i++) { cout<<order[i]<<" "; } cout<<endl; } int main() { #ifdef ONLINE_JUDGE freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); read(); solve(); print(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...