Submission #1037805

# Submission time Handle Problem Language Result Execution time Memory
1037805 2024-07-29T08:36:20 Z 김은성(#10980) Cookies (JOI23_cookies) C++17
6 / 100
159 ms 257872 KB
#include <bits/stdc++.h>
using namespace std;
const int INF = 1234123412;
int a[15009];
bool dp[2][509][1509];
int cnt[15009];
short opt[509][509][509];
bool pos[15009];
int main(){
    int n, m, i, j, k, v, N = 0;
    scanf("%d", &n);
    for(i=1; i<=n; i++){
        scanf("%d", &a[i]);
        cnt[i] = a[i];
        N += a[i];
    }
    sort(cnt+1, cnt+n+1, [](int &u, int &v){return u > v;});
    for(i=n; i>=1; i--)
        cnt[i] += cnt[i+1];
    scanf("%d", &m);
    for(i=1; i<=m; i++){
        scanf("%d", &v);
        pos[v] = 1;
    }
    for(j=0; j<=N; j++)
        memset(dp[n%2][j], 0, sizeof(dp[n%2][j]));
    dp[n%2][0][0] = 1;
    for(i=n; i>=1; i--){
        if(pos[i]){
            for(j=0; j<cnt[i]; j++){
                for(k=0; k<n; k++){
                    if(dp[i%2][j][k]){
                        dp[i%2][j+1][k+1] = 1;
                        opt[i][j+1][k+1] = -1;
                    }
                }
            }
        }
        for(j=0; j<=N; j++)
            memset(dp[(i-1)%2][j], 0, sizeof(dp[(i-1)%2][j]));
        for(j=0; j<=cnt[i]; j++){
            for(k=0; k<=n; k++){
                if(dp[i%2][j][k] && j+k <= N){
                    dp[(i-1)%2][j+k][k] = 1;
                    opt[i-1][j+k][k] = j;
                }
                //printf("dp[%d][%d][%d]=%d\n", i, j, k, dp[i%2][j][k]);
            }
        }
    }
    int row = 1, col = N, kk = 0;
    while(kk <= 1500){
        if(dp[1][N][kk])
            break;
        kk++;
    }
    if(kk >= 1500){
        printf("-1\n");
        return 0;
    }
    vector<int> vec;
    while(row <= n && col > 0 && kk>0){
        //printf("row=%d col=%d kk=%d\n", row, col, kk);
        if(opt[row][col][kk] == -1){
            vec.push_back(row);
            col--;
            kk--;
        }
        else{
            col = opt[row][col][kk];
            row++;
        }
        //printf("row=%d col=%d kk=%d\n", row, col, kk);
    }
    for(i=0; i<vec.size()/2; i++)
        swap(vec[i], vec[(int)vec.size()-1-i]);
    priority_queue<pair<int, int> > qa;
    for(i=1; i<=n; i++)
        qa.push(make_pair(a[i], i));
    printf("%d\n", vec.size());
    for(i=0; i<vec.size(); i++){
        printf("%d ", vec[i]);
        vector<pair<int, int> > temp;
        for(int j=0; j<vec[i]; j++){
            temp.push_back(qa.top());
            temp.back().first--;
            printf("%d ", temp.back().second);
            qa.pop();
        }
        printf("\n");
        while(!temp.empty()){
            qa.push(temp.back());
            temp.pop_back();
        }
    }
    return 0;
}

Compilation message

cookies.cpp: In function 'int main()':
cookies.cpp:75:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(i=0; i<vec.size()/2; i++)
      |              ~^~~~~~~~~~~~~
cookies.cpp:80:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   80 |     printf("%d\n", vec.size());
      |             ~^     ~~~~~~~~~~
      |              |             |
      |              int           std::vector<int>::size_type {aka long unsigned int}
      |             %ld
cookies.cpp:81:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for(i=0; i<vec.size(); i++){
      |              ~^~~~~~~~~~~
cookies.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
cookies.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
cookies.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d", &m);
      |     ~~~~~^~~~~~~~~~
cookies.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf("%d", &v);
      |         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 91 ms 257852 KB Output is correct
9 Correct 76 ms 257620 KB Output is correct
10 Correct 159 ms 257872 KB Output is correct
11 Correct 90 ms 257620 KB Output is correct
12 Correct 98 ms 257872 KB Output is correct
13 Correct 84 ms 257812 KB Output is correct
14 Correct 96 ms 249412 KB Output is correct
15 Correct 94 ms 253776 KB Output is correct
16 Correct 96 ms 257796 KB Output is correct
17 Correct 74 ms 255824 KB Output is correct
18 Correct 101 ms 255892 KB Output is correct
19 Correct 81 ms 255772 KB Output is correct
20 Correct 94 ms 255748 KB Output is correct
21 Correct 94 ms 255828 KB Output is correct
22 Correct 103 ms 255828 KB Output is correct
23 Correct 110 ms 255840 KB Output is correct
24 Correct 77 ms 253780 KB Output is correct
25 Correct 78 ms 253664 KB Output is correct
26 Correct 79 ms 253520 KB Output is correct
27 Correct 77 ms 253720 KB Output is correct
28 Correct 91 ms 253676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 77 ms 257780 KB Output is correct
6 Correct 75 ms 257704 KB Output is correct
7 Incorrect 1 ms 4444 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Incorrect 1 ms 4440 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 91 ms 257852 KB Output is correct
9 Correct 76 ms 257620 KB Output is correct
10 Correct 159 ms 257872 KB Output is correct
11 Correct 90 ms 257620 KB Output is correct
12 Correct 98 ms 257872 KB Output is correct
13 Correct 84 ms 257812 KB Output is correct
14 Correct 96 ms 249412 KB Output is correct
15 Correct 94 ms 253776 KB Output is correct
16 Correct 96 ms 257796 KB Output is correct
17 Correct 74 ms 255824 KB Output is correct
18 Correct 101 ms 255892 KB Output is correct
19 Correct 81 ms 255772 KB Output is correct
20 Correct 94 ms 255748 KB Output is correct
21 Correct 94 ms 255828 KB Output is correct
22 Correct 103 ms 255828 KB Output is correct
23 Correct 110 ms 255840 KB Output is correct
24 Correct 77 ms 253780 KB Output is correct
25 Correct 78 ms 253664 KB Output is correct
26 Correct 79 ms 253520 KB Output is correct
27 Correct 77 ms 253720 KB Output is correct
28 Correct 91 ms 253676 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 0 ms 4444 KB Output is correct
34 Correct 0 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Incorrect 1 ms 4440 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 91 ms 257852 KB Output is correct
9 Correct 76 ms 257620 KB Output is correct
10 Correct 159 ms 257872 KB Output is correct
11 Correct 90 ms 257620 KB Output is correct
12 Correct 98 ms 257872 KB Output is correct
13 Correct 84 ms 257812 KB Output is correct
14 Correct 96 ms 249412 KB Output is correct
15 Correct 94 ms 253776 KB Output is correct
16 Correct 96 ms 257796 KB Output is correct
17 Correct 74 ms 255824 KB Output is correct
18 Correct 101 ms 255892 KB Output is correct
19 Correct 81 ms 255772 KB Output is correct
20 Correct 94 ms 255748 KB Output is correct
21 Correct 94 ms 255828 KB Output is correct
22 Correct 103 ms 255828 KB Output is correct
23 Correct 110 ms 255840 KB Output is correct
24 Correct 77 ms 253780 KB Output is correct
25 Correct 78 ms 253664 KB Output is correct
26 Correct 79 ms 253520 KB Output is correct
27 Correct 77 ms 253720 KB Output is correct
28 Correct 91 ms 253676 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 0 ms 4444 KB Output is correct
34 Correct 0 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Incorrect 1 ms 4440 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 91 ms 257852 KB Output is correct
9 Correct 76 ms 257620 KB Output is correct
10 Correct 159 ms 257872 KB Output is correct
11 Correct 90 ms 257620 KB Output is correct
12 Correct 98 ms 257872 KB Output is correct
13 Correct 84 ms 257812 KB Output is correct
14 Correct 96 ms 249412 KB Output is correct
15 Correct 94 ms 253776 KB Output is correct
16 Correct 96 ms 257796 KB Output is correct
17 Correct 74 ms 255824 KB Output is correct
18 Correct 101 ms 255892 KB Output is correct
19 Correct 81 ms 255772 KB Output is correct
20 Correct 94 ms 255748 KB Output is correct
21 Correct 94 ms 255828 KB Output is correct
22 Correct 103 ms 255828 KB Output is correct
23 Correct 110 ms 255840 KB Output is correct
24 Correct 77 ms 253780 KB Output is correct
25 Correct 78 ms 253664 KB Output is correct
26 Correct 79 ms 253520 KB Output is correct
27 Correct 77 ms 253720 KB Output is correct
28 Correct 91 ms 253676 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 77 ms 257780 KB Output is correct
34 Correct 75 ms 257704 KB Output is correct
35 Incorrect 1 ms 4444 KB Output isn't correct
36 Halted 0 ms 0 KB -