Submission #789325

# Submission time Handle Problem Language Result Execution time Memory
789325 2023-07-21T09:15:56 Z 반딧불(#10041) Cookies (JOI23_cookies) C++17
6 / 100
24 ms 24676 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 order[3002];

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);
        }
    }
    lim[s+1] = lim[s];

    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++){
        set<int> st;
        for(int m=1; m<=k; m++){
            int i = DP[j][m];
//            printf("%d %d: %d\n", j, m, i);
            if(j==s){
                if(ansI > i) ansI = i, ansJ = j, ansM = m;
                continue;
            }
            if(i!=1e9) order[i] = m, st.insert(i);
            int idx = lower_bound(lim+1, lim+s+2, j+b[m]) - lim - 1; /// i�� idx �̻��̾�� ��
            auto it = st.lower_bound(idx);
            if(it == st.end()) continue;
            i = *it;
            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] = order[i]; /// �ֱ�
        }
    }

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

    vector<int> cnt;
    int i = ansI, j = ansJ, m = ansM;
    while(i){
        cnt.push_back(b[m]);
        int tm = track[j][m];
        j -= b[m], i--;
        m = tm;
    }
    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:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
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<=n; i++) scanf("%d", &a[i]);
      |                             ~~~~~^~~~~~~~~~~~~
cookies.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf("%d", &k);
      |     ~~~~~^~~~~~~~~~
cookies.cpp:22:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     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 0 ms 340 KB Output is correct
3 Correct 1 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 0 ms 340 KB Output is correct
8 Correct 24 ms 4308 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 5 ms 5716 KB Output is correct
11 Correct 3 ms 3796 KB Output is correct
12 Correct 3 ms 4436 KB Output is correct
13 Correct 10 ms 4052 KB Output is correct
14 Correct 4 ms 3796 KB Output is correct
15 Correct 5 ms 3904 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 2 ms 4308 KB Output is correct
19 Correct 2 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 4 ms 3924 KB Output is correct
23 Correct 3 ms 3924 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 4 ms 4264 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 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 24 ms 4308 KB Output is correct
6 Correct 1 ms 2260 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 4308 KB Output is correct
9 Correct 18 ms 24676 KB Output is correct
10 Runtime error 2 ms 456 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 1 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 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 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 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 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 Incorrect 1 ms 340 KB Output isn't correct
21 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 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 0 ms 340 KB Output is correct
8 Correct 24 ms 4308 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 5 ms 5716 KB Output is correct
11 Correct 3 ms 3796 KB Output is correct
12 Correct 3 ms 4436 KB Output is correct
13 Correct 10 ms 4052 KB Output is correct
14 Correct 4 ms 3796 KB Output is correct
15 Correct 5 ms 3904 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 2 ms 4308 KB Output is correct
19 Correct 2 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 4 ms 3924 KB Output is correct
23 Correct 3 ms 3924 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 4 ms 4264 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 1 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 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 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 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 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 Incorrect 1 ms 340 KB Output isn't correct
49 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 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 0 ms 340 KB Output is correct
8 Correct 24 ms 4308 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 5 ms 5716 KB Output is correct
11 Correct 3 ms 3796 KB Output is correct
12 Correct 3 ms 4436 KB Output is correct
13 Correct 10 ms 4052 KB Output is correct
14 Correct 4 ms 3796 KB Output is correct
15 Correct 5 ms 3904 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 2 ms 4308 KB Output is correct
19 Correct 2 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 4 ms 3924 KB Output is correct
23 Correct 3 ms 3924 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 4 ms 4264 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 1 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 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 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 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 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 Incorrect 1 ms 340 KB Output isn't correct
49 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 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 0 ms 340 KB Output is correct
8 Correct 24 ms 4308 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 5 ms 5716 KB Output is correct
11 Correct 3 ms 3796 KB Output is correct
12 Correct 3 ms 4436 KB Output is correct
13 Correct 10 ms 4052 KB Output is correct
14 Correct 4 ms 3796 KB Output is correct
15 Correct 5 ms 3904 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 2 ms 4308 KB Output is correct
19 Correct 2 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 4 ms 3924 KB Output is correct
23 Correct 3 ms 3924 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 4 ms 4264 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 1 ms 212 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 24 ms 4308 KB Output is correct
34 Correct 1 ms 2260 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 3 ms 4308 KB Output is correct
37 Correct 18 ms 24676 KB Output is correct
38 Runtime error 2 ms 456 KB Execution killed with signal 11
39 Halted 0 ms 0 KB -