# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
920487 | zeta7532 | Friends (BOI17_friends) | C++17 | 5 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = int;
const ll mod = 998244353;
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr)
int main() {
ll N,P,Q;
cin >> N >> P >> Q;
bool A[N][N];
rep(i,N) rep(j,N) A[i][j]=false;
rep(i,N){
ll x;
cin >> x;
rep(j,x){
ll y;
cin >> y;
A[i][y]=true;
}
}
bool S[1<<N];
rep(bit,1<<N){
S[bit]=false;
ll people=0;
ll cnt=0;
rep(i,N){
if(bit&(1<<i)) people++;
rep(j,N){
if(bit&(1<<i)) if(bit&(1<<j)) if(A[i][j]) cnt++;
}
}
if(people<=P&&cnt>=2*Q) S[bit]=true;
}
bool dp[1<<N];
rep(bit,1<<N) dp[bit]=false;
dp[0]=true;
for(ll bit=1;bit<(1<<N);bit++){
for(ll T=bit;T>=0;T--){
T&=bit;
if(T==0) continue;
if(S[T]) if(dp[bit-T]) dp[bit]=true;
}
}
if(dp[(1<<N)-1]){
cout << "home" << endl;
vector<ll> ans;
ll bit=(1<<N)-1;
while(1){
for(ll T=bit;T>=0;T--){
T&=bit;
if(T==bit) continue;
if(dp[T]&&S[bit-T]){
ans.push_back(bit-T);
bit=T;
break;
}
}
if(bit==0) break;
}
cout << ans.size() << endl;
rep(i,ans.size()){
vector<ll> ANS;
rep(j,N) if(ans[i]&(1<<j)) ANS.push_back(j);
cout << ANS.size() << " ";
rep(j,ANS.size()) cout << ANS[j] << " ";
cout << endl;
}
}else{
cout << "detention" << endl;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |