Submission #789232

# Submission time Handle Problem Language Result Execution time Memory
789232 2023-07-21T08:27:33 Z 반딧불(#10041) Cookies (JOI23_cookies) C++17
63 / 100
45 ms 31792 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, k, s;
int a[3002], b[3002];
int lim[3002];

bool DP[502][502][502]; /// DP[i][j][m]: i��°�� ���� j, �ִ밡 m�� �ǵ��� ���� �� �ִ°�?
int ansI = 1e9, ansJ = -1, ansM = -1;

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &a[i]);
    s = accumulate(a+1, a+n+1, 0);
    scanf("%d", &k);
    for(int i=1; i<=k; i++) scanf("%d", &b[i]);
    reverse(b+1, b+k+1);

    for(int i=1; i<=s; i++){
        for(int j=1; j<=s; j++){
            lim[i] += min(a[j], i);
        }
    }

    DP[0][0][1] = 1;
    for(int i=0; i<=s; i++){
        for(int j=i; j<=s; j++){
            for(int m=1; m<=k; m++){
                if(!DP[i][j][m]) continue;
//                printf("cnt %d sum %d max %d possible!\n", i, j, b[m]);
                if(j==s){
                    if(ansI > i){
                        ansI = i, ansJ = j, ansM = m;
                        goto answer;
                    }
                    continue;
                }
                if(m<k) DP[i][j][m+1] = 1; /// �������� �ѱ��
                if(j+b[m]<=lim[i+1]) DP[i+1][j+b[m]][m] = 1; /// �ֱ�
            }
        }
    }

    answer:
    if(ansI == 1e9){
        puts("-1");
        return 0;
    }

    vector<int> cnt;
    int i = ansI, j = ansJ, m = ansM;
    while(i){
        if(DP[i][j][m-1]) m--;
        else{
            cnt.push_back(b[m]);
            j -= b[m], i--;
            assert(DP[i][j][m]);
        }
    }
    sort(cnt.rbegin(), cnt.rend());

    vector<vector<int> > ans;
    for(int p: cnt){
        vector<pair<int, int> > vec;
        for(int i=1; i<=n; i++) vec.push_back(make_pair(a[i], i));
        sort(vec.rbegin(), vec.rend());
        ans.push_back(vector<int>());
        for(int i=0; i<p; i++) ans.back().push_back(vec[i].second), a[vec[i].second]--;
    }

    printf("%d\n", (int)ans.size());
    for(auto p: ans){
        printf("%d ", (int)p.size());
        for(auto x: p) printf("%d ", x);
        puts("");
    }
}

Compilation message

cookies.cpp: In function 'int main()':
cookies.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
cookies.cpp:16:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     for(int i=1; i<=n; i++) scanf("%d", &a[i]);
      |                             ~~~~~^~~~~~~~~~~~~
cookies.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%d", &k);
      |     ~~~~~^~~~~~~~~~
cookies.cpp:19:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     for(int i=1; i<=k; i++) scanf("%d", &b[i]);
      |                             ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 29 ms 2576 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 980 KB Output is correct
