Submission #950230

#TimeUsernameProblemLanguageResultExecution timeMemory
950230AbitoCookies (JOI23_cookies)C++17
0 / 100
1072 ms27396 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,M=1e6; int n,b[N],m,dp[M],k,best[M]; bool sz[N]; vector<int> a,h[M]; vector<vector<int>> ans; map<vector<int>,int> mp; bool vis[M]; int rec(int hsh){ //cout<<hsh<<endl; mp[h[hsh]]=hsh; bool z=1; for (auto u:h[hsh]) z&=(!u); if (z) return 0; if (vis[hsh]) return dp[hsh]; dp[hsh]=1e6;vis[hsh]=1; 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)) && h[hsh][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]=h[hsh][j]-1; else c[j]=h[hsh][j]; int to=0; if (!mp[c]) to=++k,swap(c,h[to]); else to=mp[c]; int x=rec(to)+1; if (x<dp[hsh]) dp[hsh]=x,best[hsh]=to; } return dp[hsh]; } void getans(int hsh){ bool z=1; for (auto u:h[hsh]) z&=(!u); if (z) return; vector<int> d; for (int i=0;i<n;i++) if (h[best[hsh]][i]<h[hsh][i]) d.pb(i); ans.pb(d); getans(best[hsh]); 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; h[++k]=a; int x=rec(1); if (x>=1e6){ cout<<-1<<endl; return 0; }cout<<x<<endl; getans(1); for (auto v:ans){ cout<<v.size()<<' '; for (auto u:v) cout<<u+1<<' ';cout<<endl; } return 0; }

Compilation message (stderr)

cookies.cpp: In function 'int32_t main()':
cookies.cpp:70:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   70 |         for (auto u:v) cout<<u+1<<' ';cout<<endl;
      |         ^~~
cookies.cpp:70:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   70 |         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...