Submission #950157

# Submission time Handle Problem Language Result Execution time Memory
950157 2024-03-20T05:58:17 Z Abito Cookies (JOI23_cookies) C++17
0 / 100
951 ms 1048576 KB
#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
1 Correct 6 ms 1884 KB Output is correct
2 Correct 1 ms 1408 KB Output is correct
3 Correct 1 ms 1368 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 54 ms 4052 KB Output is correct
8 Runtime error 2 ms 2396 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 951 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1888 KB Output is correct
2 Runtime error 897 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1884 KB Output is correct
2 Correct 1 ms 1408 KB Output is correct
3 Correct 1 ms 1368 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 54 ms 4052 KB Output is correct
8 Runtime error 2 ms 2396 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1884 KB Output is correct
2 Correct 1 ms 1408 KB Output is correct
3 Correct 1 ms 1368 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 54 ms 4052 KB Output is correct
8 Runtime error 2 ms 2396 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1884 KB Output is correct
2 Correct 1 ms 1408 KB Output is correct
3 Correct 1 ms 1368 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 54 ms 4052 KB Output is correct
8 Runtime error 2 ms 2396 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -