답안 #967240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967240 2024-04-21T15:11:17 Z huutuan Cookies (JOI23_cookies) C++14
7 / 100
3 ms 1432 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];
   reverse(b+1, b+m+1);
   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;
   }
   vector<int> sz;
   for (int i=m; i>=1; --i){
      for (int j=sum/b[i]; j>=0; --j) if (f[i-1][sum-j*b[i]]){
         while (j--) sz.push_back(b[i]), sum-=b[i];
      }
   }
   priority_queue<pair<int, int>> pq;
   for (int i=1; i<=n; ++i) pq.emplace(a[i], i);
   vector<vector<int>> ans;
   for (int i:sz){
      ans.emplace_back();
      for (int j=0; j<i; ++j){
         if (pq.empty()){
            cout << -1 << '\n';
            return 0;
         }
         ans.back().push_back(pq.top().second);
         pq.pop();
      }
      for (int j:ans.back()){
         --a[j];
         if (a[j]) pq.emplace(a[j], j);
      }
   }
   cout << ans.size() << '\n';
   for (auto &i:ans){
      cout << i.size();
      for (int j:i) cout << ' ' << j;
      cout << '\n';
   }
   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 532 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 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 3 ms 1432 KB Output is correct
11 Correct 0 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 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -