제출 #950186

#제출 시각아이디문제언어결과실행 시간메모리
950186AbitoCookies (JOI23_cookies)C++17
0 / 100
1096 ms6200 KiB
#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=20;
int n,b[N],m;
bool sz[N];
vector<int> a;
map<vector<int>,int> dp;
map<vector<int>,vector<int>> best;
vector<vector<int>> ans;
int rec(vector<int> v){
    bool z=1;
    for (auto u:v) z&=(!u);
    if (z) return 0;
    if (dp.find(v)!=dp.end()) return dp[v];
    dp[v]=1e6;int d=dp[v];
    for (int i=1;i<(1<<n);i++){
        if (!sz[__builtin_popcount(i)]) continue;
        bool go=1;
        for (int j=0;j<n;j++) if ((i&(1<<j)) && v[j]<=0) {go=0;break;}
        if (!go) continue;
        vector<int> c(n);
        for (int j=0;j<n;j++) if (i&(1<<j)) c[j]=v[j]-1; else c[j]=v[j];
        int x=rec(c)+1;
        if (x<d) d=x,best[v]=c;
    }return dp[v]=d;
}
void getans(vector<int> v){
    bool z=1;
    for (auto u:v) z&=(!u);
    if (z) return;
    vector<int> c=best[v],d;
    for (int i=0;i<n;i++) if (v[i]>c[i]) d.pb(i);
    ans.pb(d);
    getans(best[v]);
    return;
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n;a.resize(n);
    for (int i=0;i<n;i++) cin>>a[i];
    cin>>m;
    for (int j=0;j<m;j++) cin>>b[j],sz[b[j]]=1;
    int x=rec(a);
    if (x>=1e6){
        cout<<-1<<endl;
        return 0;
    }cout<<x<<endl;
    getans(a);
    for (auto v:ans){
        cout<<v.size()<<' ';
        for (auto u:v) cout<<u+1<<' ';cout<<endl;
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

cookies.cpp: In function 'int32_t main()':
cookies.cpp:63:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   63 |         for (auto u:v) cout<<u+1<<' ';cout<<endl;
      |         ^~~
cookies.cpp:63:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   63 |         for (auto u:v) cout<<u+1<<' ';cout<<endl;
      |                                       ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...