# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
950221 | 2024-03-20T07:00:43 Z | Abito | Cookies (JOI23_cookies) | C++17 | 1000 ms | 145372 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=1e6; 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 35656 KB | Output is correct |
2 | Correct | 6 ms | 24924 KB | Output is correct |
3 | Correct | 6 ms | 25040 KB | Output is correct |
4 | Correct | 6 ms | 24924 KB | Output is correct |
5 | Correct | 6 ms | 24924 KB | Output is correct |
6 | Correct | 5 ms | 24924 KB | Output is correct |
7 | Correct | 105 ms | 40052 KB | Output is correct |
8 | Execution timed out | 1043 ms | 26576 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 24920 KB | Output is correct |
2 | Correct | 6 ms | 24924 KB | Output is correct |
3 | Correct | 6 ms | 24924 KB | Output is correct |
4 | Correct | 6 ms | 25056 KB | Output is correct |
5 | Execution timed out | 1050 ms | 26704 KB | Time limit exceeded |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 40 ms | 35688 KB | Output is correct |
2 | Correct | 6 ms | 24920 KB | Output is correct |
3 | Correct | 6 ms | 24924 KB | Output is correct |
4 | Correct | 6 ms | 24924 KB | Output is correct |
5 | Correct | 7 ms | 24924 KB | Output is correct |
6 | Correct | 6 ms | 25092 KB | Output is correct |
7 | Correct | 5 ms | 24924 KB | Output is correct |
8 | Correct | 102 ms | 40140 KB | Output is correct |
9 | Correct | 5 ms | 24924 KB | Output is correct |
10 | Correct | 5 ms | 24924 KB | Output is correct |
11 | Correct | 6 ms | 24924 KB | Output is correct |
12 | Correct | 6 ms | 24924 KB | Output is correct |
13 | Correct | 7 ms | 25036 KB | Output is correct |
14 | Correct | 7 ms | 25036 KB | Output is correct |
15 | Correct | 25 ms | 39184 KB | Output is correct |
16 | Correct | 6 ms | 25176 KB | Output is correct |
17 | Runtime error | 141 ms | 145372 KB | Execution killed with signal 11 |
18 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 35656 KB | Output is correct |
2 | Correct | 6 ms | 24924 KB | Output is correct |
3 | Correct | 6 ms | 25040 KB | Output is correct |
4 | Correct | 6 ms | 24924 KB | Output is correct |
5 | Correct | 6 ms | 24924 KB | Output is correct |
6 | Correct | 5 ms | 24924 KB | Output is correct |
7 | Correct | 105 ms | 40052 KB | Output is correct |
8 | Execution timed out | 1043 ms | 26576 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 35656 KB | Output is correct |
2 | Correct | 6 ms | 24924 KB | Output is correct |
3 | Correct | 6 ms | 25040 KB | Output is correct |
4 | Correct | 6 ms | 24924 KB | Output is correct |
5 | Correct | 6 ms | 24924 KB | Output is correct |
6 | Correct | 5 ms | 24924 KB | Output is correct |
7 | Correct | 105 ms | 40052 KB | Output is correct |
8 | Execution timed out | 1043 ms | 26576 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 35656 KB | Output is correct |
2 | Correct | 6 ms | 24924 KB | Output is correct |
3 | Correct | 6 ms | 25040 KB | Output is correct |
4 | Correct | 6 ms | 24924 KB | Output is correct |
5 | Correct | 6 ms | 24924 KB | Output is correct |
6 | Correct | 5 ms | 24924 KB | Output is correct |
7 | Correct | 105 ms | 40052 KB | Output is correct |
8 | Execution timed out | 1043 ms | 26576 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |