406. Goggle
Memory limit: 65536 kilobytes
output: standard
Everybody knows search engine Goggle. But only advanced users know that it is possible to search number sequences. You can enter a set of numbers and the search engine will find all sequences which contain it. Goggle developers decided to improve the engine. New feature will help you if you know numbers which shouldn't be in the result. These numbers must be entered with the opposite sign. For example, if somebody enters "5 -3 6", the engine will find all the sequences which contain 5 and 6, but do not contain 3.
Help Goggle developers to implement the feature.
sample input | sample output |
3 5 6 1 2 3 1 2 3 4 3 2 4 5 2 4 2 3 1 2 3 2 3 2 3 2 -1 3 2 4 -2 2 4 5 | 1 6 1 2 3 1 2 3 2 6 1 2 3 1 2 3 4 3 2 4 5 1 4 3 2 4 5 0 1 4 3 2 4 5 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dat[11][11];
int num[11][105];
int ask[11];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d",&dat[i][0]);
for(int j=1;j<=dat[i][0];j++)
{
scanf("%d",&dat[i][j]);
num[i][dat[i][j]]++;
}
}
while(m--)
{
queue<int> q;
int ans=0;
int nn;
scanf("%d",&nn);
for(int i=1;i<=nn;i++)scanf("%d",&ask[i]);
for(int i=1;i<=n;i++)
{
bool f=1;
for(int j=1;j<=nn;j++)
{
if(ask[j]>0&&num[i][ask[j]]==0){f=0;break;}
if(ask[j]<0&&num[i][-ask[j]]!=0){f=0;break;}
}
if(f==0)continue;
q.push(i);
ans++;
}
printf("%d\n",ans);
while(!q.empty())
{
int now=q.front();
q.pop();
for(int i=0;i<=dat[now][0];i++)printf("%d ",dat[now][i]);
printf("\n");
}
}
return 0;
}