Submission #789280

# Submission time Handle Problem Language Result Execution time Memory
789280 2023-07-21T08:49:54 Z 반딧불(#10041) Cookies (JOI23_cookies) C++17
6 / 100
20 ms 24620 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

int DP[3002][3002]; /// DP[j][m]: ���� j, �ִ밡 m�� �ǵ��� ���� �� ���� �� �ּ� ����
int track[3002][3002];
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);
        }
    }

    for(int i=0; i<=s; i++) for(int j=0; j<=k; j++) DP[i][j] = 1e9;

    DP[0][1] = 0;
    for(int j=0; j<=s; j++){
        for(int m=1; m<=k; m++){
            if(DP[j][m] == 1e9) continue;
            int i = DP[j][m];
            if(j==s){
                if(ansI > i) ansI = i, ansJ = j, ansM = m;
                continue;
            }
            if(m<k && DP[j][m+1] > i) DP[j][m+1] = i, track[j][m+1] = 1; /// �������� �ѱ��
            if(j+b[m]<=lim[i+1] && DP[j+b[m]][m] > i+1) DP[j+b[m]][m] = i+1, track[j+b[m]][m] = 2; /// �ֱ�
        }
    }

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

    vector<int> cnt;
    int i = ansI, j = ansJ, m = ansM;
    while(i){
        if(track[j][m] == 1) m--;
        else{
            cnt.push_back(b[m]);
            j -= b[m], i--;
        }
    }
    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:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
cookies.cpp:17:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     for(int i=1; i<=n; i++) scanf("%d", &a[i]);
      |                             ~~~~~^~~~~~~~~~~~~
cookies.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d", &k);
      |     ~~~~~^~~~~~~~~~
cookies.cpp:20:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     for(int i=1; i<=k; i++) scanf("%d", &b[i]);
      |                             ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 17 ms 4392 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 3 ms 5808 KB Output is correct
11 Correct 2 ms 3924 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 9 ms 4168 KB Output is correct
14 Correct 2 ms 3796 KB Output is correct
15 Correct 4 ms 3924 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 3 ms 4360 KB Output is correct
19 Correct 3 ms 3924 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 4436 KB Output is correct
22 Correct 2 ms 3924 KB Output is correct
23 Correct 2 ms 3924 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 3 ms 4308 KB Output is correct
26 Correct 2 ms 3796 KB Output is correct
27 Correct 2 ms 3668 KB Output is correct
28 Correct 3 ms 4052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 20 ms 4396 KB Output is correct
6 Correct 1 ms 2260 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 3 ms 4308 KB Output is correct
9 Correct 16 ms 24620 KB Output is correct
10 Runtime error 2 ms 340 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 17 ms 4392 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 3 ms 5808 KB Output is correct
11 Correct 2 ms 3924 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 9 ms 4168 KB Output is correct
14 Correct 2 ms 3796 KB Output is correct
15 Correct 4 ms 3924 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 3 ms 4360 KB Output is correct
19 Correct 3 ms 3924 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 4436 KB Output is correct
22 Correct 2 ms 3924 KB Output is correct
23 Correct 2 ms 3924 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 3 ms 4308 KB Output is correct
26 Correct 2 ms 3796 KB Output is correct
27 Correct 2 ms 3668 KB Output is correct
28 Correct 3 ms 4052 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Incorrect 1 ms 340 KB Output isn't correct
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 17 ms 4392 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 3 ms 5808 KB Output is correct
11 Correct 2 ms 3924 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 9 ms 4168 KB Output is correct
14 Correct 2 ms 3796 KB Output is correct
15 Correct 4 ms 3924 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 3 ms 4360 KB Output is correct
19 Correct 3 ms 3924 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 4436 KB Output is correct
22 Correct 2 ms 3924 KB Output is correct
23 Correct 2 ms 3924 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 3 ms 4308 KB Output is correct
26 Correct 2 ms 3796 KB Output is correct
27 Correct 2 ms 3668 KB Output is correct
28 Correct 3 ms 4052 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Incorrect 1 ms 340 KB Output isn't correct
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 17 ms 4392 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 3 ms 5808 KB Output is correct
11 Correct 2 ms 3924 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 9 ms 4168 KB Output is correct
14 Correct 2 ms 3796 KB Output is correct
15 Correct 4 ms 3924 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 3 ms 4360 KB Output is correct
19 Correct 3 ms 3924 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 4436 KB Output is correct
22 Correct 2 ms 3924 KB Output is correct
23 Correct 2 ms 3924 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 3 ms 4308 KB Output is correct
26 Correct 2 ms 3796 KB Output is correct
27 Correct 2 ms 3668 KB Output is correct
28 Correct 3 ms 4052 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 20 ms 4396 KB Output is correct
34 Correct 1 ms 2260 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 3 ms 4308 KB Output is correct
37 Correct 16 ms 24620 KB Output is correct
38 Runtime error 2 ms 340 KB Execution killed with signal 11
39 Halted 0 ms 0 KB -