# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
950218 | 2024-03-20T07:00:05 Z | Abito | Cookies (JOI23_cookies) | C++17 | 1000 ms | 24496 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=20,M=1e5; int n,b[N],m,dp[M],k,best[M]; bool sz[N]; vector<int> a,h[M]; vector<vector<int>> ans; bool vis[M]; int rec(int hsh){ //cout<<hsh<<endl; 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; int to=++k; h[to].resize(n); for (int j=0;j<n;j++) if (i&(1<<j)) h[to][j]=h[hsh][j]-1; else h[to][j]=h[hsh][j]; 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 9812 KB | Output is correct |
2 | Correct | 1 ms | 2648 KB | Output is correct |
3 | Correct | 2 ms | 2652 KB | Output is correct |
4 | Correct | 1 ms | 2652 KB | Output is correct |
5 | Correct | 1 ms | 2652 KB | Output is correct |
6 | Correct | 1 ms | 2652 KB | Output is correct |
7 | Runtime error | 82 ms | 24496 KB | Execution killed with signal 11 |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2648 KB | Output is correct |
2 | Correct | 1 ms | 2652 KB | Output is correct |
3 | Correct | 1 ms | 2652 KB | Output is correct |
4 | Correct | 2 ms | 2652 KB | Output is correct |
5 | Execution timed out | 1043 ms | 4460 KB | Time limit exceeded |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 10008 KB | Output is correct |
2 | Correct | 1 ms | 2652 KB | Output is correct |
3 | Correct | 1 ms | 2652 KB | Output is correct |
4 | Correct | 1 ms | 2652 KB | Output is correct |
5 | Correct | 1 ms | 2652 KB | Output is correct |
6 | Correct | 1 ms | 2652 KB | Output is correct |
7 | Correct | 1 ms | 2652 KB | Output is correct |
8 | Runtime error | 82 ms | 24404 KB | Execution killed with signal 11 |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 9812 KB | Output is correct |
2 | Correct | 1 ms | 2648 KB | Output is correct |
3 | Correct | 2 ms | 2652 KB | Output is correct |
4 | Correct | 1 ms | 2652 KB | Output is correct |
5 | Correct | 1 ms | 2652 KB | Output is correct |
6 | Correct | 1 ms | 2652 KB | Output is correct |
7 | Runtime error | 82 ms | 24496 KB | Execution killed with signal 11 |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 9812 KB | Output is correct |
2 | Correct | 1 ms | 2648 KB | Output is correct |
3 | Correct | 2 ms | 2652 KB | Output is correct |
4 | Correct | 1 ms | 2652 KB | Output is correct |
5 | Correct | 1 ms | 2652 KB | Output is correct |
6 | Correct | 1 ms | 2652 KB | Output is correct |
7 | Runtime error | 82 ms | 24496 KB | Execution killed with signal 11 |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 9812 KB | Output is correct |
2 | Correct | 1 ms | 2648 KB | Output is correct |
3 | Correct | 2 ms | 2652 KB | Output is correct |
4 | Correct | 1 ms | 2652 KB | Output is correct |
5 | Correct | 1 ms | 2652 KB | Output is correct |
6 | Correct | 1 ms | 2652 KB | Output is correct |
7 | Runtime error | 82 ms | 24496 KB | Execution killed with signal 11 |
8 | Halted | 0 ms | 0 KB | - |