답안 #950155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950155 2024-03-20T05:57:54 Z Abito Cookies (JOI23_cookies) C++17
컴파일 오류
0 ms 0 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=0;
    for (int i=0;i<M;i++) x+=adj[i].size();
    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;
}

Compilation message

cookies.cpp: In function 'int32_t main()':
cookies.cpp:75:9: error: redeclaration of 'long long int x'
   75 |     int x=rec(0);
      |         ^
cookies.cpp:73:10: note: 'long long int x' previously declared here
   73 |     }int x=0;
      |          ^