11 Correct 38 ms 616 KB Output is correct
12 Correct 2 ms 2004 KB Output is correct
13 Correct 32 ms 9412 KB Output is correct
14 Correct 5 ms 2644 KB Output is correct
15 Correct 13 ms 5780 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 3 ms 3412 KB Output is correct
18 Correct 3 ms 2900 KB Output is correct
19 Correct 1 ms 1364 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 45 ms 31792 KB Output is correct
23 Correct 41 ms 16092 KB Output is correct
24 Correct 3 ms 3540 KB Output is correct
25 Correct 3 ms 3540 KB Output is correct
26 Correct 2 ms 2516 KB Output is correct
27 Correct 2 ms 2516 KB Output is correct
28 Correct 3 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 25 ms 2516 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 9 ms 2540 KB Output is correct
9 Runtime error 33 ms 5000 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 260 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 304 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 29 ms 2576 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 980 KB Output is correct
11 Correct 38 ms 616 KB Output is correct
12 Correct 2 ms 2004 KB Output is correct
13 Correct 32 ms 9412 KB Output is correct
14 Correct 5 ms 2644 KB Output is correct
15 Correct 13 ms 5780 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 3 ms 3412 KB Output is correct
18 Correct 3 ms 2900 KB Output is correct
19 Correct 1 ms 1364 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 45 ms 31792 KB Output is correct
23 Correct 41 ms 16092 KB Output is correct
24 Correct 3 ms 3540 KB Output is correct
25 Correct 3 ms 3540 KB Output is correct
26 Correct 2 ms 2516 KB Output is correct
27 Correct 2 ms 2516 KB Output is correct
28 Correct 3 ms 2772 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 308 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 304 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 260 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 308 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 308 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 304 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 308 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 304 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 308 KB Output is correct
67 Correct 10 ms 2604 KB Output is correct
68 Correct 2 ms 468 KB Output is correct
69 Correct 9 ms 716 KB Output is correct
70 Correct 2 ms 3028 KB Output is correct
71 Correct 2 ms 2516 KB Output is correct
72 Correct 2 ms 2004 KB Output is correct
73 Correct 1 ms 1076 KB Output is correct
74 Correct 2 ms 1460 KB Output is correct
75 Correct 1 ms 1336 KB Output is correct
76 Correct 5 ms 11476 KB Output is correct
77 Correct 3 ms 4064 KB Output is correct
78 Correct 8 ms 15060 KB Output is correct
79 Correct 6 ms 11732 KB Output is correct
80 Correct 8 ms 16980 KB Output is correct
81 Correct 2 ms 3156 KB Output is correct
82 Correct 3 ms 4564 KB Output is correct
83 Correct 1 ms 1236 KB Output is correct
84 Correct 2 ms 1728 KB Output is correct
85 Correct 3 ms 4052 KB Output is correct
86 Correct 2 ms 1968 KB Output is correct
87 Correct 1 ms 1748 KB Output is correct
88 Correct 2 ms 2132 KB Output is correct
89 Correct 2 ms 1364 KB Output is correct
90 Correct 1 ms 1108 KB Output is correct
91 Correct 1 ms 1492 KB Output is correct
92 Correct 3 ms 3128 KB Output is correct
93 Correct 19 ms 6448 KB Output is correct
94 Correct 8 ms 7772 KB Output is correct
95 Correct 4 ms 6228 KB Output is correct
96 Correct 2 ms 3760 KB Output is correct
97 Correct 1 ms 1720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 29 ms 2576 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 980 KB Output is correct
11 Correct 38 ms 616 KB Output is correct
12 Correct 2 ms 2004 KB Output is correct
13 Correct 32 ms 9412 KB Output is correct
14 Correct 5 ms 2644 KB Output is correct
15 Correct 13 ms 5780 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 3 ms 3412 KB Output is correct
18 Correct 3 ms 2900 KB Output is correct
19 Correct 1 ms 1364 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 45 ms 31792 KB Output is correct
23 Correct 41 ms 16092 KB Output is correct
24 Correct 3 ms 3540 KB Output is correct
25 Correct 3 ms 3540 KB Output is correct
26 Correct 2 ms 2516 KB Output is correct
27 Correct 2 ms 2516 KB Output is correct
28 Correct 3 ms 2772 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 308 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 304 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 260 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 308 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 308 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 304 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 308 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 304 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 308 KB Output is correct
67 Correct 10 ms 2604 KB Output is correct
68 Correct 2 ms 468 KB Output is correct
69 Correct 9 ms 716 KB Output is correct
70 Correct 2 ms 3028 KB Output is correct
71 Correct 2 ms 2516 KB Output is correct
72 Correct 2 ms 2004 KB Output is correct
73 Correct 1 ms 1076 KB Output is correct
74 Correct 2 ms 1460 KB Output is correct
75 Correct 1 ms 1336 KB Output is correct
76 Correct 5 ms 11476 KB Output is correct
77 Correct 3 ms 4064 KB Output is correct
78 Correct 8 ms 15060 KB Output is correct
79 Correct 6 ms 11732 KB Output is correct
80 Correct 8 ms 16980 KB Output is correct
81 Correct 2 ms 3156 KB Output is correct
82 Correct 3 ms 4564 KB Output is correct
83 Correct 1 ms 1236 KB Output is correct
84 Correct 2 ms 1728 KB Output is correct
85 Correct 3 ms 4052 KB Output is correct
86 Correct 2 ms 1968 KB Output is correct
87 Correct 1 ms 1748 KB Output is correct
88 Correct 2 ms 2132 KB Output is correct
89 Correct 2 ms 1364 KB Output is correct
90 Correct 1 ms 1108 KB Output is correct
91 Correct 1 ms 1492 KB Output is correct
92 Correct 3 ms 3128 KB Output is correct
93 Correct 19 ms 6448 KB Output is correct
94 Correct 8 ms 7772 KB Output is correct
95 Correct 4 ms 6228 KB Output is correct
96 Correct 2 ms 3760 KB Output is correct
97 Correct 1 ms 1720 KB Output is correct
98 Runtime error 32 ms 5004 KB Execution killed with signal 11
99 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 29 ms 2576 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 980 KB Output is correct
11 Correct 38 ms 616 KB Output is correct
12 Correct 2 ms 2004 KB Output is correct
13 Correct 32 ms 9412 KB Output is correct
14 Correct 5 ms 2644 KB Output is correct
15 Correct 13 ms 5780 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 3 ms 3412 KB Output is correct
18 Correct 3 ms 2900 KB Output is correct
19 Correct 1 ms 1364 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 45 ms 31792 KB Output is correct
23 Correct 41 ms 16092 KB Output is correct
24 Correct 3 ms 3540 KB Output is correct
25 Correct 3 ms 3540 KB Output is correct
26 Correct 2 ms 2516 KB Output is correct
27 Correct 2 ms 2516 KB Output is correct
28 Correct 3 ms 2772 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 308 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 25 ms 2516 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 9 ms 2540 KB Output is correct
37 Runtime error 33 ms 5000 KB Execution killed with signal 11
38 Halted 0 ms 0 KB -