답안 #891986

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891986 2023-12-24T14:36:43 Z alexander707070 Cookies (JOI23_cookies) C++14
6 / 100
6 ms 33624 KB
#include<bits/stdc++.h>
#define MAXN 15007
using namespace std;

int n,m,pt,total;
int a[MAXN],b[MAXN];

vector< pair<int,int> > v;
vector< vector<int> > sol;

bool li[MAXN][MAXN];
int dp[MAXN][MAXN];

int ff(int pos,int sum){
    if(sum<0)return 1000000;
    if(sum==0 and pos==0)return 0;
    else if(pos==0)return 1000000;

    if(li[pos][sum])return dp[pos][sum];
    li[pos][sum]=true;

    dp[pos][sum]=min(ff(pos-1,sum),ff(pos,sum-b[pos])+1);

    return dp[pos][sum];
}

int main(){

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        total+=a[i];
        v.push_back({a[i],i});
    }
    reverse(v.begin(),v.end());

    cin>>m;
    for(int i=1;i<=m;i++){
        cin>>b[i];
    }

    if(ff(m,total)>total){
        cout<<"-1\n";
        return 0;
    }

    pt=m;
    while(!v.empty()){
        while(pt>=1 and (b[pt]>v.size() or ff(pt,total)!=ff(pt,total-b[pt])+1))pt--;
        if(pt==0){
            cout<<"-1\n";
            return 0;
        }

        sol.push_back({});

        for(int i=0;i<b[pt];i++){
            v[i].first--;
            sol.back().push_back(v[i].second);
        }
        total-=b[pt];

        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());

        while(!v.empty() and v.back().first==0)v.pop_back();
    }

    cout<<sol.size()<<"\n";
    for(int i=0;i<sol.size();i++){
        cout<<sol[i].size()<<" ";
        for(int f:sol[i])cout<<f<<" ";
        cout<<"\n";
    }


    return 0;
}

Compilation message

cookies.cpp: In function 'int main()':
cookies.cpp:49:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         while(pt>=1 and (b[pt]>v.size() or ff(pt,total)!=ff(pt,total-b[pt])+1))pt--;
      |                          ~~~~~^~~~~~~~~
cookies.cpp:70:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int i=0;i<sol.size();i++){
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 2436 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 6 ms 33624 KB Output is correct
11 Correct 3 ms 18012 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 5 ms 9052 KB Output is correct
14 Correct 3 ms 15708 KB Output is correct
15 Correct 3 ms 15708 KB Output is correct
16 Correct 3 ms 15964 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 7004 KB Output is correct
22 Correct 3 ms 18012 KB Output is correct
23 Correct 3 ms 18012 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2648 KB Output is correct
28 Correct 2 ms 11356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 4 ms 1944 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 2436 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 6 ms 33624 KB Output is correct
11 Correct 3 ms 18012 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 5 ms 9052 KB Output is correct
14 Correct 3 ms 15708 KB Output is correct
15 Correct 3 ms 15708 KB Output is correct
16 Correct 3 ms 15964 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 7004 KB Output is correct
22 Correct 3 ms 18012 KB Output is correct
23 Correct 3 ms 18012 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2648 KB Output is correct
28 Correct 2 ms 11356 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Incorrect 0 ms 348 KB Output isn't correct
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 2436 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 6 ms 33624 KB Output is correct
11 Correct 3 ms 18012 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 5 ms 9052 KB Output is correct
14 Correct 3 ms 15708 KB Output is correct
15 Correct 3 ms 15708 KB Output is correct
16 Correct 3 ms 15964 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 7004 KB Output is correct
22 Correct 3 ms 18012 KB Output is correct
23 Correct 3 ms 18012 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2648 KB Output is correct
28 Correct 2 ms 11356 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Incorrect 0 ms 348 KB Output isn't correct
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 2436 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 6 ms 33624 KB Output is correct
11 Correct 3 ms 18012 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 5 ms 9052 KB Output is correct
14 Correct 3 ms 15708 KB Output is correct
15 Correct 3 ms 15708 KB Output is correct
16 Correct 3 ms 15964 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 7004 KB Output is correct
22 Correct 3 ms 18012 KB Output is correct
23 Correct 3 ms 18012 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2648 KB Output is correct
28 Correct 2 ms 11356 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 600 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 4 ms 1944 KB Output is correct
39 Correct 0 ms 600 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Incorrect 0 ms 348 KB Output isn't correct
45 Halted 0 ms 0 KB -