Submission #647628

#TimeUsernameProblemLanguageResultExecution timeMemory
647628mychecksedadFriends (BOI17_friends)C++17
0 / 100
18 ms23820 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef long double ld; #define MOD (1000000000+7) #define MOD1 (998244353) #define PI 3.1415926535 #define pb push_back #define setp() cout << setprecision(15) #define all(x) x.begin(), x.end() #define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> #define debug(x) cerr << #x << " is " << x << '\n'; const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20; int n, p, q; bool dp[N]; vector<vector<int>> solution[N]; bitset<20> g[N]; void solve(){ cin >> n >> p >> q; for(int i = 0; i < n; ++i){ int m; cin >> m; for(int j = 0; j < m; ++j){ int x; cin >> x; g[i][x] = 1; } } bool ok = 1; for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ if(g[i][j] && !g[j][i]){ ok = 0; } } } if(!ok){ cout << "Detention"; return; } for(int i = 0; i < (1<<n); ++i) dp[i] = 0; for(int mask = 1; mask < (1<<n); ++mask){ if(__builtin_popcount(mask) > p) continue; vector<int> v; bitset<20> a(mask); int x = 0; for(int j = 0; j < n; ++j){ if(mask&(1<<j)){ x += ((a&g[j]) ^ g[j]).count(); v.pb(j); } } if(x > q){ continue; } dp[mask] = 1; solution[mask].pb(v); } for(int mask = 0; mask < (1<<n); ++mask){ int s = mask; for(; s>0; s=((s-1)&mask)){ if(dp[s] & dp[mask^s]){ dp[mask] = 1; solution[mask] = solution[s]; if(!solution[mask^s].empty()) for(auto v: solution[mask^s]) solution[mask].pb(v); break; } } } if(dp[(1<<n) - 1]){ cout << "Home\n"; cout << solution[(1<<n)-1].size() << '\n'; for(auto v: solution[(1<<n) - 1]){ cout << v.size() << '\n'; for(int x: v) cout << x << ' '; cout << '\n'; } }else cout << "Detention"; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int T = 1, aa; // cin >> T;aa=T; while(T--){ // cout << "Case #" << aa-T << ": "; solve(); cout << '\n'; } return 0; }

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:91:16: warning: unused variable 'aa' [-Wunused-variable]
   91 |     int T = 1, aa;
      |                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...