#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,p,q,x,a[20],b[20],i,j,t,tot,y;
vector<int>f[(1<<16)+5];
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n>>p>>q;
for(i=0;i<n;i++)
{
cin>>y;
while(y--)
{
cin>>x;
a[i]|=(1<<x);
b[x]|=(1<<i);
}
}
for(i=0;i<n;i++)
{
if(a[i]!=b[i])rc("detention");
}
for(i=0;i<(1<<n);i++)
{
if(__builtin_popcount(i)>p)continue;
tot=0;
for(j=0;j<n;j++)
{
if(!(i&(1<<j)))continue;
x=__builtin_popcount(a[j])-__builtin_popcount(a[j]&i);
tot+=x;
}
if(tot<=q)f[i].pb(i);
}
for(i=0;i<(1<<n);i++)
{
if(!f[i].empty())continue;
for(j=i;j;j=i&(j-1))
{
if(f[j].empty() || f[i^j].empty())continue;
for(t=0;t<(int)f[j].size();t++)f[i].pb(f[j][t]);
for(t=0;t<(int)f[i^j].size();t++)f[i].pb(f[i^j][t]);
break;
}
}
x=(1<<n)-1;
if(f[x].empty())rc("detention");
cout<<"home"<<endl<<(int)f[x].size()<<endl;
for(i=0;i<(int)f[x].size();i++)
{
cout<<__builtin_popcount(f[x][i])<<" ";
for(j=0;j<n;j++)if(f[x][i]&(1<<j))cout<<j<<" ";
cout<<endl;
}
return 0;
}
Compilation message
friends.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("O3")
friends.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("unroll-loops")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
4 ms |
1912 KB |
Output is correct |
3 |
Correct |
4 ms |
1912 KB |
Output is correct |
4 |
Correct |
23 ms |
3068 KB |
Output is correct |
5 |
Correct |
76 ms |
3192 KB |
Output is correct |
6 |
Correct |
117 ms |
2040 KB |
Output is correct |
7 |
Correct |
127 ms |
2152 KB |
Output is correct |
8 |
Correct |
4 ms |
1912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1912 KB |
Output is correct |
2 |
Execution timed out |
1069 ms |
1912 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1912 KB |
Output is correct |
2 |
Execution timed out |
1069 ms |
1912 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
4 ms |
1912 KB |
Output is correct |
3 |
Correct |
4 ms |
1912 KB |
Output is correct |
4 |
Correct |
23 ms |
3068 KB |
Output is correct |
5 |
Correct |
76 ms |
3192 KB |
Output is correct |
6 |
Correct |
117 ms |
2040 KB |
Output is correct |
7 |
Correct |
127 ms |
2152 KB |
Output is correct |
8 |
Correct |
4 ms |
1912 KB |
Output is correct |
9 |
Correct |
3 ms |
1912 KB |
Output is correct |
10 |
Execution timed out |
1069 ms |
1912 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |