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>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=16,M=4e4;
int n,m,a[N],b[N],s,mn=INT_MAX,dp[M];
vector<int> v,adj[M];
bool sz[N],vis[M];
vector<vector<int>> ans;
int rec(int mask){
if (__builtin_popcount(mask)==s) return 0;
if (vis[mask]) return dp[mask];
vis[mask]=1;dp[mask]=1e6;
for (auto u:adj[mask]){
set<int> z;bool go=1;int x=0;
for (int i=0;i<s;i++){
if ((u&(1<<i)) && !(mask&(1<<i))){
if (z.count(v[i])) go=0;
z.ep(v[i]);
x++;
}
}
if (go && sz[x]) dp[mask]=min(dp[mask],rec(u)+1);
}return dp[mask];
}
void getans(int mask){
if (__builtin_popcount(mask)==s) return;
for (auto u:adj[mask]){
set<int> z;bool go=1;int x=0;
for (int i=0;i<s;i++){
if ((u&(1<<i)) && !(mask&(1<<i))){
if (z.count(v[i])) go=0;
z.ep(v[i]);
x++;
}
}
if (go && sz[x] && dp[u]+1==dp[mask]){
vector<int> z;
for (int i=0;i<s;i++){
if ((u&(1<<i)) && !(mask&(1<<i))) z.pb(v[i]);
}
ans.pb(z);
getans(u);
return;
}
}return;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for (int i=1;i<=n;i++){
cin>>a[i];s+=a[i];
for (int j=0;j<a[i];j++) v.pb(i);
}
cin>>m;
for (int i=1;i<=m;i++) cin>>b[i],sz[b[i]]=1;
for (int i=(1<<s)-2;i>=0;i--){
for (int j=0;j<s;j++){
if (i&(1<<j)) continue;
int x=i^(1<<j);adj[i].pb(x);
for (auto u:adj[x]) adj[i].pb(u);
}
}
int x=rec(0);
if (x>=1e6){
cout<<-1<<endl;
return 0;
}cout<<x<<endl;
getans(0);
for (auto u:ans){
cout<<u.size()<<' ';
for (auto y:u) cout<<y<<' ';
cout<<endl;
}
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |