Submission #129616

#TimeUsernameProblemLanguageResultExecution timeMemory
129616davitmargFriends (BOI17_friends)C++17
20 / 100
65 ms10488 KiB
/*DavitMarg*/ #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #include <map> #include <set> #include <queue> #include <iomanip> #include <stack> #include <cassert> #include <iterator> #include <bitset> #include <fstream> #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin(),v.end() using namespace std; map<pair<int,int>,bool> edge; int n,p,q,lst[(1<<17)+5],mask[200005],dp[(1<<17)+5],can[(1<<17)+5],pop[(1<<17)+5]; vector<int> g[200005]; void print(int msk) { cout<<pop[msk]<<" "; for(int i=0;i<n;i++) if(((1<<i)&msk)) cout<<i<<" "; cout<<endl; } int main() { cin >> n >> p >> q; for(int i=0;i<n;i++) { int p; int m; scanf("%d",&m); while(m--) { scanf("%d",&p); g[i].PB(p); edge[MP(i,p)]=1; mask[i]|=(1<<p); } } for(int i=0;i<n;i++) for(int j=0;j<g[i].size();j++) if(edge[MP(i,g[j][j])]!=edge[MP(g[j][j],i)]) { cout<<"detention"<<endl; return 0; } dp[0]=1; for(int i=1;i<(1<<n);i++) pop[i]=__builtin_popcount(i); for(int i=1;i<(1<<n);i++) { if(pop[i]>p) continue; int cnt=0; can[i]=1; for(int j=0;j<n;j++) { if(((1<<j)&i)==0) continue; cnt+=pop[i^(mask[j]|i)]; } if(cnt>q) can[i]=0; dp[i]=can[i]; } for(int i=1;i<(1<<n);i++) { int msk=i; while(msk>0) { if(can[msk] && dp[i^msk]) { dp[i]=1; lst[i]=msk; break; } msk=(msk-1)&i; } } if(!dp[(1<<n)-1]) { cout<<"detention"<<endl; return 0; } int cnt=0; int msk=(1<<n)-1; while(msk) { cnt++; msk^=lst[msk]; } cout<<"home\n"<<cnt<<endl; msk=(1<<n)-1; while(msk) { print(lst[msk]); msk^=lst[msk]; } return 0; } /* 5 14 5 5 0 5 9 5 12 10 0 7 7 7 12 8 4 7 10 0 12 0 5 0 7 7 12 0 13 */

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:54:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<g[i].size();j++)
               ~^~~~~~~~~~~~
friends.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&m);
   ~~~~~^~~~~~~~~
friends.cpp:47:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&p);
    ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...