Submission #967250

# Submission time Handle Problem Language Result Execution time Memory
967250 2024-04-21T15:52:17 Z huutuan Cookies (JOI23_cookies) C++14
7 / 100
5 ms 2396 KB
#include<bits/stdc++.h>

using namespace std;

const int N=15e3+10;
bool f[N][N];
int n, m, a[N], b[N];

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cin >> n;
   for (int i=1; i<=n; ++i) cin >> a[i];
   cin >> m;
   for (int i=1; i<=m; ++i) cin >> b[i];
   int sum=accumulate(a+1, a+n+1, 0);
   f[0][0]=1;
   for (int i=1; i<=m; ++i){
      memcpy(f[i], f[i-1], sizeof f[i]);
      for (int j=b[i]; j<=sum; ++j) f[i][j]|=f[i][j-b[i]];
   }
   if (!f[m][sum]){
      cout << -1 << '\n';
      return 0;
   }
   priority_queue<pair<int, int>> pq;
   vector<vector<int>> ans;
   for (int i=1; i<=n; ++i) pq.emplace(a[i], i);
   for (int i=m; i>=1; --i){
      auto _pq=pq;
      int j;
      vector<int> vv;
      for (j=0; (int)pq.size()>=b[i]; ++j){
         vector<int> v;
         for (int k=0; k<b[i]; ++k){
            v.push_back(pq.top().second);
            vv.push_back(pq.top().second);
            pq.pop();
         }
         for (int k:v){
            --a[k];
            if (a[k]) pq.emplace(a[k], k);
         }
      }
      pq=_pq;
      for (int k:vv) ++a[k];
      for (; j>=0; --j){
         if (f[i-1][sum-j*b[i]]){
            while (j--){
               ans.emplace_back();
               for (int k=0; k<b[i]; ++k){
                  ans.back().push_back(pq.top().second);
                  pq.pop();
               }
               for (int k:ans.back()){
                  --a[k];
                  if (a[k]) pq.emplace(a[k], k);
               }
               sum-=b[i];
            }
         }
      }
   }
   if (sum){
      cout << -1 << '\n';
      return 0;
   }
   cout << ans.size() << '\n';
   for (auto &i:ans){
      cout << i.size();
      for (int j:i) cout << ' ' << j;
      cout << '\n';
   }
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 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 1 ms 464 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Incorrect 2 ms 2392 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 468 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 5 ms 1292 KB Output is correct
11 Correct 1 ms 348 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 460 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 4 ms 860 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 1 ms 2392 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 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 1 ms 464 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Incorrect 2 ms 2392 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 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 1 ms 464 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Incorrect 2 ms 2392 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 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 1 ms 464 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Incorrect 2 ms 2392 KB Output isn't correct
8 Halted 0 ms 0 KB -