Submission #836843

# Submission time Handle Problem Language Result Execution time Memory
836843 2023-08-24T16:15:43 Z alvingogo Cookies (JOI23_cookies) C++14
19 / 100
848 ms 1048576 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
#define int long long
using namespace std;

signed main(){
    AquA;
    int n;
    cin >> n;
    vector<int> a(n);
    int s=0;
    const int gd=15005;
    vector<int> c(gd);
    for(int i=0;i<n;i++){
        cin >> a[i];
        c[a[i]]++;
        s+=a[i];
    }
    for(int i=gd-2;i>=1;i--){
        c[i]+=c[i+1];
    }
    for(int i=2;i<gd;i++){
        c[i]+=c[i-1];
    }
    int m;
    cin >> m;
    vector<int> b(m+1);
    for(int i=1;i<=m;i++){
        cin >> b[i];
    }
    sort(b.begin()+1,b.end(),greater<int>());
    vector<vector<bitset<gd> > > bt(gd,vector<bitset<gd> >(m+1));
    vector<bitset<gd> > lp(gd);
    for(int i=1;i<gd;i++){
        lp[i]|=lp[i-1];
        for(int j=c[i-1]+1;j<=c[i];j++){
            lp[i][j]=1;
        }
    }
    bt[0][0][0]=1;
    for(int i=0;i<gd;i++){
        for(int j=0;j<m && i*(b[j+1])<gd;j++){
            bt[i][j+1]|=bt[i][j];
        }
        for(int j=1;j<=m && (i+1)*b[j]<gd;j++){
            bt[i+1][j]|=(bt[i][j]<<b[j])&lp[i+1];
        }
    }
    for(int i=0;i<gd;i++){
        for(int j=0;j<=m;j++){
            if(bt[i][j][s]){
                vector<int> k;
                while(i>0 && j>0){
                    if(i>0 && bt[i-1][j][s-b[j]]){
                        k.push_back(b[j]);
                        s-=b[j];
                        i--;
                    }
                    else{
                        j--;
                    }
                }
                p_q<pair<int,int> > pq;
                for(int f=0;f<n;f++){
                    pq.push({a[f],f});
                }
                cout << k.size() << "\n";
                for(auto h:k){
                    vector<pair<int,int> > d;
                    cout << h << ' ';
                    for(int p=0;p<h;p++){
                        d.push_back(pq.top());
                        pq.pop();
                    }
                    for(auto z:d){
                        pq.push({z.fs-1,z.sc});
                        cout << z.sc+1 << " ";
                    }
                    cout << "\n";
                }
                return 0;
            }
        }
    }
    cout << -1 << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 61 ms 139036 KB Output is correct
2 Correct 53 ms 83748 KB Output is correct
3 Correct 57 ms 83836 KB Output is correct
4 Correct 40 ms 83796 KB Output is correct
5 Correct 54 ms 111312 KB Output is correct
6 Correct 57 ms 111316 KB Output is correct
7 Correct 67 ms 138992 KB Output is correct
8 Correct 57 ms 83828 KB Output is correct
9 Correct 42 ms 83788 KB Output is correct
10 Runtime error 848 ms 1048576 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 83784 KB Output is correct
2 Correct 68 ms 83740 KB Output is correct
3 Correct 55 ms 83832 KB Output is correct
4 Correct 57 ms 83788 KB Output is correct
5 Correct 69 ms 83792 KB Output is correct
6 Correct 45 ms 83836 KB Output is correct
7 Correct 54 ms 83844 KB Output is correct
8 Correct 68 ms 83796 KB Output is correct
9 Correct 71 ms 83788 KB Output is correct
10 Correct 52 ms 84044 KB Output is correct
11 Correct 49 ms 83796 KB Output is correct
12 Correct 56 ms 83740 KB Output is correct
13 Correct 55 ms 83800 KB Output is correct
14 Correct 56 ms 83796 KB Output is correct
15 Correct 54 ms 83836 KB Output is correct
16 Correct 44 ms 83792 KB Output is correct
17 Correct 44 ms 83788 KB Output is correct
18 Correct 47 ms 83884 KB Output is correct
19 Correct 49 ms 83916 KB Output is correct
20 Correct 53 ms 83788 KB Output is correct
21 Correct 49 ms 83924 KB Output is correct
22 Correct 48 ms 83816 KB Output is correct
23 Correct 41 ms 83784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 138956 KB Output is correct
2 Correct 45 ms 83788 KB Output is correct
3 Correct 64 ms 83732 KB Output is correct
4 Correct 51 ms 83796 KB Output is correct
5 Correct 43 ms 83788 KB Output is correct
6 Correct 57 ms 111316 KB Output is correct
7 Correct 56 ms 111324 KB Output is correct
8 Correct 62 ms 138956 KB Output is correct
9 Correct 57 ms 83792 KB Output is correct
10 Correct 54 ms 83744 KB Output is correct
11 Correct 59 ms 83716 KB Output is correct
12 Correct 56 ms 83804 KB Output is correct
13 Correct 45 ms 83764 KB Output is correct
14 Correct 51 ms 83788 KB Output is correct
15 Correct 62 ms 111316 KB Output is correct
16 Correct 62 ms 111388 KB Output is correct
17 Correct 77 ms 139052 KB Output is correct
18 Correct 56 ms 111308 KB Output is correct
19 Correct 88 ms 138960 KB Output is correct
20 Correct 68 ms 138992 KB Output is correct
21 Correct 70 ms 138916 KB Output is correct
22 Correct 89 ms 138956 KB Output is correct
23 Correct 67 ms 139040 KB Output is correct
24 Correct 67 ms 138944 KB Output is correct
25 Correct 64 ms 138956 KB Output is correct
26 Correct 65 ms 138956 KB Output is correct
27 Correct 65 ms 139024 KB Output is correct
28 Correct 89 ms 194124 KB Output is correct
29 Correct 69 ms 139032 KB Output is correct
30 Correct 70 ms 139088 KB Output is correct
31 Correct 102 ms 221732 KB Output is correct
32 Correct 82 ms 166556 KB Output is correct
33 Correct 83 ms 166488 KB Output is correct
34 Correct 82 ms 166476 KB Output is correct
35 Correct 139 ms 304772 KB Output is correct
36 Correct 179 ms 442588 KB Output is correct
37 Correct 54 ms 111308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 139036 KB Output is correct
2 Correct 53 ms 83748 KB Output is correct
3 Correct 57 ms 83836 KB Output is correct
4 Correct 40 ms 83796 KB Output is correct
5 Correct 54 ms 111312 KB Output is correct
6 Correct 57 ms 111316 KB Output is correct
7 Correct 67 ms 138992 KB Output is correct
8 Correct 57 ms 83828 KB Output is correct
9 Correct 42 ms 83788 KB Output is correct
10 Runtime error 848 ms 1048576 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 139036 KB Output is correct
2 Correct 53 ms 83748 KB Output is correct
3 Correct 57 ms 83836 KB Output is correct
4 Correct 40 ms 83796 KB Output is correct
5 Correct 54 ms 111312 KB Output is correct
6 Correct 57 ms 111316 KB Output is correct
7 Correct 67 ms 138992 KB Output is correct
8 Correct 57 ms 83828 KB Output is correct
9 Correct 42 ms 83788 KB Output is correct
10 Runtime error 848 ms 1048576 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 139036 KB Output is correct
2 Correct 53 ms 83748 KB Output is correct
3 Correct 57 ms 83836 KB Output is correct
4 Correct 40 ms 83796 KB Output is correct
5 Correct 54 ms 111312 KB Output is correct
6 Correct 57 ms 111316 KB Output is correct
7 Correct 67 ms 138992 KB Output is correct
8 Correct 57 ms 83828 KB Output is correct
9 Correct 42 ms 83788 KB Output is correct
10 Runtime error 848 ms 1048576 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -