# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
950186 | 2024-03-20T06:36:33 Z | Abito | Cookies (JOI23_cookies) | C++17 | 1000 ms | 6200 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; 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 516 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 2 ms | 348 KB | Output is correct |
8 | Execution timed out | 1038 ms | 2204 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 604 KB | Output is correct |
5 | Execution timed out | 1096 ms | 2032 KB | Time limit exceeded |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 460 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 2 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 452 KB | Output is correct |
10 | Correct | 1 ms | 344 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 1 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Correct | 1 ms | 348 KB | Output is correct |
19 | Correct | 1 ms | 348 KB | Output is correct |
20 | Correct | 2 ms | 348 KB | Output is correct |
21 | Correct | 1 ms | 344 KB | Output is correct |
22 | Correct | 1 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 348 KB | Output is correct |
24 | Correct | 4 ms | 604 KB | Output is correct |
25 | Correct | 3 ms | 540 KB | Output is correct |
26 | Correct | 4 ms | 604 KB | Output is correct |
27 | Correct | 5 ms | 860 KB | Output is correct |
28 | Correct | 2 ms | 348 KB | Output is correct |
29 | Correct | 11 ms | 1116 KB | Output is correct |
30 | Correct | 7 ms | 860 KB | Output is correct |
31 | Correct | 93 ms | 2132 KB | Output is correct |
32 | Correct | 3 ms | 344 KB | Output is correct |
33 | Correct | 10 ms | 1372 KB | Output is correct |
34 | Correct | 30 ms | 848 KB | Output is correct |
35 | Execution timed out | 1061 ms | 6200 KB | Time limit exceeded |
36 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 516 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 2 ms | 348 KB | Output is correct |
8 | Execution timed out | 1038 ms | 2204 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 516 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 2 ms | 348 KB | Output is correct |
8 | Execution timed out | 1038 ms | 2204 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 516 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 2 ms | 348 KB | Output is correct |
8 | Execution timed out | 1038 ms | 2204 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |