답안 #836905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836905 2023-08-24T17:02:25 Z alvingogo Cookies (JOI23_cookies) C++14
19 / 100
35 ms 55704 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
using namespace std;

int 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];
    }
    reverse(b.begin()+1,b.end());
    vector<vector<bitset<gd> > > bt(m+1);
    vector<bitset<gd> > lp(gd+1);
    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].resize(1);
    bt[0][0][0]=1;
    for(int i=0;i<m;i++){
        bt[i+1].resize(s/(b[i+1])+1);
        for(int j=0;j<bt[i].size();j++){
            bt[i+1][j]|=bt[i][j];
        }
        for(int j=1;j<bt[i+1].size();j++){
            bt[i+1][j]|=(bt[i+1][j-1]<<b[i+1])&lp[j];
        }
    }
    for(int i=0;i<=m;i++){
        for(int j=0;j<bt[i].size();j++){
            if(bt[i][j][s]){
                vector<int> k;
                while(i>0 && j>0){
                    if(j<bt[i-1].size() && bt[i-1][j][s]){
                        i--;
                    }
                    else{
                        k.push_back(b[i]);
                        s-=b[i];
                        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;
}

Compilation message

cookies.cpp: In function 'int main()':
cookies.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::bitset<15005> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int j=0;j<bt[i].size();j++){
      |                     ~^~~~~~~~~~~~~
cookies.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::bitset<15005> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for(int j=1;j<bt[i+1].size();j++){
      |                     ~^~~~~~~~~~~~~~~
cookies.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::bitset<15005> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int j=0;j<bt[i].size();j++){
      |                     ~^~~~~~~~~~~~~
cookies.cpp:59:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::bitset<15005> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |                     if(j<bt[i-1].size() && bt[i-1][j][s]){
      |                        ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 27988 KB Output is correct
2 Correct 14 ms 27884 KB Output is correct
3 Correct 16 ms 27988 KB Output is correct
4 Correct 15 ms 27988 KB Output is correct
5 Correct 13 ms 27988 KB Output is correct
6 Correct 13 ms 27964 KB Output is correct
7 Correct 14 ms 27900 KB Output is correct
8 Correct 18 ms 28876 KB Output is correct
9 Correct 16 ms 27988 KB Output is correct
10 Correct 19 ms 34744 KB Output is correct
11 Correct 14 ms 28884 KB Output is correct
12 Correct 15 ms 31188 KB Output is correct
13 Correct 17 ms 28860 KB Output is correct
14 Correct 15 ms 29164 KB Output is correct
15 Correct 14 ms 29044 KB Output is correct
16 Correct 15 ms 29124 KB Output is correct
17 Correct 16 ms 28244 KB Output is correct
18 Incorrect 14 ms 28740 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 27964 KB Output is correct
2 Correct 15 ms 27996 KB Output is correct
3 Correct 15 ms 27988 KB Output is correct
4 Correct 14 ms 27944 KB Output is correct
5 Correct 14 ms 28888 KB Output is correct
6 Correct 14 ms 27992 KB Output is correct
7 Correct 14 ms 27892 KB Output is correct
8 Correct 14 ms 28892 KB Output is correct
9 Correct 20 ms 33540 KB Output is correct
10 Correct 35 ms 55704 KB Output is correct
11 Correct 14 ms 27988 KB Output is correct
12 Correct 15 ms 27968 KB Output is correct
13 Correct 15 ms 27908 KB Output is correct
14 Correct 14 ms 27988 KB Output is correct
15 Correct 17 ms 27900 KB Output is correct
16 Correct 16 ms 27988 KB Output is correct
17 Correct 13 ms 28020 KB Output is correct
18 Correct 23 ms 34940 KB Output is correct
19 Correct 22 ms 37216 KB Output is correct
20 Correct 16 ms 28380 KB Output is correct
21 Correct 16 ms 28100 KB Output is correct
22 Correct 14 ms 28244 KB Output is correct
23 Correct 14 ms 27904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 27992 KB Output is correct
2 Correct 14 ms 27920 KB Output is correct
3 Correct 14 ms 27988 KB Output is correct
4 Correct 14 ms 27872 KB Output is correct
5 Correct 17 ms 27988 KB Output is correct
6 Correct 16 ms 27988 KB Output is correct
7 Correct 14 ms 27988 KB Output is correct
8 Correct 16 ms 27988 KB Output is correct
9 Correct 16 ms 27988 KB Output is correct
10 Correct 12 ms 27972 KB Output is correct
11 Correct 12 ms 27892 KB Output is correct
12 Correct 13 ms 27900 KB Output is correct
13 Correct 13 ms 27988 KB Output is correct
14 Correct 13 ms 27908 KB Output is correct
15 Correct 12 ms 27988 KB Output is correct
16 Correct 12 ms 27988 KB Output is correct
17 Correct 16 ms 27988 KB Output is correct
18 Correct 14 ms 27988 KB Output is correct
19 Correct 14 ms 27988 KB Output is correct
20 Correct 14 ms 27924 KB Output is correct
21 Correct 15 ms 28000 KB Output is correct
22 Correct 14 ms 28012 KB Output is correct
23 Correct 15 ms 27996 KB Output is correct
24 Correct 14 ms 28044 KB Output is correct
25 Correct 14 ms 27988 KB Output is correct
26 Correct 15 ms 27920 KB Output is correct
27 Correct 18 ms 28036 KB Output is correct
28 Correct 15 ms 27988 KB Output is correct
29 Correct 14 ms 27980 KB Output is correct
30 Correct 14 ms 27920 KB Output is correct
31 Correct 15 ms 27988 KB Output is correct
32 Correct 15 ms 27936 KB Output is correct
33 Correct 13 ms 27992 KB Output is correct
34 Correct 13 ms 27900 KB Output is correct
35 Correct 13 ms 27996 KB Output is correct
36 Correct 13 ms 27988 KB Output is correct
37 Correct 14 ms 27988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 27988 KB Output is correct
2 Correct 14 ms 27884 KB Output is correct
3 Correct 16 ms 27988 KB Output is correct
4 Correct 15 ms 27988 KB Output is correct
5 Correct 13 ms 27988 KB Output is correct
6 Correct 13 ms 27964 KB Output is correct
7 Correct 14 ms 27900 KB Output is correct
8 Correct 18 ms 28876 KB Output is correct
9 Correct 16 ms 27988 KB Output is correct
10 Correct 19 ms 34744 KB Output is correct
11 Correct 14 ms 28884 KB Output is correct
12 Correct 15 ms 31188 KB Output is correct
13 Correct 17 ms 28860 KB Output is correct
14 Correct 15 ms 29164 KB Output is correct
15 Correct 14 ms 29044 KB Output is correct
16 Correct 15 ms 29124 KB Output is correct
17 Correct 16 ms 28244 KB Output is correct
18 Incorrect 14 ms 28740 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 27988 KB Output is correct
2 Correct 14 ms 27884 KB Output is correct
3 Correct 16 ms 27988 KB Output is correct
4 Correct 15 ms 27988 KB Output is correct
5 Correct 13 ms 27988 KB Output is correct
6 Correct 13 ms 27964 KB Output is correct
7 Correct 14 ms 27900 KB Output is correct
8 Correct 18 ms 28876 KB Output is correct
9 Correct 16 ms 27988 KB Output is correct
10 Correct 19 ms 34744 KB Output is correct
11 Correct 14 ms 28884 KB Output is correct
12 Correct 15 ms 31188 KB Output is correct
13 Correct 17 ms 28860 KB Output is correct
14 Correct 15 ms 29164 KB Output is correct
15 Correct 14 ms 29044 KB Output is correct
16 Correct 15 ms 29124 KB Output is correct
17 Correct 16 ms 28244 KB Output is correct
18 Incorrect 14 ms 28740 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 27988 KB Output is correct
2 Correct 14 ms 27884 KB Output is correct
3 Correct 16 ms 27988 KB Output is correct
4 Correct 15 ms 27988 KB Output is correct
5 Correct 13 ms 27988 KB Output is correct
6 Correct 13 ms 27964 KB Output is correct
7 Correct 14 ms 27900 KB Output is correct
8 Correct 18 ms 28876 KB Output is correct
9 Correct 16 ms 27988 KB Output is correct
10 Correct 19 ms 34744 KB Output is correct
11 Correct 14 ms 28884 KB Output is correct
12 Correct 15 ms 31188 KB Output is correct
13 Correct 17 ms 28860 KB Output is correct
14 Correct 15 ms 29164 KB Output is correct
15 Correct 14 ms 29044 KB Output is correct
16 Correct 15 ms 29124 KB Output is correct
17 Correct 16 ms 28244 KB Output is correct
18 Incorrect 14 ms 28740 KB Output isn't correct
19 Halted 0 ms 0 KB -