# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
950186 | Abito | Cookies (JOI23_cookies) | C++17 | 1096 ms | 6200 KiB |
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=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;
}
Compilation message (stderr)
# | 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... |