답안 #1037811

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037811 2024-07-29T08:43:33 Z 김은성(#10980) Cookies (JOI23_cookies) C++17
63 / 100
162 ms 257976 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);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 0 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 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 101 ms 257840 KB Output is correct
9 Correct 95 ms 257708 KB Output is correct
10 Correct 162 ms 257876 KB Output is correct
11 Correct 111 ms 257616 KB Output is correct
12 Correct 107 ms 257872 KB Output is correct
13 Correct 111 ms 257868 KB Output is correct
14 Correct 108 ms 249584 KB Output is correct
15 Correct 110 ms 253776 KB Output is correct
16 Correct 113 ms 257864 KB Output is correct
17 Correct 103 ms 255756 KB Output is correct
18 Correct 100 ms 255812 KB Output is correct
19 Correct 93 ms 255828 KB Output is correct
20 Correct 95 ms 255660 KB Output is correct
21 Correct 119 ms 256084 KB Output is correct
22 Correct 119 ms 255852 KB Output is correct
23 Correct 120 ms 255828 KB Output is correct
24 Correct 97 ms 253620 KB Output is correct
25 Correct 98 ms 253776 KB Output is correct
26 Correct 95 ms 253520 KB Output is correct
27 Correct 92 ms 253520 KB Output is correct
28 Correct 105 ms 253520 KB Output is correct
# 결과 실행 시간 메모리 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 94 ms 257976 KB Output is correct
6 Correct 94 ms 257616 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 5464 KB Output is correct
9 Runtime error 6 ms 6232 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 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 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 4712 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6488 KB Output is correct
27 Correct 1 ms 6588 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6592 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6488 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 8680 KB Output is correct
36 Correct 1 ms 10588 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 0 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 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 101 ms 257840 KB Output is correct
9 Correct 95 ms 257708 KB Output is correct
10 Correct 162 ms 257876 KB Output is correct
11 Correct 111 ms 257616 KB Output is correct
12 Correct 107 ms 257872 KB Output is correct
13 Correct 111 ms 257868 KB Output is correct
14 Correct 108 ms 249584 KB Output is correct
15 Correct 110 ms 253776 KB Output is correct
16 Correct 113 ms 257864 KB Output is correct
17 Correct 103 ms 255756 KB Output is correct
18 Correct 100 ms 255812 KB Output is correct
19 Correct 93 ms 255828 KB Output is correct
20 Correct 95 ms 255660 KB Output is correct
21 Correct 119 ms 256084 KB Output is correct
22 Correct 119 ms 255852 KB Output is correct
23 Correct 120 ms 255828 KB Output is correct
24 Correct 97 ms 253620 KB Output is correct
25 Correct 98 ms 253776 KB Output is correct
26 Correct 95 ms 253520 KB Output is correct
27 Correct 92 ms 253520 KB Output is correct
28 Correct 105 ms 253520 KB Output is correct
29 Correct 1 ms 6488 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 4444 KB Output is correct
32 Correct 0 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 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 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 0 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 4712 KB Output is correct
53 Correct 1 ms 6492 KB Output is correct
54 Correct 1 ms 6488 KB Output is correct
55 Correct 1 ms 6588 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
57 Correct 1 ms 6592 KB Output is correct
58 Correct 1 ms 6492 KB Output is correct
59 Correct 1 ms 6492 KB Output is correct
60 Correct 1 ms 6488 KB Output is correct
61 Correct 1 ms 6492 KB Output is correct
62 Correct 1 ms 6492 KB Output is correct
63 Correct 1 ms 8680 KB Output is correct
64 Correct 1 ms 10588 KB Output is correct
65 Correct 1 ms 4444 KB Output is correct
66 Correct 1 ms 6492 KB Output is correct
67 Correct 2 ms 5468 KB Output is correct
68 Correct 4 ms 11612 KB Output is correct
69 Correct 3 ms 11604 KB Output is correct
70 Correct 24 ms 79204 KB Output is correct
71 Correct 37 ms 105968 KB Output is correct
72 Correct 66 ms 130644 KB Output is correct
73 Correct 78 ms 155220 KB Output is correct
74 Correct 51 ms 155216 KB Output is correct
75 Correct 64 ms 181844 KB Output is correct
76 Correct 15 ms 38284 KB Output is correct
77 Correct 14 ms 38236 KB Output is correct
78 Correct 6 ms 23992 KB Output is correct
79 Correct 16 ms 68904 KB Output is correct
80 Correct 4 ms 9564 KB Output is correct
81 Correct 8 ms 23900 KB Output is correct
82 Correct 14 ms 24156 KB Output is correct
83 Correct 23 ms 69052 KB Output is correct
84 Correct 27 ms 69204 KB Output is correct
85 Correct 29 ms 69052 KB Output is correct
86 Correct 19 ms 40328 KB Output is correct
87 Correct 22 ms 48520 KB Output is correct
88 Correct 25 ms 64956 KB Output is correct
89 Correct 39 ms 105956 KB Output is correct
90 Correct 43 ms 130740 KB Output is correct
91 Correct 58 ms 155348 KB Output is correct
92 Correct 21 ms 54620 KB Output is correct
93 Correct 138 ms 231252 KB Output is correct
94 Correct 113 ms 243404 KB Output is correct
95 Correct 7 ms 19800 KB Output is correct
96 Correct 16 ms 54864 KB Output is correct
97 Correct 61 ms 181840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 0 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 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 101 ms 257840 KB Output is correct
9 Correct 95 ms 257708 KB Output is correct
10 Correct 162 ms 257876 KB Output is correct
11 Correct 111 ms 257616 KB Output is correct
12 Correct 107 ms 257872 KB Output is correct
13 Correct 111 ms 257868 KB Output is correct
14 Correct 108 ms 249584 KB Output is correct
15 Correct 110 ms 253776 KB Output is correct
16 Correct 113 ms 257864 KB Output is correct
17 Correct 103 ms 255756 KB Output is correct
18 Correct 100 ms 255812 KB Output is correct
19 Correct 93 ms 255828 KB Output is correct
20 Correct 95 ms 255660 KB Output is correct
21 Correct 119 ms 256084 KB Output is correct
22 Correct 119 ms 255852 KB Output is correct
23 Correct 120 ms 255828 KB Output is correct
24 Correct 97 ms 253620 KB Output is correct
25 Correct 98 ms 253776 KB Output is correct
26 Correct 95 ms 253520 KB Output is correct
27 Correct 92 ms 253520 KB Output is correct
28 Correct 105 ms 253520 KB Output is correct
29 Correct 1 ms 6488 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 4444 KB Output is correct
32 Correct 0 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 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 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 0 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 4712 KB Output is correct
53 Correct 1 ms 6492 KB Output is correct
54 Correct 1 ms 6488 KB Output is correct
55 Correct 1 ms 6588 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
57 Correct 1 ms 6592 KB Output is correct
58 Correct 1 ms 6492 KB Output is correct
59 Correct 1 ms 6492 KB Output is correct
60 Correct 1 ms 6488 KB Output is correct
61 Correct 1 ms 6492 KB Output is correct
62 Correct 1 ms 6492 KB Output is correct
63 Correct 1 ms 8680 KB Output is correct
64 Correct 1 ms 10588 KB Output is correct
65 Correct 1 ms 4444 KB Output is correct
66 Correct 1 ms 6492 KB Output is correct
67 Correct 2 ms 5468 KB Output is correct
68 Correct 4 ms 11612 KB Output is correct
69 Correct 3 ms 11604 KB Output is correct
70 Correct 24 ms 79204 KB Output is correct
71 Correct 37 ms 105968 KB Output is correct
72 Correct 66 ms 130644 KB Output is correct
73 Correct 78 ms 155220 KB Output is correct
74 Correct 51 ms 155216 KB Output is correct
75 Correct 64 ms 181844 KB Output is correct
76 Correct 15 ms 38284 KB Output is correct
77 Correct 14 ms 38236 KB Output is correct
78 Correct 6 ms 23992 KB Output is correct
79 Correct 16 ms 68904 KB Output is correct
80 Correct 4 ms 9564 KB Output is correct
81 Correct 8 ms 23900 KB Output is correct
82 Correct 14 ms 24156 KB Output is correct
83 Correct 23 ms 69052 KB Output is correct
84 Correct 27 ms 69204 KB Output is correct
85 Correct 29 ms 69052 KB Output is correct
86 Correct 19 ms 40328 KB Output is correct
87 Correct 22 ms 48520 KB Output is correct
88 Correct 25 ms 64956 KB Output is correct
89 Correct 39 ms 105956 KB Output is correct
90 Correct 43 ms 130740 KB Output is correct
91 Correct 58 ms 155348 KB Output is correct
92 Correct 21 ms 54620 KB Output is correct
93 Correct 138 ms 231252 KB Output is correct
94 Correct 113 ms 243404 KB Output is correct
95 Correct 7 ms 19800 KB Output is correct
96 Correct 16 ms 54864 KB Output is correct
97 Correct 61 ms 181840 KB Output is correct
98 Runtime error 6 ms 6232 KB Execution killed with signal 11
99 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 0 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 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 101 ms 257840 KB Output is correct
9 Correct 95 ms 257708 KB Output is correct
10 Correct 162 ms 257876 KB Output is correct
11 Correct 111 ms 257616 KB Output is correct
12 Correct 107 ms 257872 KB Output is correct
13 Correct 111 ms 257868 KB Output is correct
14 Correct 108 ms 249584 KB Output is correct
15 Correct 110 ms 253776 KB Output is correct
16 Correct 113 ms 257864 KB Output is correct
17 Correct 103 ms 255756 KB Output is correct
18 Correct 100 ms 255812 KB Output is correct
19 Correct 93 ms 255828 KB Output is correct
20 Correct 95 ms 255660 KB Output is correct
21 Correct 119 ms 256084 KB Output is correct
22 Correct 119 ms 255852 KB Output is correct
23 Correct 120 ms 255828 KB Output is correct
24 Correct 97 ms 253620 KB Output is correct
25 Correct 98 ms 253776 KB Output is correct
26 Correct 95 ms 253520 KB Output is correct
27 Correct 92 ms 253520 KB Output is correct
28 Correct 105 ms 253520 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 94 ms 257976 KB Output is correct
34 Correct 94 ms 257616 KB Output is correct
35 Correct 1 ms 4440 KB Output is correct
36 Correct 1 ms 5464 KB Output is correct
37 Runtime error 6 ms 6232 KB Execution killed with signal 11
38 Halted 0 ms 0 KB -